forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_spec.coffee
More file actions
99 lines (82 loc) · 2.84 KB
/
Copy pathcli_spec.coffee
File metadata and controls
99 lines (82 loc) · 2.84 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
require("../spec_helper")
_ = require("lodash")
R = require("ramda")
cp = require("child_process")
pr = require("../support/helpers/process")
pkg = require("../../package.json")
execa = require("execa")
semver = require("semver")
anyLineWithCaret = (str) ->
str[0] is ">"
clean = (str) ->
## remove blank lines and slice off any line
## starting with a caret because thats junk
## from npm logs
_
.chain(str)
.split("\n")
.compact()
.reject(anyLineWithCaret)
.join("\n")
.value()
env = _.omit(process.env, "CYPRESS_DEBUG")
describe "CLI Interface", ->
beforeEach ->
## set the timeout high due to
## spawning child processes
@currentTest.timeout(20000)
it "writes out ping value and exits", (done) ->
cp.exec "npm run dev -- --cwd=/foo/bar --smoke-test --ping=12345", {env: env}, (err, stdout, stderr) ->
done(err) if err
expect(clean(stdout)).to.eq("12345")
done()
it "writes out package.json and exits", (done) ->
cp.exec "npm run dev -- --return-pkg", {env: env}, (err, stdout, stderr) ->
done(err) if err
json = JSON.parse(clean(stdout))
expect(json.name).to.eq("cypress")
expect(json.productName).to.eq("Cypress", stdout)
done()
## this tests that our exit codes are correct.
## there was a bug at one point where we incorrectly
## spawned child electron processes and did not bubble
## up their exit codes to the calling process. this
## caused false-positives in CI because tests were failing
## but the exit code was always zero
context "exit codes", ->
describe "from start script command", ->
beforeEach ->
## run the start script directly
## instead of going through npm wrapper
@dev = pkg.scripts.dev
it "exits with code 22", (done) ->
s = cp.exec("#{@dev} --exit-with-code=22")
s.on "close", (code) ->
expect(code).to.eq(22)
done()
it "exits with code 0", (done) ->
s = cp.exec("#{@dev} --exit-with-code=0")
s.on "close", (code) ->
expect(code).to.eq(0)
done()
describe "through NPM script", ->
npmVersion = null
isNpmSlurpingCode = () ->
semver.lt(npmVersion, '4.0.0')
beforeEach ->
execa("npm", ["-version"])
.then R.prop("stdout")
.then (version) ->
npmVersion = version
expect(npmVersion).to.be.a.string
it "npm slurps up or not exit value on failure", (done) ->
expectedCode = if isNpmSlurpingCode() then 1 else 10
s = cp.exec("npm run dev -- --exit-with-code=10")
s.on "close", (code) ->
expect(code).to.eq(expectedCode)
done()
it "npm passes on 0 exit code", (done) ->
s = cp.exec("npm run dev -- --exit-with-code=0")
s.on "close", (code) ->
expect(code).to.eq(0)
done()