Skip to content

Commit

Permalink
Fix fail-fast interrupt test
Browse files Browse the repository at this point in the history
Listen for the peer-failure notification before resuming tests. Then
verify the test execution was interrupted.

That's still not enough on Windows, where the passes-slow test results aren't always received. So only test for that when they are.
  • Loading branch information
novemberborn committed Jan 18, 2020
1 parent 61e0d05 commit 5a33572
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -119,6 +119,7 @@
"execa": "^4.0.0",
"get-stream": "^5.1.0",
"lolex": "^5.1.2",
"p-event": "^4.1.0",
"proxyquire": "^2.1.3",
"react": "^16.12.0",
"react-test-renderer": "^16.12.0",
Expand Down
57 changes: 30 additions & 27 deletions test/api.js
Expand Up @@ -123,7 +123,7 @@ test('fail-fast mode - multiple files & serial', t => {
});
});

test('fail-fast mode - multiple files & interrupt', t => {
test('fail-fast mode - multiple files & interrupt', async t => {
const api = apiCreator({
failFast: true,
concurrency: 2
Expand All @@ -149,32 +149,35 @@ test('fail-fast mode - multiple files & interrupt', t => {
});
});

return api.run({files: [
path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js')
]})
.then(runStatus => {
t.ok(api.options.failFast);
t.strictDeepEqual(tests, [{
ok: true,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
title: 'first pass'
}, {
ok: false,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
title: 'second fail'
}, {
ok: true,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
title: 'third pass'
}, {
ok: true,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js'),
title: 'first pass'
}]);
t.is(runStatus.stats.passedTests, 3);
t.is(runStatus.stats.failedTests, 1);
});
const fails = path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js');
const passesSlow = path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js');

const runStatus = await api.run({files: [fails, passesSlow]});
t.ok(api.options.failFast);
t.ok(runStatus.stats.passedTests >= 2); // Results from passes-slow are not always received on Windows.
t.ok(runStatus.stats.passedTests <= 3);
t.is(runStatus.stats.failedTests, 1);

t.strictDeepEqual(tests.filter(({testFile}) => testFile === fails), [{
ok: true,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
title: 'first pass'
}, {
ok: false,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
title: 'second fail'
}, {
ok: true,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
title: 'third pass'
}]);
if (runStatus.stats.passedTests === 3) {
t.strictDeepEqual(tests.filter(({testFile}) => testFile === passesSlow), [{
ok: true,
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js'),
title: 'first pass'
}]);
}
});

test('fail-fast mode - crash & serial', t => {
Expand Down
13 changes: 11 additions & 2 deletions test/fixture/fail-fast/multiple-files/passes-slow.js
@@ -1,8 +1,17 @@
const pEvent = require('p-event');
const test = require('../../../..');

test.serial('first pass', t => {
test.serial('first pass', async t => {
t.pass();
return new Promise(resolve => setTimeout(resolve, 60000));
const timer = setTimeout(() => {}, 60000); // Ensure process stays alive.
await pEvent(process, 'message', message => {
if (message.ava) {
return message.ava.type === 'peer-failed';
}

return false;
});
clearTimeout(timer);
});

test.serial('second pass', t => {
Expand Down

0 comments on commit 5a33572

Please sign in to comment.