diff --git a/packages/wb/src/commands/test.ts b/packages/wb/src/commands/test.ts index 0f379d1df..9a9f9e6af 100644 --- a/packages/wb/src/commands/test.ts +++ b/packages/wb/src/commands/test.ts @@ -243,7 +243,7 @@ function getDefaultUnitTargets(project: Project): string[] | false { return []; } if (project.hasVitest && fs.existsSync(path.join(project.dirPath, 'test'))) { - return ['test']; + return fs.existsSync(path.join(project.dirPath, 'test', 'e2e')) ? ['test', '--exclude', 'test/e2e/**'] : ['test']; } return false; } diff --git a/packages/wb/src/scripts/execution/baseScripts.ts b/packages/wb/src/scripts/execution/baseScripts.ts index 4e5e6a594..00b62ede1 100644 --- a/packages/wb/src/scripts/execution/baseScripts.ts +++ b/packages/wb/src/scripts/execution/baseScripts.ts @@ -6,6 +6,7 @@ import { buildShellCommand, buildShellEnvironmentAssignment } from '../../utils/ import type { ScriptArgv } from '../builder.js'; import { toDevNull } from '../builder.js'; import { dockerScripts } from '../dockerScripts.js'; +import { drizzleScripts } from '../drizzleScripts.js'; import { prismaScripts } from '../prismaScripts.js'; export interface TestE2EOptions { @@ -88,11 +89,15 @@ export abstract class BaseScripts { ecosystemConfigPath === undefined ? [ `YARN wb buildIfNeeded ${argv.verbose ? '--verbose' : ''}`.trim(), - `node dist/index.js ${argv.normalizedArgsText ?? ''}`.trim(), + `${project.isBunAvailable ? 'bun' : 'node'} dist/index.js ${argv.normalizedArgsText ?? ''}`.trim(), ] : [project.buildCommand, `pm2-runtime start --no-autorestart ${ecosystemConfigPath}`]; - return [...(project.hasPrisma ? prismaScripts.migrate(project).split('&&') : []), ...commands] + const migrationCommands = [ + ...(project.hasPrisma ? [prismaScripts.migrate(project)] : []), + ...(project.hasDrizzle ? [drizzleScripts.migrate(project)] : []), + ]; + return [...migrationCommands.flatMap((cmd) => cmd.split('&&')), ...commands] .filter(Boolean) .map((cmd) => `${cmd} ${toDevNull(argv)}`.trim()) .join(' && '); diff --git a/packages/wb/src/scripts/execution/httpServerScripts.ts b/packages/wb/src/scripts/execution/httpServerScripts.ts index 4131980f9..5e44fb52d 100644 --- a/packages/wb/src/scripts/execution/httpServerScripts.ts +++ b/packages/wb/src/scripts/execution/httpServerScripts.ts @@ -33,6 +33,8 @@ 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 targets = argv.targets?.map(String); + const normalizedTargets = targets?.length ? targets : ['test/e2e/']; + const testCommand = this.testUnit(project, { ...argv, targets: normalizedTargets }); return buildShellCommand([ 'YARN', 'wb', @@ -42,16 +44,7 @@ class HttpServerScripts extends BaseScripts { '--success', 'first', `${startCommand} && exit 1`, - `wait-on -t 600000 -i 2000 http-get://127.0.0.1:${port} - && ${buildShellCommand([ - 'vitest', - 'run', - ...(targets && targets.length > 0 ? targets : ['test/e2e/']), - '--color', - '--passWithNoTests', - '--allowOnly', - ...(argv.bail ? ['--bail=1'] : []), - ])}${suffix}`, + `wait-on -t 600000 -i 2000 http-get://127.0.0.1:${port} && ${testCommand}${suffix}`, ]); } } diff --git a/packages/wb/test/scripts/execution/httpServerScripts.test.ts b/packages/wb/test/scripts/execution/httpServerScripts.test.ts index 3c1f4bee9..78fd0b7af 100644 --- a/packages/wb/test/scripts/execution/httpServerScripts.test.ts +++ b/packages/wb/test/scripts/execution/httpServerScripts.test.ts @@ -18,6 +18,7 @@ describe('HttpServerScripts.testE2E', () => { env: { WB_ENV: 'test', PORT: '3000' }, packageJson: { scripts: {} }, hasPlaywrightConfig: false, + hasVitest: true, hasPrisma: false, buildCommand: 'echo "no build"', findFile: vi.fn().mockImplementation(() => { @@ -51,6 +52,7 @@ describe('HttpServerScripts.testE2E', () => { env: { WB_ENV: 'test', PORT: '3000' }, packageJson: { scripts: {} }, hasPlaywrightConfig: false, + hasVitest: true, hasPrisma: false, buildCommand: 'echo "no build"', findFile: vi.fn().mockImplementation(() => { @@ -73,8 +75,8 @@ describe('HttpServerScripts.testE2E', () => { '--success', 'first', 'YARN wb buildIfNeeded && node dist/index.js && exit 1', - `wait-on -t 600000 -i 2000 http-get://127.0.0.1:3000 - && ${buildShellCommand([ + `wait-on -t 600000 -i 2000 http-get://127.0.0.1:3000 && ${buildShellCommand([ + 'YARN', 'vitest', 'run', `test/e2e/quo'te.spec.ts`, @@ -82,6 +84,7 @@ describe('HttpServerScripts.testE2E', () => { '--color', '--passWithNoTests', '--allowOnly', + '--watch=false', ])}`, ]) );