forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_spec.coffee
More file actions
181 lines (149 loc) · 5.57 KB
/
Copy pathsettings_spec.coffee
File metadata and controls
181 lines (149 loc) · 5.57 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
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
require("../spec_helper")
path = require("path")
R = require("ramda")
fs = require("#{root}lib/util/fs")
settings = require("#{root}lib/util/settings")
projectRoot = process.cwd()
describe "lib/settings", ->
context "with no configFile option", ->
beforeEach ->
@setup = (obj = {}) ->
fs.writeJsonAsync("cypress.json", obj)
afterEach ->
fs.removeAsync("cypress.json")
context "nested cypress object", ->
it "flattens object on read", ->
@setup({cypress: {foo: "bar"}})
.then ->
settings.read(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq {foo: "bar"}
fs.readJsonAsync("cypress.json")
.then (obj) ->
expect(obj).to.deep.eq({foo: "bar"})
context ".readEnv", ->
afterEach ->
fs.removeAsync("cypress.env.json")
it "parses json", ->
json = {foo: "bar", baz: "quux"}
fs.writeJsonSync("cypress.env.json", json)
settings.readEnv(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq(json)
it "throws when invalid json", ->
fs.writeFileSync("cypress.env.json", "{'foo;: 'bar}")
settings.readEnv(projectRoot)
.catch (err) ->
expect(err.type).to.eq("ERROR_READING_FILE")
expect(err.message).to.include("SyntaxError")
expect(err.message).to.include(projectRoot)
noArguments = R.nAry(0)
it "does not write initial file", ->
settings.readEnv(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq({})
.then () ->
fs.pathExists("cypress.env.json")
.then (found) ->
expect(found).to.be.false
context ".id", ->
beforeEach ->
@projectRoot = path.join(projectRoot, "_test-output/path/to/project/")
fs.ensureDirAsync(@projectRoot)
afterEach ->
fs.removeAsync("#{@projectRoot}cypress.json")
it "returns project id for project", ->
fs.writeJsonAsync("#{@projectRoot}cypress.json", {
projectId: "id-123"
})
.then =>
settings.id(@projectRoot)
.then (id) ->
expect(id).to.equal("id-123")
context ".read", ->
it "promises cypress.json", ->
@setup({foo: "bar"})
.then ->
settings.read(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq {foo: "bar"}
it "renames commandTimeout -> defaultCommandTimeout", ->
@setup({commandTimeout: 30000, foo: "bar"})
.then ->
settings.read(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq {defaultCommandTimeout: 30000, foo: "bar"}
it "renames supportFolder -> supportFile", ->
@setup({supportFolder: "foo", foo: "bar"})
.then ->
settings.read(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq {supportFile: "foo", foo: "bar"}
it "renames visitTimeout -> pageLoadTimeout", ->
@setup({visitTimeout: 30000, foo: "bar"})
.then ->
settings.read(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq {pageLoadTimeout: 30000, foo: "bar"}
it "renames visitTimeout -> pageLoadTimeout on nested cypress obj", ->
@setup({cypress: {visitTimeout: 30000, foo: "bar"}})
.then ->
settings.read(projectRoot)
.then (obj) ->
expect(obj).to.deep.eq {pageLoadTimeout: 30000, foo: "bar"}
context ".write", ->
it "promises cypress.json updates", ->
@setup().then ->
settings.write(projectRoot, {foo: "bar"})
.then (obj) ->
expect(obj).to.deep.eq {foo: "bar"}
it "only writes over conflicting keys", ->
@setup({projectId: "12345", autoOpen: true})
.then ->
settings.write(projectRoot, {projectId: "abc123"})
.then (obj) ->
expect(obj).to.deep.eq {projectId: "abc123", autoOpen: true}
context "with configFile: false", ->
beforeEach ->
@projectRoot = path.join(projectRoot, "_test-output/path/to/project/")
@options = {
configFile: false
}
it ".exists passes", ->
settings.exists(@projectRoot, @options)
.then (exists) ->
expect(exists).to.equal(undefined)
it ".write does not create a file", ->
settings.write(@projectRoot, {}, @options)
.then () =>
fs.exists(path.join(@projectRoot, "cypress.json"))
.then (exists) ->
expect(exists).to.equal(false)
it ".read returns empty object", ->
settings.read(@projectRoot, @options)
.then (settings) ->
expect(settings).to.deep.equal({})
context "with a configFile set", ->
beforeEach ->
@projectRoot = path.join(projectRoot, "_test-output/path/to/project/")
@options = {
configFile: "my-test-config-file.json"
}
afterEach ->
fs.removeAsync("#{@projectRoot}#{@options.configFile}")
it ".exists fails when configFile doesn't exist", ->
settings.exists(@projectRoot, @options)
.catch (error) ->
expect(error.type).to.equal('CONFIG_FILE_NOT_FOUND')
it ".write creates configFile" , ->
settings.write(@projectRoot, { foo: "bar" }, @options)
.then () =>
fs.readJsonAsync(path.join(@projectRoot, @options.configFile))
.then (json) ->
expect(json).to.deep.equal({ foo: "bar" })
it ".read returns from configFile", ->
fs.writeJsonAsync(path.join(@projectRoot, @options.configFile), { foo: "bar" })
.then () =>
settings.read(@projectRoot, @options)
.then (settings) ->
expect(settings).to.deep.equal({ foo: "bar" })