Skip to content

Commit

Permalink
feat: ✨ added vitest arg passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Dec 5, 2024
1 parent 543bda2 commit d892adc
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/good-shoes-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@moonwall/cli": patch
"@moonwall/tests": patch
---

Added vitest arg pass through
13 changes: 13 additions & 0 deletions .changeset/smooth-bears-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@moonwall/cli": patch
---

### Enhanced Test CLI Options

#### New Features

- Added support for passing Vitest configuration options directly through CLI

```bash
moonwall test dev_test --vitest "bail=2 retry=2"
```
6 changes: 6 additions & 0 deletions packages/cli/src/cmds/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ yargs(hideBin(process.argv))
describe: "Update all snapshots",
alias: "u",
type: "boolean",
})
.option("vitestArgPassthrough", {
describe: "Arguments to pass directly to Vitest (space-delimited)",
alias: "vitest",
type: "string",
});
},
async (args) => {
Expand All @@ -129,6 +134,7 @@ yargs(hideBin(process.argv))
subDirectory: args.subDirectory,
shard: args.testShard,
update: args.update,
vitestPassthroughArgs: args.vitestArgPassthrough?.split(" "),
}))
) {
process.exitCode = 1;
Expand Down
33 changes: 26 additions & 7 deletions packages/cli/src/cmds/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type testRunArgs = {
subDirectory?: string;
shard?: string;
update?: boolean;
vitestPassthroughArgs?: string[];
};

export async function executeTests(env: Environment, testRunArgs?: testRunArgs) {
Expand Down Expand Up @@ -92,7 +93,23 @@ export async function executeTests(env: Environment, testRunArgs?: testRunArgs)
}
}

const additionalArgs: testRunArgs = testRunArgs || {};
const additionalArgs: Omit<testRunArgs, "vitestPassthroughArgs"> = testRunArgs
? {
testNamePattern: testRunArgs.testNamePattern,
subDirectory: testRunArgs.subDirectory,
shard: testRunArgs.shard,
update: testRunArgs.update,
}
: {};

const vitestOptions = testRunArgs?.vitestPassthroughArgs?.reduce<UserConfig>((acc, arg) => {
const [key, value] = arg.split("=");
return {
// biome-ignore lint/performance/noAccumulatingSpread: this is fine
...acc,
[key]: Number(value) || value,
};
}, {});

// transform in regexp pattern
if (env.skipTests && env.skipTests.length > 0) {
Expand Down Expand Up @@ -126,12 +143,14 @@ export async function executeTests(env: Environment, testRunArgs?: testRunArgs)
: env.testFileDir;

const folders = testFileDir.map((folder) => path.join(".", folder, "/"));
resolve(
(await startVitest("test", folders, {
...options,
...additionalArgs,
})) as Vitest
);
const optionsToUse = {
...options,
...additionalArgs,
...vitestOptions,
} satisfies UserConfig;

console.log(`Options to use: ${JSON.stringify(optionsToUse, null, 2)}`);
resolve((await startVitest("test", folders, optionsToUse)) as Vitest);
} catch (e) {
console.error(e);
reject(e);
Expand Down
12 changes: 12 additions & 0 deletions test/moonwall.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@
},
"connections": []
},
{
"name": "passthrough_test",
"testFileDir": ["suites/multi_fail"],
"description": "Testing that bail can be passed through",
"foundation": {
"type": "read_only",
"launchSpec": {
"disableRuntimeVersionCheck": true
}
},
"connections": []
},
{
"name": "failing_prescript",
"testFileDir": ["suites/basic"],
Expand Down
57 changes: 57 additions & 0 deletions test/suites/multi_fail/test_multifails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { expect, describeSuite, beforeAll } from "@moonwall/cli";
import { setupLogger } from "@moonwall/util";
import { setTimeout } from "timers/promises";
describeSuite({
id: "F01",
title: "This test suite fails multiple times",
foundationMethods: "read_only",
testCases: ({ it, log }) => {
const anotherLogger = setupLogger("additional");

beforeAll(() => {
log("Test suite setup");
});

it({
id: "T01",
title: "This is a bool test case",
test: async() => {
await setTimeout(500)
expect(false).to.be.true;
},
});
it({
id: "T02",
title: "This is a bool test case",
test: async() => {
const rand = Math.floor(Math.random() * 1000);
expect(rand).toBeGreaterThan(800)
},
});
it({
id: "T03",
title: "This is a bool test case",
test: async() => {
await setTimeout(500)
expect(false).to.be.true;
},
});
it({
id: "T04",
title: "This is a bool test case",
test: async() => {
await setTimeout(500)
expect(false).to.be.true;
},
});
it({
id: "T05",
title: "This is a bool test case",
test: async() => {
await setTimeout(500)
expect(false).to.be.true;
},
});

},
});

0 comments on commit d892adc

Please sign in to comment.