Skip to content

Commit 26c8326

Browse files
authoredApr 19, 2020
Support parallel runs that do not need to run test files
1 parent 7eb23dd commit 26c8326

File tree

16 files changed

+74
-10
lines changed

16 files changed

+74
-10
lines changed
 

‎lib/reporters/verbose.js

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class VerboseReporter {
9090
this.failFastEnabled = plan.failFastEnabled;
9191
this.matching = plan.matching;
9292
this.previousFailures = plan.previousFailures;
93+
this.emptyParallelRun = plan.status.emptyParallelRun;
9394

9495
if (this.watching || plan.files.length > 1) {
9596
this.prefixTitle = (testFile, title) => prefixTitle(plan.filePathPrefix, testFile, title);
@@ -320,6 +321,12 @@ class VerboseReporter {
320321
}
321322

322323
endRun() { // eslint-disable-line complexity
324+
if (this.emptyParallelRun) {
325+
this.lineWriter.writeLine('No files tested in this parallel run');
326+
this.lineWriter.writeLine();
327+
return;
328+
}
329+
323330
if (!this.stats) {
324331
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any files to test`));
325332
this.lineWriter.writeLine();

‎lib/run-status.js

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class RunStatus extends Emittery {
88

99
this.pendingTests = new Map();
1010

11+
this.emptyParallelRun = parallelRuns &&
12+
parallelRuns.currentFileCount === 0 &&
13+
parallelRuns.totalRuns > 1 &&
14+
files > 0;
15+
1116
this.stats = {
1217
byFile: new Map(),
1318
declaredTests: 0,
@@ -143,6 +148,10 @@ class RunStatus extends Emittery {
143148
}
144149

145150
suggestExitCode(circumstances) {
151+
if (this.emptyParallelRun) {
152+
return 0;
153+
}
154+
146155
if (circumstances.matching && this.stats.selectedTests === 0) {
147156
return 1;
148157
}

‎test-tap/fixture/parallel-runs/2.js ‎test-tap/fixture/parallel-runs/less-files-than-ci-total/2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('../../..');
1+
const test = require('../../../..');
22

33
test('at expected index', t => {
44
t.is(process.env.CI_NODE_INDEX, '0');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const test = require('../../../..');
2+
3+
test('at expected index', t => {
4+
t.is(process.env.CI_NODE_INDEX, '1');
5+
});

‎test-tap/fixture/parallel-runs/10.js ‎test-tap/fixture/parallel-runs/more-files-than-ci-total/10.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('../../..');
1+
const test = require('../../../..');
22

33
test('at expected index', t => {
44
t.is(process.env.CI_NODE_INDEX, '1');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const test = require('../../../..');
2+
3+
test('at expected index', t => {
4+
t.is(process.env.CI_NODE_INDEX, '0');
5+
});

‎test-tap/fixture/parallel-runs/2a.js ‎test-tap/fixture/parallel-runs/more-files-than-ci-total/2a.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('../../..');
1+
const test = require('../../../..');
22

33
test('at expected index', t => {
44
t.is(process.env.CI_NODE_INDEX, '0');

‎test-tap/fixture/parallel-runs/9.js ‎test-tap/fixture/parallel-runs/more-files-than-ci-total/9.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('../../..');
1+
const test = require('../../../..');
22

33
test('at expected index', t => {
44
t.is(process.env.CI_NODE_INDEX, '0');

‎test-tap/fixture/parallel-runs/Ab.js ‎test-tap/fixture/parallel-runs/more-files-than-ci-total/Ab.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable unicorn/filename-case */
2-
const test = require('../../..');
2+
const test = require('../../../..');
33

44
test('at expected index', t => {
55
t.is(process.env.CI_NODE_INDEX, '1');

‎test-tap/fixture/parallel-runs/a.js ‎test-tap/fixture/parallel-runs/more-files-than-ci-total/a.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('../../..');
1+
const test = require('../../../..');
22

33
test('at expected index', t => {
44
t.is(process.env.CI_NODE_INDEX, '1');

‎test-tap/fixture/parallel-runs/b.js ‎test-tap/fixture/parallel-runs/more-files-than-ci-total/b.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('../../..');
1+
const test = require('../../../..');
22

33
test('at expected index', t => {
44
t.is(process.env.CI_NODE_INDEX, '2');

‎test-tap/fixture/parallel-runs/c.js ‎test-tap/fixture/parallel-runs/more-files-than-ci-total/c.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const test = require('../../..');
1+
const test = require('../../../..');
22

33
test('at expected index', t => {
44
t.is(process.env.CI_NODE_INDEX, '2');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ava": {
3+
"files": ["*.js"]
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"ava": {
3+
"files": ["*.js"]
4+
}
5+
}

‎test-tap/integration/parallel-runs.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
const {test} = require('tap');
33
const {execCli} = require('../helper/cli');
44

5-
test('correctly distributes the test files', t => {
5+
test('correctly distributes more test files than CI_NODE_TOTAL', t => {
66
t.plan(3);
77
for (let i = 0; i < 3; i++) {
88
execCli([], {
9-
dirname: 'fixture/parallel-runs',
9+
dirname: 'fixture/parallel-runs/more-files-than-ci-total',
1010
env: {
1111
AVA_FORCE_CI: 'ci',
1212
CI_NODE_INDEX: String(i),
@@ -15,3 +15,31 @@ test('correctly distributes the test files', t => {
1515
}, err => t.ifError(err));
1616
}
1717
});
18+
19+
test('correctly distributes less test files than CI_NODE_TOTAL', t => {
20+
t.plan(3);
21+
for (let i = 0; i < 3; i++) {
22+
execCli([], {
23+
dirname: 'fixture/parallel-runs/less-files-than-ci-total',
24+
env: {
25+
AVA_FORCE_CI: 'ci',
26+
CI_NODE_INDEX: String(i),
27+
CI_NODE_TOTAL: '3'
28+
}
29+
}, err => t.ifError(err));
30+
}
31+
});
32+
33+
test('fail when there are no files', t => {
34+
t.plan(3);
35+
for (let i = 0; i < 3; i++) {
36+
execCli([], {
37+
dirname: 'fixture/parallel-runs/no-files',
38+
env: {
39+
AVA_FORCE_CI: 'ci',
40+
CI_NODE_INDEX: String(i),
41+
CI_NODE_TOTAL: '3'
42+
}
43+
}, err => t.ok(err));
44+
}
45+
});

0 commit comments

Comments
 (0)
Please sign in to comment.