-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
cypress_spec.js
175 lines (143 loc) · 4.16 KB
/
cypress_spec.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
require('../spec_helper')
const os = require('os')
const path = require('path')
const R = require('ramda')
const snapshot = require('../support/snapshot')
const Promise = require('bluebird')
const tmp = Promise.promisifyAll(require('tmp'))
const mockfs = require('mock-fs')
const fs = require(`${lib}/fs`)
const open = require(`${lib}/exec/open`)
const run = require(`${lib}/exec/run`)
const cypress = require(`${lib}/cypress`)
describe('cypress', function () {
beforeEach(function () {
mockfs({})
})
afterEach(() => {
mockfs.restore()
})
context('.open', function () {
beforeEach(function () {
sinon.stub(open, 'start').resolves()
})
const getCallArgs = R.path(['lastCall', 'args', 0])
const getStartArgs = () => {
expect(open.start).to.be.called
return getCallArgs(open.start)
}
it('calls open#start, passing in options', function () {
return cypress.open({ foo: 'foo' })
.then(getStartArgs)
.then((args) => {
expect(args.foo).to.equal('foo')
})
})
it('normalizes config object', () => {
const config = {
pageLoadTime: 10000,
watchForFileChanges: false,
}
return cypress.open({ config })
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq({ config: JSON.stringify(config) })
})
})
it('passes configFile: false', () => {
const opts = {
configFile: false,
}
return cypress.open(opts)
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq(opts)
})
})
})
context('.run', function () {
let outputPath
beforeEach(function () {
outputPath = path.join(os.tmpdir(), 'cypress/monorepo/cypress_spec/output.json')
sinon.stub(tmp, 'fileAsync').resolves(outputPath)
sinon.stub(run, 'start').resolves()
return fs.outputJsonAsync(outputPath, {
code: 0,
failingTests: [],
})
})
const getCallArgs = R.path(['lastCall', 'args', 0])
const normalizeCallArgs = (args) => {
expect(args.outputPath).to.equal(outputPath)
delete args.outputPath
return args
}
const getStartArgs = () => {
expect(run.start).to.be.called
return normalizeCallArgs(getCallArgs(run.start))
}
it('calls run#start, passing in options', () => {
return cypress.run({ spec: 'foo' })
.then(getStartArgs)
.then((args) => {
expect(args.spec).to.equal('foo')
})
})
it('normalizes config object', () => {
const config = {
pageLoadTime: 10000,
watchForFileChanges: false,
}
return cypress.run({ config })
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq({ config: JSON.stringify(config) })
})
})
it('normalizes env option if passed an object', () => {
const env = { foo: 'bar', another: 'one' }
return cypress.run({ env })
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq({ env: JSON.stringify(env) })
})
})
it('gets random tmp file and passes it to run#start', function () {
return cypress.run().then(() => {
expect(run.start.lastCall.args[0].outputPath).to.equal(outputPath)
})
})
it('resolves with contents of tmp file', () => {
return cypress.run().then(snapshot)
})
it('passes configFile: false', () => {
const opts = {
configFile: false,
}
return cypress.run(opts)
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq(opts)
})
})
it('rejects if project is an empty string', () => {
return expect(cypress.run({ project: '' })).to.be.rejected
})
it('rejects if project is true', () => {
return expect(cypress.run({ project: true })).to.be.rejected
})
it('rejects if project is false', () => {
return expect(cypress.run({ project: false })).to.be.rejected
})
it('passes quiet: true', () => {
const opts = {
quiet: true,
}
return cypress.run(opts)
.then(getStartArgs)
.then((args) => {
expect(args).to.deep.eq(opts)
})
})
})
})