Skip to content

Commit

Permalink
fix: improve deferral for single-file execution;
Browse files Browse the repository at this point in the history
Closes #145
  • Loading branch information
lukeed committed Oct 8, 2021
1 parent 75b6573 commit 2a3a598
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.js
Expand Up @@ -95,6 +95,12 @@ async function runner(ctx, name) {
}
}

let timer;
function defer() {
clearTimeout(timer);
timer = setTimeout(exec);
}

function setup(ctx, name = '') {
ctx.state.__test__ = '';
ctx.state.__suite__ = name;
Expand All @@ -110,6 +116,7 @@ function setup(ctx, name = '') {
let run = runner.bind(0, copy, name);
Object.assign(ctx, context(copy.state));
UVU_QUEUE[globalThis.UVU_INDEX || 0].push(run);
isCLI || defer();
};
return test;
}
Expand Down Expand Up @@ -144,5 +151,3 @@ export async function exec(bail) {

if (isNode) process.exitCode = code;
}

isCLI || Promise.resolve().then(exec);

0 comments on commit 2a3a598

Please sign in to comment.