Skip to content

Commit 117e914

Browse files
authored
[patch] fixing watching attachments (issue 61) (#62)
1 parent fcf6e73 commit 117e914

File tree

4 files changed

+50
-58
lines changed

4 files changed

+50
-58
lines changed

integration/e2e/groups/groups.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// eslint-disable-next-line @typescript-eslint/no-namespace
2+
declare namespace Cypress {
3+
export interface Chainable {
4+
step(name: string): Chainable<any>;
5+
other(name: string): Chainable<any>;
6+
}
7+
}
8+
9+
describe('groupped', () => {
10+
Cypress.Commands.add('other', name => {
11+
Cypress.log({ name: 'other', message: name, groupStart: true, type: 'parent' } as any);
12+
cy.log('other').then(() => {
13+
Cypress.log({ emitOnly: true, groupEnd: true } as any);
14+
});
15+
});
16+
Cypress.Commands.add('step', name => {
17+
Cypress.log({ name: 'group', message: name, groupStart: true, type: 'parent' } as any);
18+
cy.wait(200).then(() => {
19+
//
20+
});
21+
cy.other('step NESTED');
22+
cy.log('hello').then(() => {
23+
Cypress.log({ emitOnly: true, groupEnd: true } as any);
24+
});
25+
// cy.pause();
26+
});
27+
28+
it('test', () => {
29+
cy.step('step 1');
30+
cy.other('step Paretn');
31+
// cy.step('step 2');
32+
// cy.step('step 3');
33+
// cy.step('step 4');
34+
// cy.step('step 5');
35+
});
36+
});

src/plugins/allure-reporter-plugin.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -723,23 +723,24 @@ export class AllureReporter {
723723
this.globalHooks.processForTest();
724724
}
725725

726-
endTests() {
727-
this.tests.forEach(() => {
728-
this.endTest({ result: UNKNOWN, details: undefined });
729-
});
726+
async endTests() {
727+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
728+
for (const _tst of this.tests) {
729+
await this.endTest({ result: UNKNOWN, details: undefined });
730+
}
730731
}
731732

732-
endGroups() {
733-
this.endTests();
733+
async endGroups() {
734+
await this.endTests();
734735
this.groups.forEach(() => {
735736
this.endGroup();
736737
});
737738
}
738739

739-
endAll() {
740+
async endAll() {
740741
this.endAllSteps({ status: UNKNOWN, details: undefined });
741742
this.endHooks(Status.BROKEN);
742-
this.endGroups();
743+
await this.endGroups();
743744
}
744745

745746
addDescriptionHtml(arg: AllureTaskArgs<'addDescriptionHtml'>) {

src/plugins/allure.ts

+2-48
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ export const allureTasks = (opts: ReporterOptions): AllureTasks => {
301301
log('testParameter');
302302
},
303303

304-
endAll: () => {
304+
endAll: async () => {
305305
log('endAll started');
306-
allureReporter.endAll();
306+
await allureReporter.endAll();
307307
log('endAll');
308308
},
309309

@@ -340,12 +340,6 @@ export const allureTasks = (opts: ReporterOptions): AllureTasks => {
340340
log('attachScreenshots');
341341
},
342342

343-
/* attachVideoToTests: async (arg: AllureTaskArgs<'attachVideoToTests'>) => {
344-
log(`attachScreenshots ${JSON.stringify(arg)}`);
345-
await allureReporter.attachVideoToTests(arg);
346-
log('attachVideoToTests');
347-
},*/
348-
349343
async afterSpec(arg: AllureTaskArgs<'afterSpec'>) {
350344
log(`afterSpec ${JSON.stringify(arg)}`);
351345

@@ -361,45 +355,5 @@ export const allureTasks = (opts: ReporterOptions): AllureTasks => {
361355
await copyResultsToWatchFolder(allureResults, allureResultsWatch);
362356
log('afterSpec');
363357
},
364-
365-
/*flushWatcher: async (_arg: AllureTaskArgs<'flushWatcher'>) => {
366-
const allFiles = sync(`${allureResults}/*`);
367-
debug('FLUSH spec');
368-
let doneFiles = 0;
369-
370-
for (const fl of allFiles) {
371-
if (!existsSync(fl)) {
372-
doneFiles = doneFiles + 1;
373-
374-
return;
375-
}
376-
377-
readFile(fl, (err, content) => {
378-
if (!err) {
379-
writeFile(fl, content, errWrite => {
380-
if (errWrite) {
381-
debug(`Error writing file: ${errWrite.message}`);
382-
} else {
383-
debug('done writing');
384-
doneFiles++;
385-
}
386-
});
387-
} else {
388-
debug(`Error reading file: ${err?.message}`);
389-
}
390-
});
391-
}
392-
393-
const started = Date.now();
394-
const timeout = 10000;
395-
396-
while (doneFiles < allFiles.length) {
397-
if (Date.now() - started >= timeout) {
398-
console.error(`Could not flush all files in ${timeout}ms`);
399-
break;
400-
}
401-
await delay(100);
402-
}
403-
},*/
404358
};
405359
};

src/plugins/fs-tools.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { copyFile, existsSync, mkdirSync, rm, writeFile } from 'fs';
22
import Debug from 'debug';
33
import { delay, packageLog } from '../common';
44
import { Attachment } from 'allure-js-commons';
5-
import { basename } from 'path';
5+
import { basename, dirname } from 'path';
66

77
const debug = Debug('cypress-allure:fs-tools');
88

@@ -58,8 +58,9 @@ export const waitWhileCondition = async (whileCondition: () => boolean) => {
5858
}
5959
};
6060

61-
export const copyAttachments = async (attachments: Attachment[], watchPath: string, allureResults: string) => {
61+
export const copyAttachments = async (attachments: Attachment[], watchPath: string, allureResultFile: string) => {
6262
let attachsDone = 0;
63+
const allureResults = dirname(allureResultFile);
6364

6465
attachments.forEach(attach => {
6566
const attachTo = `${watchPath}/${attach.source}`;

0 commit comments

Comments
 (0)