Repository navigation
Expand file tree
/
Copy pathrun-node-tests.mjs
More file actions
56 lines (49 loc) · 1.67 KB
/
Copy pathrun-node-tests.mjs
File metadata and controls
56 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
import { readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
import { spawn } from 'node:child_process'
const testsDir = join(process.cwd(), 'tests')
function walk(dir) {
// eslint-disable-next-line security/detect-non-literal-fs-filename -- dir is derived from controlled repository test folder
const entries = readdirSync(dir)
const files = []
for (const entry of entries) {
const full = join(dir, entry)
// eslint-disable-next-line security/detect-non-literal-fs-filename -- full is constrained to discovered files under tests/
const st = statSync(full)
if (st.isDirectory()) {
// Skip Playwright tests from node test runner
if (full.includes(`${join('tests', 'playwright')}`)) {continue}
files.push(...walk(full))
} else if (entry.endsWith('.test.js')) {
files.push(full)
}
}
return files
}
let files = walk(testsDir)
// Optionally skip network-dependent tests in restricted environments
const skipNetwork = ['1', 'true', 'yes'].includes(
String(process.env.WEBSSH2_SKIP_NETWORK || '').toLowerCase()
)
if (skipNetwork) {
files = files.filter((f) => !f.endsWith('/ssh.test.js'))
// Also skip HTTP route tests that bind/listen via supertest in restricted envs
files = files.filter((f) => !f.endsWith('/post-auth.test.js'))
}
if (files.length === 0) {
console.error('No test files found to run.')
process.exit(1)
}
const child = spawn(
process.execPath,
['--test', '--test-concurrency=1', ...files],
{ stdio: 'inherit' }
)
child.on('exit', (code, signal) => {
if (signal) {
console.error(`Tests exited with signal ${signal}`)
process.exit(1)
}
process.exit(code ?? 1)
})