Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/wb/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const builder = {
description: 'Reduce redundant outputs',
type: 'boolean',
},
bail: {
description: 'Stop tests after the first failure',
type: 'boolean',
},
'unit-timeout': {
description: 'Timeout for unit tests',
type: 'number',
Expand Down
24 changes: 18 additions & 6 deletions packages/wb/src/scripts/execution/baseScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export abstract class BaseScripts {
): Promise<string> {
const port = await checkAndKillPortProcess(project.env.PORT, project);
const suffix = project.packageJson.scripts?.['test/e2e-additional'] ? ' && YARN test/e2e-additional' : '';
const playwrightCommand = buildPlaywrightCommand(playwrightArgs, argv.targets);
const playwrightCommand = buildPlaywrightCommand(playwrightArgs, argv.targets, argv.bail);
if (project.skipLaunchingServerForPlaywright) {
return `${playwrightCommand}${suffix}`;
}
Expand All @@ -116,10 +116,12 @@ export abstract class BaseScripts {
testUnit(project: Project, argv: TestArgv): string {
const testTarget = argv.targets?.join(' ') || 'test/unit/';
if (project.hasVitest) {
const bailOption = argv.bail ? ' --bail=1' : '';
// Since this command is referred from other commands, we have to use "vitest run" (non-interactive mode).
return `YARN vitest run ${testTarget} --color --passWithNoTests --allowOnly`;
return `YARN vitest run ${testTarget} --color --passWithNoTests --allowOnly${bailOption}`;
} else if (project.isBunAvailable) {
return `bun test ${testTarget}`;
const bailOption = argv.bail ? ' --bail' : '';
return `bun test ${testTarget}${bailOption}`;
}
return 'echo "No tests."';
}
Expand Down Expand Up @@ -151,11 +153,11 @@ function findEcosystemConfigPath(project: Project): string | undefined {
}
}

function buildPlaywrightCommand(playwrightArgs: string, targets: TestArgv['targets']): string {
function buildPlaywrightCommand(playwrightArgs: string, targets: TestArgv['targets'], bail?: boolean): string {
const base = 'BUN playwright';
const target = targets?.join(' ') || 'test/e2e/';
if (!playwrightArgs.startsWith('test ') || !targets?.length) {
return `${base} ${playwrightArgs}`;
return appendPlaywrightBailOption(`${base} ${playwrightArgs}`, bail);
}

const rest = playwrightArgs.slice('test '.length).trim();
Expand All @@ -165,5 +167,15 @@ function buildPlaywrightCommand(playwrightArgs: string, targets: TestArgv['targe
} else {
parts[0] = target;
}
return `${base} test ${parts.join(' ')}`;
return appendPlaywrightBailOption(`${base} test ${parts.join(' ')}`, bail);
}

function appendPlaywrightBailOption(command: string, bail?: boolean): string {
if (!bail || !command.includes('playwright test')) {
return command;
}
if (/--max-failures(?:=|\s)/.test(command)) {
return command;
}
return `${command} --max-failures=1`;
}
3 changes: 2 additions & 1 deletion packages/wb/src/scripts/execution/httpServerScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class HttpServerScripts extends BaseScripts {
const port = await checkAndKillPortProcess(project.env.PORT, project);
const suffix = project.packageJson.scripts?.['test/e2e-additional'] ? ' && YARN test/e2e-additional' : '';
const testTarget = argv.targets && argv.targets.length > 0 ? argv.targets.join(' ') : 'test/e2e/';
const bailOption = argv.bail ? ' --bail=1' : '';

return `YARN concurrently --kill-others --raw --success first
"${startCommand} && exit 1"
"wait-on -t 600000 -i 2000 http-get://127.0.0.1:${port}
&& vitest run ${testTarget} --color --passWithNoTests --allowOnly${suffix}"`;
&& vitest run ${testTarget} --color --passWithNoTests --allowOnly${bailOption}${suffix}"`;
}
}

Expand Down