-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
run_spec.js
189 lines (157 loc) · 5.45 KB
/
run_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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
require('../../spec_helper')
const os = require('os')
const snapshot = require('../../support/snapshot')
const util = require(`${lib}/util`)
const run = require(`${lib}/exec/run`)
const spawn = require(`${lib}/exec/spawn`)
const verify = require(`${lib}/tasks/verify`)
describe('exec run', function () {
beforeEach(function () {
sinon.stub(util, 'isInstalledGlobally').returns(true)
sinon.stub(process, 'exit')
})
context('.processRunOptions', function () {
it('allows string --project option', () => {
const args = run.processRunOptions({
project: '/path/to/project',
})
expect(args).to.deep.equal(['--run-project', '/path/to/project'])
})
it('throws an error for empty string --project', () => {
expect(() => run.processRunOptions({ project: '' })).to.throw()
})
it('throws an error for boolean --project', () => {
expect(() => run.processRunOptions({ project: false })).to.throw()
expect(() => run.processRunOptions({ project: true })).to.throw()
})
it('throws an error for --project "false" or "true"', () => {
expect(() => run.processRunOptions({ project: 'false' })).to.throw()
expect(() => run.processRunOptions({ project: 'true' })).to.throw()
})
it('passes --browser option', () => {
const args = run.processRunOptions({
browser: 'test browser',
})
snapshot(args)
})
it('passes --record option', () => {
const args = run.processRunOptions({
record: 'my record id',
})
snapshot(args)
})
it('passes --config-file false option', () => {
const args = run.processRunOptions({
configFile: false,
})
snapshot(args)
})
it('does not allow setting paradoxical --headed and --headless flags', () => {
os.platform.returns('linux')
process.exit.returns()
expect(() => run.processRunOptions({ headed: true, headless: true })).to.throw()
})
it('passes --headed according to --headless', () => {
expect(run.processRunOptions({ headless: true })).to.deep.eq([
'--run-project', undefined, '--headed', false,
])
})
it('does not remove --record option when using --browser', () => {
const args = run.processRunOptions({
record: 'foo',
browser: 'test browser',
})
snapshot(args)
})
})
context('.start', function () {
beforeEach(function () {
sinon.stub(spawn, 'start').resolves()
sinon.stub(verify, 'start').resolves()
})
it('verifies cypress', function () {
return run.start()
.then(() => {
expect(verify.start).to.be.calledOnce
})
})
it('spawns with --key and xvfb', function () {
return run.start({ port: '1234' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--port', '1234'])
})
})
it('spawns with --env', function () {
return run.start({ env: 'host=http://localhost:1337,name=brian' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--env', 'host=http://localhost:1337,name=brian'])
})
})
it('spawns with --config', function () {
return run.start({ config: 'watchForFileChanges=false,baseUrl=localhost' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--config', 'watchForFileChanges=false,baseUrl=localhost'])
})
})
it('spawns with --config-file false', function () {
return run.start({ configFile: false })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--run-project', process.cwd(), '--config-file', false],
)
})
})
it('spawns with --config-file set', function () {
return run.start({ configFile: 'special-cypress.json' })
.then(() => {
expect(spawn.start).to.be.calledWith(
['--run-project', process.cwd(), '--config-file', 'special-cypress.json'],
)
})
})
it('spawns with --record false', function () {
return run.start({ record: false })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--record', false])
})
})
it('spawns with --headed true', function () {
return run.start({ headed: true })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--headed', true,
])
})
})
it('spawns with --no-exit', function () {
return run.start({ exit: false })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--no-exit',
])
})
})
it('spawns with --output-path', function () {
return run.start({ outputPath: '/path/to/output' })
.then(() => {
expect(spawn.start).to.be.calledWith(['--run-project', process.cwd(), '--output-path', '/path/to/output'])
})
})
it('spawns with --tag value', function () {
return run.start({ tag: 'nightly' })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--tag', 'nightly',
])
})
})
it('spawns with several --tag words unchanged', function () {
return run.start({ tag: 'nightly, sanity' })
.then(() => {
expect(spawn.start).to.be.calledWith([
'--run-project', process.cwd(), '--tag', 'nightly, sanity',
])
})
})
})
})