This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathcli.js
83 lines (71 loc) · 2.07 KB
/
cli.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { join } from "path"
import { exec } from "child_process"
const target = join(__dirname, "..", "test-phenomic-theme-base")
const execOpts = { cwd: target }
const phenomic = "node ./node_modules/.bin/phenomic"
const timing = process.env.CI ? 10000 : 5000
describe("Integration: CLI", () => {
it("should throw if a CLI flag is NOT recognized", () => {
return new Promise((resolve, reject) => {
const child = exec(
`${ phenomic } start --open=false --lol`, execOpts,
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
expect(err.message.indexOf("Unknown argument") > -1).toBeTruthy()
resolve()
}
}
)
const timeout = setTimeout(() => {
child.kill()
reject("Test didn't finish before timeout")
}, timing)
})
})
it("should NOT throw if a CLI flag is recognized", () => {
return new Promise((resolve, reject) => {
const child = exec(
`${ phenomic } start --open=false --devPort=4000`, execOpts,
// should die quickly...
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
reject(err)
}
}
)
// ...or be ok quickly
// we assume it's ok and kill the process
// we don't need the actual build
const timeout = setTimeout(() => {
child.kill()
resolve()
}, timing)
})
})
fit("should NOT throw if port is used", () => {
return new Promise((resolve, reject) => {
const app = require("express")()
const server = app.listen(8081, (err) => {
if (err) {
reject(err)
}
const child = exec(
`${ phenomic } start --open=false --devPort=8081`, execOpts,
(err) => {
if (err && !err.killed) {
clearTimeout(timeout)
reject(err)
}
}
)
const timeout = setTimeout(() => {
child.kill()
server.close()
resolve()
}, timing * 2)
})
})
})
})