Skip to content

Commit

Permalink
try using registerCompletionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Mar 5, 2024
1 parent a0a8558 commit 0c58a48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@shopify/semaphore": "^3.0.2",
"@sindresorhus/is": "^6.2.0",
"@sindresorhus/tsconfig": "^5.0.0",
"@types/common-tags": "^1.8.4",
Expand Down Expand Up @@ -117,7 +116,6 @@
"--import=tsimp"
],
"environmentVariables": {
"concurrency": "25",
"TSIMP_DIAG": "ignore"
}
}
Expand Down
12 changes: 5 additions & 7 deletions test/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable ava/no-ignored-test-files */

import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {Semaphore} from '@shopify/semaphore';
import test, {registerCompletionHandler} from 'ava';
import {
execa,
type ExecaChildProcess,
Expand Down Expand Up @@ -62,12 +61,12 @@ type VerifyCliMacroArguments = [{
};
}, 'expected' | 'error'>];

const semaphore = new Semaphore(Number(process.env['concurrency']) || 5);
registerCompletionHandler(() => {
process.exit(0);
});

export const _verifyCli = (baseFixture = defaultFixture) => test.macro<VerifyCliMacroArguments>(
async (t, {fixture = baseFixture, args, execaOptions, expected, error}) => {
const permit = await semaphore.acquire();

const assertions = await t.try(async tt => {
const arguments_ = args ? args.split(' ') : [];
const {all: output, exitCode} = await spawnFixture(fixture, arguments_, {reject: false, all: true, ...execaOptions}) as ExecaReturnValue & {all: string};
Expand Down Expand Up @@ -97,6 +96,5 @@ export const _verifyCli = (baseFixture = defaultFixture) => test.macro<VerifyCli
});

assertions.commit({retainLogs: !assertions.passed});
await permit.release();
},
);

0 comments on commit 0c58a48

Please sign in to comment.