|
| 1 | +#!/usr/bin/env node |
| 2 | +import { spawnSync } from 'node:child_process'; |
| 3 | +import { createRequire } from 'node:module'; |
| 4 | +// oxlint-disable-next-line no-restricted-imports |
| 5 | +import { dirname, resolve } from 'node:path'; |
| 6 | +import { parseArgs } from 'node:util'; |
| 7 | +import { globSync } from 'tinyglobby'; |
| 8 | + |
| 9 | +const { values } = parseArgs({ |
| 10 | + options: { |
| 11 | + runtime: { type: 'string', default: 'bun' }, |
| 12 | + smoke: { type: 'boolean', default: false }, |
| 13 | + }, |
| 14 | +}); |
| 15 | + |
| 16 | +const useBun = |
| 17 | + values.runtime === 'bun' && spawnSync('bun', ['--version'], { stdio: 'ignore', shell: true }).status === 0; |
| 18 | + |
| 19 | +const patterns = values.smoke |
| 20 | + ? ['test/*.test.ts', 'test/{plugins,util}/*.test.ts'] |
| 21 | + : ['test/*.test.ts', 'test/**/*.test.ts']; |
| 22 | + |
| 23 | +const files = globSync(patterns); |
| 24 | + |
| 25 | +const [major, minor] = process.versions.node.split('.').map(Number); |
| 26 | +const nativeTS = major >= 24 || (major === 22 && minor >= 18); |
| 27 | + |
| 28 | +const require = createRequire(import.meta.url); |
| 29 | +const tsxBin = nativeTS ? null : resolve(dirname(require.resolve('tsx/package.json')), require('tsx/package.json').bin); |
| 30 | + |
| 31 | +const result = useBun |
| 32 | + ? spawnSync('bun', ['test', ...files], { stdio: 'inherit' }) |
| 33 | + : spawnSync(process.execPath, [...(tsxBin ? [tsxBin] : []), '--test', ...files], { stdio: 'inherit' }); |
| 34 | + |
| 35 | +process.exit(result.status ?? 1); |
0 commit comments