Skip to content

Commit

Permalink
Support parallel runs that do not need to run test files
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelmbagira committed Apr 19, 2020
1 parent 7eb23dd commit 26c8326
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 10 deletions.
7 changes: 7 additions & 0 deletions lib/reporters/verbose.js
Expand Up @@ -90,6 +90,7 @@ class VerboseReporter {
this.failFastEnabled = plan.failFastEnabled;
this.matching = plan.matching;
this.previousFailures = plan.previousFailures;
this.emptyParallelRun = plan.status.emptyParallelRun;

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

endRun() { // eslint-disable-line complexity
if (this.emptyParallelRun) {
this.lineWriter.writeLine('No files tested in this parallel run');
this.lineWriter.writeLine();
return;
}

if (!this.stats) {
this.lineWriter.writeLine(colors.error(`${figures.cross} Couldn’t find any files to test`));
this.lineWriter.writeLine();
Expand Down
9 changes: 9 additions & 0 deletions lib/run-status.js
Expand Up @@ -8,6 +8,11 @@ class RunStatus extends Emittery {

this.pendingTests = new Map();

this.emptyParallelRun = parallelRuns &&
parallelRuns.currentFileCount === 0 &&
parallelRuns.totalRuns > 1 &&
files > 0;

this.stats = {
byFile: new Map(),
declaredTests: 0,
Expand Down Expand Up @@ -143,6 +148,10 @@ class RunStatus extends Emittery {
}

suggestExitCode(circumstances) {
if (this.emptyParallelRun) {
return 0;
}

if (circumstances.matching && this.stats.selectedTests === 0) {
return 1;
}
Expand Down
@@ -1,4 +1,4 @@
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '0');
Expand Down
5 changes: 5 additions & 0 deletions test-tap/fixture/parallel-runs/less-files-than-ci-total/9.js
@@ -0,0 +1,5 @@
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '1');
});
File renamed without changes.
@@ -1,4 +1,4 @@
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '1');
Expand Down
5 changes: 5 additions & 0 deletions test-tap/fixture/parallel-runs/more-files-than-ci-total/2.js
@@ -0,0 +1,5 @@
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '0');
});
@@ -1,4 +1,4 @@
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '0');
Expand Down
@@ -1,4 +1,4 @@
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '0');
Expand Down
@@ -1,5 +1,5 @@
/* eslint-disable unicorn/filename-case */
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '1');
Expand Down
@@ -1,4 +1,4 @@
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '1');
Expand Down
@@ -1,4 +1,4 @@
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '2');
Expand Down
@@ -1,4 +1,4 @@
const test = require('../../..');
const test = require('../../../..');

test('at expected index', t => {
t.is(process.env.CI_NODE_INDEX, '2');
Expand Down
@@ -0,0 +1,5 @@
{
"ava": {
"files": ["*.js"]
}
}
5 changes: 5 additions & 0 deletions test-tap/fixture/parallel-runs/no-files/package.json
@@ -0,0 +1,5 @@
{
"ava": {
"files": ["*.js"]
}
}
32 changes: 30 additions & 2 deletions test-tap/integration/parallel-runs.js
Expand Up @@ -2,11 +2,11 @@
const {test} = require('tap');
const {execCli} = require('../helper/cli');

test('correctly distributes the test files', t => {
test('correctly distributes more test files than CI_NODE_TOTAL', t => {
t.plan(3);
for (let i = 0; i < 3; i++) {
execCli([], {
dirname: 'fixture/parallel-runs',
dirname: 'fixture/parallel-runs/more-files-than-ci-total',
env: {
AVA_FORCE_CI: 'ci',
CI_NODE_INDEX: String(i),
Expand All @@ -15,3 +15,31 @@ test('correctly distributes the test files', t => {
}, err => t.ifError(err));
}
});

test('correctly distributes less test files than CI_NODE_TOTAL', t => {
t.plan(3);
for (let i = 0; i < 3; i++) {
execCli([], {
dirname: 'fixture/parallel-runs/less-files-than-ci-total',
env: {
AVA_FORCE_CI: 'ci',
CI_NODE_INDEX: String(i),
CI_NODE_TOTAL: '3'
}
}, err => t.ifError(err));
}
});

test('fail when there are no files', t => {
t.plan(3);
for (let i = 0; i < 3; i++) {
execCli([], {
dirname: 'fixture/parallel-runs/no-files',
env: {
AVA_FORCE_CI: 'ci',
CI_NODE_INDEX: String(i),
CI_NODE_TOTAL: '3'
}
}, err => t.ok(err));
}
});

0 comments on commit 26c8326

Please sign in to comment.