Skip to content

Commit

Permalink
refactor: rebase and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed Aug 28, 2024
1 parent 9a7af35 commit bc0385f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-ants-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/reassure-cli': minor
---

Passthrough args after -- to Jest
27 changes: 16 additions & 11 deletions packages/cli/src/commands/measure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export async function run(options: MeasureOptions) {
const header = { metadata };
writeFileSync(outputFile, JSON.stringify(header) + '\n');

const nodeMajorVersion = getNodeMajorVersion();
logger.verbose(`Node.js version: ${nodeMajorVersion} (${process.versions.node})`);

const testRunnerPath = process.env.TEST_RUNNER_PATH ?? getJestBinPath();
if (!testRunnerPath) {
logger.error(
Expand All @@ -56,13 +59,15 @@ export async function run(options: MeasureOptions) {
return;
}

const baseRunnerArgs = process.env.TEST_RUNNER_ARGS ?? buildDefaultTestRunnerArgs(options);
const passthroughRunnerArgs = options._ ?? [];

const nodeMajorVersion = getNodeMajorVersion();
logger.verbose(`Node.js version: ${nodeMajorVersion} (${process.versions.node})`);
const baseTestRunnerArgs = process.env.TEST_RUNNER_ARGS ?? buildDefaultTestRunnerArgs(options);
const passthroughTestRunnerArgs = options._ ?? [];

const nodeArgs = [...getNodeFlags(nodeMajorVersion), testRunnerPath, baseRunnerArgs, ...passthroughRunnerArgs];
const nodeArgs = [
...getNodeFlags(nodeMajorVersion),
testRunnerPath,
...baseTestRunnerArgs,
...passthroughTestRunnerArgs,
];
logger.verbose('Running tests using command:');
logger.verbose(`$ node \\\n ${nodeArgs.join(' \\\n ')}\n`);

Expand Down Expand Up @@ -147,23 +152,23 @@ export const command: CommandModule<{}, MeasureOptions> = {
handler: (args) => run(args),
};

function buildDefaultTestRunnerArgs(options: MeasureOptions) {
function buildDefaultTestRunnerArgs(options: MeasureOptions): string[] {
if (options.testMatch && options.testRegex) {
logger.error('Configuration options "testMatch" and "testRegex" cannot be used together.');
process.exit(1);
}

const commonArgs = '--runInBand';
const commonArgs = ['--runInBand'];

if (options.testMatch) {
return `${commonArgs} --testMatch=${toShellArray(options.testMatch)}`;
return [...commonArgs, `--testMatch=${toShellArray(options.testMatch)}`];
}

if (options.testRegex) {
return `${commonArgs} --testRegex=${toShellArray(options.testRegex)}`;
return [...commonArgs, `--testRegex=${toShellArray(options.testRegex)}`];
}

return `${commonArgs} --testMatch=${toShellArray(DEFAULT_TEST_MATCH)}`;
return [...commonArgs, `--testMatch=${toShellArray(DEFAULT_TEST_MATCH)}`];
}

function toShellArray(texts: string[]): string {
Expand Down

0 comments on commit bc0385f

Please sign in to comment.