Update asyncify script to handle more Mocha hooks

This commit is contained in:
Abe Jellinek 2025-07-23 16:09:05 -04:00 committed by Dan Stillman
parent 20e75c3251
commit b87bdeea41

View file

@ -31,10 +31,10 @@ function doTranslate(inputFile, root) {
return arg;
});
// Rewrite generator arguments to Mocha it() calls with async functions,
// Rewrite generator arguments to Mocha hooks with async functions,
// and replace yields with awaits
root.find(j.CallExpression)
.filter(path => isMochaItMethodCall(path))
.filter(path => isMochaHookMethodCall(path))
.forEach(path => {
let func = path.node.arguments.at(-1);
rewriteGeneratorToAsync(func);
@ -86,10 +86,10 @@ function getContainingGenerator(path) {
}
}
function isMochaItMethodCall(path) {
function isMochaHookMethodCall(path) {
let callee = path.node.callee;
return callee.type === 'Identifier'
&& callee.name === 'it';
&& ['it', 'before', 'beforeAll', 'beforeEach', 'after', 'afterAll', 'afterEach'].includes(callee.name);
}
function isStaticPromiseMethodCall(path, methodFilter) {