2022-03-16 12:34:27 +00:00
|
|
|
export interface RunTestOptions {
|
|
|
|
rootDir: string,
|
2022-03-17 21:31:06 +00:00
|
|
|
dev?: boolean,
|
|
|
|
watch?: boolean
|
2022-03-16 12:34:27 +00:00
|
|
|
runner?: 'vitest'
|
|
|
|
}
|
|
|
|
|
|
|
|
const RunTestDefaults: Partial<RunTestOptions> = {
|
|
|
|
runner: 'vitest'
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function runTests (opts: RunTestOptions) {
|
|
|
|
opts = { ...RunTestDefaults, ...opts }
|
|
|
|
|
|
|
|
if (opts.runner !== 'vitest') {
|
|
|
|
throw new Error(`Unsupported runner: ${opts.runner}. Currently only vitest runner is supported.`)
|
|
|
|
}
|
2022-03-17 21:31:06 +00:00
|
|
|
|
|
|
|
if (opts.dev) {
|
|
|
|
// Set default dev option for @nuxt/test-utils
|
|
|
|
process.env.NUXT_TEST_DEV = 'true'
|
|
|
|
}
|
|
|
|
|
2022-03-16 12:34:27 +00:00
|
|
|
const { startVitest } = await import('vitest/dist/node.js')
|
|
|
|
const succeeded = await startVitest(
|
|
|
|
[] /* argv */,
|
|
|
|
// Vitest options
|
|
|
|
{
|
|
|
|
root: opts.rootDir,
|
2022-03-17 21:31:06 +00:00
|
|
|
run: !opts.watch
|
2022-03-16 12:34:27 +00:00
|
|
|
},
|
|
|
|
// Vite options
|
|
|
|
{
|
|
|
|
esbuild: {
|
|
|
|
tsconfigRaw: '{}'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if (!succeeded) {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
}
|