Skip to content

Commit 1514c5e

Browse files
committed
refactor(test): run tests directly via bun test --parallel
Drop the custom scripts/run-tests.ts wrapper in favor of bun test's built-in --parallel mode, which implies --isolate and gives module-state isolation between test files. Expand lint and format coverage to test/e2e/ and add an .oxfmtrc.json that excludes fixture lockfiles. Clean up the e2e fixture helpers: drop the unused description parameter from createTestUser/deleteTestUser, pass dotenv: false to clerkSetup so the CLI's own env-loading is what gets tested, and tidy the per-test user lifecycle and logger surfaces.
1 parent 1102614 commit 1514c5e

22 files changed

Lines changed: 319 additions & 505 deletions

.oxfmtrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"ignorePatterns": ["test/e2e/fixtures/**"]
4+
}

.oxlintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
23
"rules": {
34
"unicorn/no-process-exit": "error",
45
"no-console": "error"
56
},
7+
"ignorePatterns": ["test/e2e/fixtures/**"],
68
"overrides": [
79
{
810
"files": [

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bunx playwright install chromium
8888

8989
bun run test:e2e:op # Run all E2E tests (secrets from 1Password)
9090
bun run test:e2e:op -- --filter react # Run only tests matching "react"
91-
bun run test:e2e:op -- --debug # Verbose helper logging (sets CLERK_E2E_DEBUG=1)
91+
bun run test:e2e:op -- --debug # Force serial execution for parsing logs (sets CLERK_E2E_DEBUG=1)
9292
bun run test:e2e:op -- --har # Capture HAR files to test/e2e/.har for network debugging
9393
bun run test:e2e:op -- --har-dir ./out # Capture HAR files to a custom directory
9494
bun run e2e:refresh-fixtures # Re-scaffold fixture projects from upstream CLIs

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
"scripts": {
88
"build": "bun run --filter @clerk/cli-core build",
99
"dev": "bun run --cwd packages/cli-core dev",
10-
"test": "bun run scripts/run-tests.ts --pattern 'packages/cli-core/src/**/*.test.ts' --pattern 'scripts/**/*.test.ts'",
11-
"test:e2e": "bun run scripts/run-tests.ts --pattern 'test/e2e/*.test.ts' --retries 1",
10+
"test": "bun test 'packages/cli-core/src/' 'scripts/' --parallel --only-failures",
11+
"test:e2e": "bun test 'test/e2e/' --retry 1 --parallel --only-failures",
1212
"test:e2e:op": "bun run scripts/run-e2e-op.ts",
1313
"e2e:refresh-fixtures": "bun run scripts/refresh-e2e-fixtures.ts",
1414
"typecheck": "bun run --filter './packages/*' typecheck && tsc --noEmit -p scripts/tsconfig.json && tsc --noEmit -p test/e2e/tsconfig.json",
15-
"lint": "bun run --filter './packages/*' lint && oxlint -c .oxlintrc.json scripts/",
16-
"format": "bun run --filter './packages/*' format && oxfmt --write scripts/",
17-
"format:check": "bun run --filter './packages/*' format:check && oxfmt --check scripts/",
15+
"lint": "bun run --filter './packages/*' lint && oxlint -c .oxlintrc.json scripts/ test/e2e/",
16+
"format": "bun run --filter './packages/*' format && oxfmt --write scripts/ test/e2e/",
17+
"format:check": "bun run --filter './packages/*' format:check && oxfmt --check scripts/ test/e2e/",
1818
"check:patches": "bun run scripts/check-patches.ts",
1919
"build:compile": "bun run --filter @clerk/cli-core build:compile",
2020
"version-packages": "bun changeset version",

packages/cli-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"typecheck": "tsc --noEmit -p tsconfig.json",
1414
"lint": "oxlint src/",
1515
"format": "oxfmt --write src/",
16-
"format:check": "oxfmt --check src/"
16+
"format:check": "oxfmt --check src/",
17+
"test": "bun test src/ --parallel"
1718
},
1819
"dependencies": {
1920
"@clerk/cli-extras": "workspace:*",

scripts/run-tests.ts

Lines changed: 0 additions & 197 deletions
This file was deleted.

test/e2e/astro.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { FixtureConfig } from "./lib/types.ts";
66
const fixtureDir = join(import.meta.dir, "fixtures/astro");
77

88
export const config = {
9-
description: "Astro with TypeScript",
109
scaffoldCmd: [
1110
"npx",
1211
"--yes",
@@ -25,7 +24,7 @@ export const config = {
2524
} satisfies FixtureConfig;
2625

2726
describe("Astro with Typescript", () => {
28-
const getFixture = createGetFixture(fixtureDir, config);
27+
const getFixture = createGetFixture(fixtureDir);
2928

3029
describe("clerk init", () => {
3130
runFixtureTest(getFixture, config);

test/e2e/lib/dev-server.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,14 @@ async function tryStart(opts: {
9494
devCmd: string[];
9595
port: number;
9696
projectDir: string;
97-
fixtureName: string;
9897
}): Promise<StartAttempt> {
99-
const { devCmd, port, projectDir, fixtureName } = opts;
98+
const { devCmd, port, projectDir } = opts;
10099
const fullCmd = buildDevCommand(devCmd, port);
101100
const host = getDevServerHost(devCmd);
102101
const stderrLines: string[] = [];
103102
const stdoutLines: string[] = [];
104103

105-
log(fixtureName, `starting dev server: npx ${fullCmd.join(" ")} on port ${port}`);
104+
log(`starting dev server: npx ${fullCmd.join(" ")} on port ${port}`);
106105

107106
const proc = Bun.spawn(["npx", ...fullCmd], {
108107
cwd: projectDir,
@@ -152,7 +151,7 @@ async function tryStart(opts: {
152151
while (Date.now() < deadline) {
153152
// Early-bail: framework reported the port is taken. Don't wait the full timeout.
154153
if (hasPortConflict()) {
155-
log(fixtureName, `port ${port} reported in use by dev server`);
154+
log(`port ${port} reported in use by dev server`);
156155
await killAndAwait();
157156
return { kind: "port_conflict" };
158157
}
@@ -161,7 +160,7 @@ async function tryStart(opts: {
161160
// retrying. Detect that as a port conflict if the output supports it.
162161
if (proc.exitCode !== null) {
163162
if (hasPortConflict()) {
164-
log(fixtureName, `dev server exited (port ${port} in use)`);
163+
log(`dev server exited (port ${port} in use)`);
165164
return { kind: "port_conflict" };
166165
}
167166
throw new Error(
@@ -171,7 +170,7 @@ async function tryStart(opts: {
171170
}
172171

173172
if (await canConnect(host, port, 1000)) {
174-
log(fixtureName, `dev server ready (accepting TCP on ${host}:${port})`);
173+
log(`dev server ready (accepting TCP on ${host}:${port})`);
175174
return {
176175
kind: "ready",
177176
value: { proc, port, host, stdout: stdoutLines, stderr: stderrLines },
@@ -204,7 +203,6 @@ async function tryStart(opts: {
204203
export async function startDevServer(opts: {
205204
devCmd: string[];
206205
projectDir: string;
207-
fixtureName: string;
208206
}): Promise<ReadyServer> {
209207
for (let attempt = 1; attempt <= MAX_BIND_ATTEMPTS; attempt++) {
210208
const port = await getAvailablePort();
@@ -217,14 +215,14 @@ export async function startDevServer(opts: {
217215
`(last attempted port: ${port}).`,
218216
);
219217
}
220-
log(opts.fixtureName, `port ${port} collided, retrying (${attempt + 1}/${MAX_BIND_ATTEMPTS})`);
218+
log(`port ${port} collided, retrying (${attempt + 1}/${MAX_BIND_ATTEMPTS})`);
221219
}
222220
throw new Error("unreachable");
223221
}
224222

225223
/** Kill a dev server process, falling back to SIGKILL after 5 seconds. */
226-
export async function killDevServer(proc: Subprocess, fixtureName: string): Promise<void> {
227-
log(fixtureName, "killing dev server");
224+
export async function killDevServer(proc: Subprocess): Promise<void> {
225+
log("killing dev server");
228226
proc.kill("SIGTERM");
229227

230228
const timeout = setTimeout(() => {
@@ -237,5 +235,5 @@ export async function killDevServer(proc: Subprocess, fixtureName: string): Prom
237235
clearTimeout(timeout);
238236
}
239237

240-
log(fixtureName, "dev server stopped");
238+
log("dev server stopped");
241239
}

0 commit comments

Comments
 (0)