test: include mobile app in root test runner

This commit is contained in:
lucaronin
2026-05-04 00:52:08 +02:00
parent a122a11d46
commit 82545acbaa
3 changed files with 47 additions and 4 deletions

View File

@@ -5,10 +5,26 @@ if (testArgs[0] === '--') {
testArgs.shift()
}
const workspaceTarget = findWorkspaceTarget(testArgs)
if (workspaceTarget) {
run('pnpm', [
'--filter',
workspaceTarget.filter,
'exec',
'vitest',
'run',
'--config',
'vitest.config.ts',
...workspaceTarget.args,
])
process.exit(0)
}
run('pnpm', ['exec', 'vitest', 'run', ...testArgs])
if (testArgs.length === 0) {
run('pnpm', ['--filter', './packages/*', 'test'])
if (isFullSuite(testArgs)) {
run('pnpm', ['--filter', './apps/*', 'test', '--', ...testArgs])
run('pnpm', ['--filter', './packages/*', 'test', '--', ...testArgs])
}
function run(command, args) {
@@ -25,3 +41,24 @@ function run(command, args) {
process.exit(result.status ?? 1)
}
}
function findWorkspaceTarget(args) {
const workspacePaths = ['./apps/mobile', './packages/markdown']
return workspacePaths.map((workspacePath) => rebaseArgs(workspacePath, args)).find(Boolean)
}
function rebaseArgs(workspacePath, args) {
const prefix = `${workspacePath.slice(2)}/`
if (!args.some((arg) => arg.startsWith(prefix))) {
return null
}
return {
filter: workspacePath,
args: args.map((arg) => arg.startsWith(prefix) ? arg.slice(prefix.length) : arg),
}
}
function isFullSuite(args) {
return args.every((arg) => arg.startsWith('-'))
}