-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
executable file
·50 lines (46 loc) · 1.42 KB
/
test.js
File metadata and controls
executable file
·50 lines (46 loc) · 1.42 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
const { spawn } = require('child_process')
const path = require('path')
var test
async function runTest (p, expectfail = false, skipnode = false) {
return new Promise(resolve => {
var options = {
env: {},
detached: true
}
Object.assign(options.env, process.env)
options.env.SKIPNODE = skipnode
// Spawn the iso-test process
try {
test = spawn('node', [path.join(process.cwd(), 'server.node.js'), p], options)
} catch (e) {
console.error(e)
process.exit(1)
}
test.stdout.on('data', (data) => {
process.stdout.write(data.toString('utf8'))
})
test.stderr.on('data', (data) => {
process.stderr.write(data.toString('utf8'))
})
test.on('exit', function (code) {
if (code !== 0 && !expectfail) process.exit(code)
else if (code === 0 && expectfail) {
console.error(`fail\t${p} did not fail as expected`)
process.exit(1)
} else if (code !== 0 && expectfail) {
resolve()
} else resolve()
})
})
}
async function runAll () {
await runTest(path.join(process.cwd(), 'pass.js'))
await runTest(path.join(process.cwd(), 'fail.js'), true)
await runTest(path.join(process.cwd(), 'error.js'), true)
await runTest(path.join(process.cwd(), 'fail.js'), true, true)
await runTest(path.join(process.cwd(), 'error.js'), true, true)
console.log('All tests passed!')
}
runAll().catch(e => {
process.exit(1)
})