Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix: testInfo.outputPath with retries does not clash (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Apr 23, 2021
1 parent 9484a63 commit 49c0d46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/workerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ export class WorkerRunner extends EventEmitter {
this._loader = new Loader();
this._loader.deserialize(this._params.loader);
this._runList = this._loader.runLists()[this._params.runListIndex];

const tags = this._runList.tags.join('-');
const sameTagsAndTestType = this._loader.runLists().filter(runList => runList.tags.join('-') === tags && runList.testType === this._runList.testType);
if (sameTagsAndTestType.length > 1)
this._outputPathSegment = tags + (sameTagsAndTestType.indexOf(this._runList) + 1);
else
this._outputPathSegment = tags;
if (this._outputPathSegment)
this._outputPathSegment = '-' + this._outputPathSegment;

this._config = this._loader.config(this._runList);
this._workerInfo = {
workerIndex: this._params.workerIndex,
Expand Down Expand Up @@ -222,10 +226,10 @@ export class WorkerRunner extends EventEmitter {
const baseOutputDir = (() => {
let suffix = this._outputPathSegment;
if (entry.retry)
suffix += (suffix ? '-' : '') + 'retry' + entry.retry;
suffix += '-retry' + entry.retry;
if (this._params.repeatEachIndex)
suffix += (suffix ? '-' : '') + 'repeat' + this._params.repeatEachIndex;
return path.join(config.outputDir, relativeTestPath, suffix);
suffix += '-repeat' + this._params.repeatEachIndex;
return path.join(config.outputDir, relativeTestPath + suffix);
})();
const testInfo: TestInfo = {
...this._workerInfo,
Expand Down
16 changes: 8 additions & 8 deletions test/test-output-dir.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ test('should work and remove empty dir', async ({ runInlineTest }) => {
'my-test.spec.js': `
test('test 1', async ({}, testInfo) => {
if (testInfo.retry) {
expect(testInfo.outputDir).toContain(require('path').join('my-test', 'test-1', 'retry1'));
expect(testInfo.outputPath('foo', 'bar')).toContain(require('path').join('my-test', 'test-1', 'retry1', 'foo', 'bar'));
expect(testInfo.outputDir).toContain(require('path').join('my-test', 'test-1-retry1'));
expect(testInfo.outputPath('foo', 'bar')).toContain(require('path').join('my-test', 'test-1-retry1', 'foo', 'bar'));
} else {
expect(testInfo.outputDir).toContain(require('path').join('my-test', 'test-1'));
expect(testInfo.outputPath()).toContain(require('path').join('my-test', 'test-1'));
Expand Down Expand Up @@ -83,22 +83,22 @@ test('should include runWith tag', async ({ runInlineTest }) => {
expect(result.results[1].status).toBe('passed');

// test1, run with first env
expect(result.output).toContain('test-results/my-test/test-1/foo1/bar.txt');
expect(result.output).toContain('test-results/my-test/test-1-foo1/bar.txt');
expect(result.output).toContain('__snapshots__/my-test/test-1/snapshots1/bar.txt');
expect(result.output).toContain('test-results/my-test/test-1/foo1-retry1/bar.txt');
expect(result.output).toContain('test-results/my-test/test-1-foo1-retry1/bar.txt');
expect(result.output).toContain('__snapshots__/my-test/test-1/snapshots1/bar.txt');

// test1, run with second env
expect(result.output).toContain('test-results/my-test/test-1/foo2/bar.txt');
expect(result.output).toContain('test-results/my-test/test-1-foo2/bar.txt');
expect(result.output).toContain('__snapshots__/my-test/test-1/snapshots2/bar.txt');
expect(result.output).toContain('test-results/my-test/test-1/foo2-retry1/bar.txt');
expect(result.output).toContain('test-results/my-test/test-1-foo2-retry1/bar.txt');
expect(result.output).toContain('__snapshots__/my-test/test-1/snapshots2/bar.txt');

// test2, run with env and tag=foo
expect(result.output).toContain('test-results/my-test/test-2/foo/bar.txt');
expect(result.output).toContain('test-results/my-test/test-2-foo/bar.txt');
expect(result.output).toContain('__snapshots__/my-test/test-2/snapshots1/bar.txt');

// test2, run with env and tag=a,b
expect(result.output).toContain('test-results/my-test/test-2/a-b/bar.txt');
expect(result.output).toContain('test-results/my-test/test-2-a-b/bar.txt');
expect(result.output).toContain('__snapshots__/my-test/test-2/snapshots1/bar.txt');
});

0 comments on commit 49c0d46

Please sign in to comment.