-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect process.exit() called from tests
Fixes #861. Co-authored-by: Mark Wubben <mark@novemberborn.net>
- Loading branch information
1 parent
4b03662
commit ea597d8
Showing
11 changed files
with
130 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
const test = require('../../../../entrypoints/main.cjs'); | ||
|
||
// Allow some time for all workers to launch. | ||
const grace = new Promise(resolve => { | ||
setTimeout(resolve, 500); | ||
}); | ||
|
||
test('first pass', t => { | ||
t.pass(); | ||
}); | ||
|
||
test('second fail', t => { | ||
test('second fail', async t => { | ||
await grace; | ||
t.fail(); | ||
}); | ||
|
||
test('third pass', t => { | ||
test('third pass', async t => { | ||
await grace; | ||
t.pass(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
files: ['*.js'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import test from 'ava'; | ||
|
||
test('good', t => { | ||
t.pass(); | ||
}); | ||
|
||
test('process.exit', async t => { | ||
t.pass(); | ||
await new Promise(resolve => { | ||
setImmediate(resolve); | ||
}); | ||
process.exit(0); // eslint-disable-line unicorn/no-process-exit | ||
}); | ||
|
||
test('still good', t => { | ||
t.pass(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import test from '@ava/test'; | ||
|
||
import {fixture} from '../helpers/exec.js'; | ||
|
||
test('process.exit is intercepted', async t => { | ||
const result = await t.throwsAsync(fixture(['process-exit.js'])); | ||
t.true(result.failed); | ||
t.like(result, {timedOut: false, isCanceled: false, killed: false}); | ||
t.is(result.stats.selectedTestCount, 3); | ||
t.is(result.stats.passed.length, 2); | ||
t.is(result.stats.processExits.length, 1); | ||
}); |