-
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.
Implement registerCompletionHandler()
Register a function to be called when AVA has completed a test run without uncaught exceptions or unhandled rejections. Fixes #3279. * * Completion handlers are invoked in order of registration. Results are not awaited.
- Loading branch information
1 parent
faf45ea
commit f5eed14
Showing
13 changed files
with
117 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export {default} from '../lib/worker/main.cjs'; | ||
export {registerCompletionHandler} from '../lib/worker/completion-handlers.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
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,13 @@ | ||
import process from 'node:process'; | ||
|
||
import state from './state.cjs'; | ||
|
||
export function runCompletionHandlers() { | ||
for (const handler of state.completionHandlers) { | ||
process.nextTick(() => handler()); | ||
} | ||
} | ||
|
||
export function registerCompletionHandler(handler) { | ||
state.completionHandlers.push(handler); | ||
} |
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,5 +1,6 @@ | ||
'use strict'; | ||
exports.flags = {loadedMain: false}; | ||
exports.refs = {runnerChain: null}; | ||
exports.completionHandlers = []; | ||
exports.sharedWorkerTeardowns = []; | ||
exports.waitForReady = []; |
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,7 @@ | ||
import test, { registerCompletionHandler } from 'ava' | ||
|
||
registerCompletionHandler(() => { | ||
process.exit(0) | ||
}) | ||
|
||
test('pass', 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,9 @@ | ||
import test, { registerCompletionHandler } from 'ava' | ||
|
||
registerCompletionHandler(() => { | ||
console.error('one') | ||
}) | ||
|
||
test('pass', 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,8 @@ | ||
{ | ||
"type": "module", | ||
"ava": { | ||
"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,10 @@ | ||
import test, { registerCompletionHandler } from 'ava' | ||
|
||
registerCompletionHandler(() => { | ||
console.error('one') | ||
}) | ||
registerCompletionHandler(() => { | ||
console.error('two') | ||
}) | ||
|
||
test('pass', 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,17 @@ | ||
import test from '@ava/test'; | ||
|
||
import {cleanOutput, fixture} from '../helpers/exec.js'; | ||
|
||
test('runs a single completion handler', async t => { | ||
const result = await fixture(['one.js']); | ||
t.is(cleanOutput(result.stderr), 'one'); | ||
}); | ||
|
||
test('runs multiple completion handlers in registration order', async t => { | ||
const result = await fixture(['two.js']); | ||
t.deepEqual(cleanOutput(result.stderr).split('\n'), ['one', 'two']); | ||
}); | ||
|
||
test('completion handlers may exit the process', async t => { | ||
await t.notThrowsAsync(fixture(['exit0.js'])); | ||
}); |