mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-25 01:42:02 +03:00
2f6c4e3696
Co-authored-by: Hongtao Lye <codert.sn@gmail.com> Co-authored-by: liuyi <forehalo@gmail.com> Co-authored-by: LongYinan <lynweklm@gmail.com> Co-authored-by: X1a0t <405028157@qq.com> Co-authored-by: JimmFly <yangjinfei001@gmail.com> Co-authored-by: Peng Xiao <pengxiao@outlook.com> Co-authored-by: xiaodong zuo <53252747+zuoxiaodong0815@users.noreply.github.com> Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: Qi <474021214@qq.com> Co-authored-by: danielchim <kahungchim@gmail.com>
73 lines
1.5 KiB
TypeScript
Executable File
73 lines
1.5 KiB
TypeScript
Executable File
#!/usr/bin/env ts-node-esm
|
|
import { resolve } from 'node:path';
|
|
|
|
import * as p from '@clack/prompts';
|
|
import { spawn } from 'child_process';
|
|
import { readdir } from 'fs/promises';
|
|
import * as process from 'process';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import pkg from '../package.json' assert { type: 'json' };
|
|
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
const testDir = resolve(root, 'src', 'tests');
|
|
const files = await readdir(testDir);
|
|
|
|
const watchMode = process.argv.includes('--watch');
|
|
|
|
const sharedArgs = [
|
|
...pkg.nodemonConfig.nodeArgs,
|
|
'--test',
|
|
watchMode ? '--watch' : '',
|
|
];
|
|
|
|
const env = {
|
|
PATH: process.env.PATH,
|
|
NODE_ENV: 'test',
|
|
DATABASE_URL: process.env.DATABASE_URL,
|
|
NODE_NO_WARNINGS: '1',
|
|
};
|
|
|
|
if (process.argv[2] === 'all') {
|
|
const cp = spawn('node', [...sharedArgs, resolve(testDir, '*')], {
|
|
cwd: root,
|
|
env,
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
});
|
|
cp.on('exit', code => {
|
|
process.exit(code ?? 0);
|
|
});
|
|
} else {
|
|
const result = await p.group({
|
|
file: () =>
|
|
p.select({
|
|
message: 'Select a file to run',
|
|
options: files.map(file => ({
|
|
label: file,
|
|
value: file as any,
|
|
})),
|
|
}),
|
|
});
|
|
|
|
const target = resolve(testDir, result.file);
|
|
|
|
const cp = spawn(
|
|
'node',
|
|
[
|
|
...sharedArgs,
|
|
'--test-reporter=spec',
|
|
'--test-reporter-destination=stdout',
|
|
target,
|
|
],
|
|
{
|
|
cwd: root,
|
|
env,
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
}
|
|
);
|
|
cp.on('exit', code => {
|
|
process.exit(code ?? 0);
|
|
});
|
|
}
|