Skip to content

Commit 5a33572

Browse files
authored
Fix fail-fast interrupt test
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.
1 parent 61e0d05 commit 5a33572

File tree

4 files changed

+60
-29
lines changed

4 files changed

+60
-29
lines changed

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"execa": "^4.0.0",
120120
"get-stream": "^5.1.0",
121121
"lolex": "^5.1.2",
122+
"p-event": "^4.1.0",
122123
"proxyquire": "^2.1.3",
123124
"react": "^16.12.0",
124125
"react-test-renderer": "^16.12.0",

test/api.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ test('fail-fast mode - multiple files & serial', t => {
123123
});
124124
});
125125

126-
test('fail-fast mode - multiple files & interrupt', t => {
126+
test('fail-fast mode - multiple files & interrupt', async t => {
127127
const api = apiCreator({
128128
failFast: true,
129129
concurrency: 2
@@ -149,32 +149,35 @@ test('fail-fast mode - multiple files & interrupt', t => {
149149
});
150150
});
151151

152-
return api.run({files: [
153-
path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
154-
path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js')
155-
]})
156-
.then(runStatus => {
157-
t.ok(api.options.failFast);
158-
t.strictDeepEqual(tests, [{
159-
ok: true,
160-
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
161-
title: 'first pass'
162-
}, {
163-
ok: false,
164-
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
165-
title: 'second fail'
166-
}, {
167-
ok: true,
168-
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
169-
title: 'third pass'
170-
}, {
171-
ok: true,
172-
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js'),
173-
title: 'first pass'
174-
}]);
175-
t.is(runStatus.stats.passedTests, 3);
176-
t.is(runStatus.stats.failedTests, 1);
177-
});
152+
const fails = path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js');
153+
const passesSlow = path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js');
154+
155+
const runStatus = await api.run({files: [fails, passesSlow]});
156+
t.ok(api.options.failFast);
157+
t.ok(runStatus.stats.passedTests >= 2); // Results from passes-slow are not always received on Windows.
158+
t.ok(runStatus.stats.passedTests <= 3);
159+
t.is(runStatus.stats.failedTests, 1);
160+
161+
t.strictDeepEqual(tests.filter(({testFile}) => testFile === fails), [{
162+
ok: true,
163+
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
164+
title: 'first pass'
165+
}, {
166+
ok: false,
167+
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
168+
title: 'second fail'
169+
}, {
170+
ok: true,
171+
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/fails.js'),
172+
title: 'third pass'
173+
}]);
174+
if (runStatus.stats.passedTests === 3) {
175+
t.strictDeepEqual(tests.filter(({testFile}) => testFile === passesSlow), [{
176+
ok: true,
177+
testFile: path.join(__dirname, 'fixture/fail-fast/multiple-files/passes-slow.js'),
178+
title: 'first pass'
179+
}]);
180+
}
178181
});
179182

180183
test('fail-fast mode - crash & serial', t => {

test/fixture/fail-fast/multiple-files/passes-slow.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
const pEvent = require('p-event');
12
const test = require('../../../..');
23

3-
test.serial('first pass', t => {
4+
test.serial('first pass', async t => {
45
t.pass();
5-
return new Promise(resolve => setTimeout(resolve, 60000));
6+
const timer = setTimeout(() => {}, 60000); // Ensure process stays alive.
7+
await pEvent(process, 'message', message => {
8+
if (message.ava) {
9+
return message.ava.type === 'peer-failed';
10+
}
11+
12+
return false;
13+
});
14+
clearTimeout(timer);
615
});
716

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

0 commit comments

Comments
 (0)