feat(tests): implement test runner script for specific test execution

This commit is contained in:
Sam Chau
2026-01-21 00:03:53 +10:30
parent a64dc8a858
commit 7aaebf7dfe
2 changed files with 58 additions and 1 deletions

57
scripts/test.ts Normal file
View File

@@ -0,0 +1,57 @@
/**
* Test runner script that allows running specific test files or directories
*
* Usage:
* deno task test # Run all tests
* deno task test filters # Run src/tests/upgrades/filters.test.ts
* deno task test upgrades # Run all tests in src/tests/upgrades/
* deno task test logger # Run all tests in src/tests/logger/
*/
const aliases: Record<string, string> = {
// Individual test files
filters: 'src/tests/upgrades/filters.test.ts',
normalize: 'src/tests/upgrades/normalize.test.ts',
selectors: 'src/tests/upgrades/selectors.test.ts',
backup: 'src/tests/jobs/createBackup.test.ts',
cleanup: 'src/tests/logger/cleanupLogs.test.ts',
// Directories
upgrades: 'src/tests/upgrades',
jobs: 'src/tests/jobs',
logger: 'src/tests/logger'
};
// Get the test target from args
const target = Deno.args[0];
const testPath = target ? aliases[target] ?? target : 'src/tests';
// Check if it's a valid path
if (target && !aliases[target]) {
// Check if it's a direct path
try {
await Deno.stat(target);
} catch {
console.error(`Unknown test target: "${target}"`);
console.error('\nAvailable aliases:');
for (const [alias, path] of Object.entries(aliases)) {
console.error(` ${alias.padEnd(12)} -> ${path}`);
}
Deno.exit(1);
}
}
console.log(`Running tests: ${testPath}\n`);
const cmd = new Deno.Command('deno', {
args: ['test', testPath, '--allow-read', '--allow-write', '--allow-env'],
env: {
...Deno.env.toObject(),
APP_BASE_PATH: './dist/test'
},
stdout: 'inherit',
stderr: 'inherit'
});
const { code } = await cmd.output();
Deno.exit(code);