Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 991f87a

Browse files
committed
rename config to file
1 parent 18bd227 commit 991f87a

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const preprocessor = (options = {}) => {
7575
// when running in the GUI, it will likely get called multiple times
7676
// with the same filePath, as the user could re-run the tests, causing
7777
// the supported file and spec file to be requested again
78-
return (config) => {
79-
const filePath = config.filePath
78+
return (file) => {
79+
const filePath = file.filePath
8080
log('get', filePath)
8181

8282
// since this function can get called multiple times with the same
@@ -90,7 +90,7 @@ const preprocessor = (options = {}) => {
9090
// we're provided a default output path that lives alongside Cypress's
9191
// app data files so we don't have to worry about where to put the bundled
9292
// file on disk
93-
const outputPath = config.outputPath
93+
const outputPath = file.outputPath
9494

9595
log(`input: ${filePath}`)
9696
log(`output: ${outputPath}`)
@@ -103,7 +103,7 @@ const preprocessor = (options = {}) => {
103103
log('browserifyOptions:', browserifyOptions)
104104
const bundler = browserify(browserifyOptions)
105105

106-
if (config.shouldWatch) {
106+
if (file.shouldWatch) {
107107
log('watching')
108108
bundler.plugin(watchify, watchifyOptions)
109109
}
@@ -155,7 +155,7 @@ const preprocessor = (options = {}) => {
155155
const bundlePromise = bundles[filePath] = bundle()
156156
.finally(() => {
157157
log(`- update finished for ${filePath}`)
158-
config.emit('rerun')
158+
file.emit('rerun')
159159
})
160160
// we suppress unhandled rejections so they don't bubble up to the
161161
// unhandledRejection handler and crash the app. Cypress will eventually
@@ -171,10 +171,10 @@ const preprocessor = (options = {}) => {
171171

172172
// when the spec or project is closed, we need to clean up the cached
173173
// bundle promise and stop the watcher via `bundler.close()`
174-
config.on('close', () => {
174+
file.on('close', () => {
175175
log(`close ${filePath}`)
176176
delete bundles[filePath]
177-
if (config.shouldWatch) {
177+
if (file.shouldWatch) {
178178
bundler.close()
179179
}
180180
})

test/index_spec.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('browserify preprocessor', function () {
4646
sandbox.stub(fs, 'ensureDirAsync').resolves()
4747

4848
this.options = {}
49-
this.config = {
49+
this.file = {
5050
filePath: 'path/to/file.js',
5151
outputPath: 'output/output.js',
5252
shouldWatch: false,
@@ -55,7 +55,7 @@ describe('browserify preprocessor', function () {
5555
}
5656

5757
this.run = () => {
58-
return preprocessor(this.options)(this.config)
58+
return preprocessor(this.options)(this.file)
5959
}
6060
})
6161

@@ -72,7 +72,7 @@ describe('browserify preprocessor', function () {
7272

7373
describe('preprocessor function', function () {
7474
afterEach(function () {
75-
this.config.on.withArgs('close').yield() // resets the cached bundles
75+
this.file.on.withArgs('close').yield() // resets the cached bundles
7676
})
7777

7878
describe('when it finishes cleanly', function () {
@@ -91,9 +91,9 @@ describe('browserify preprocessor', function () {
9191
browserify.returns(this.bundlerApi)
9292

9393
const run = preprocessor(this.options)
94-
return run(this.config)
94+
return run(this.file)
9595
.then(() => {
96-
return run(this.config)
96+
return run(this.file)
9797
})
9898
.then(() => {
9999
expect(browserify).to.be.calledOnce
@@ -102,7 +102,7 @@ describe('browserify preprocessor', function () {
102102

103103
it('specifies the entry file', function () {
104104
return this.run().then(() => {
105-
expect(browserify.lastCall.args[0].entries[0]).to.equal(this.config.filePath)
105+
expect(browserify.lastCall.args[0].entries[0]).to.equal(this.file.filePath)
106106
})
107107
})
108108

@@ -120,14 +120,14 @@ describe('browserify preprocessor', function () {
120120
})
121121

122122
it('watches when shouldWatch is true', function () {
123-
this.config.shouldWatch = true
123+
this.file.shouldWatch = true
124124
return this.run().then(() => {
125125
expect(this.bundlerApi.plugin).to.be.calledWith(watchify)
126126
})
127127
})
128128

129129
it('use default watchifyOptions if not provided', function () {
130-
this.config.shouldWatch = true
130+
this.file.shouldWatch = true
131131
return this.run().then(() => {
132132
expect(this.bundlerApi.plugin).to.be.calledWith(watchify, {
133133
ignoreWatch: [
@@ -143,7 +143,7 @@ describe('browserify preprocessor', function () {
143143
})
144144

145145
it('includes watchifyOptions if provided', function () {
146-
this.config.shouldWatch = true
146+
this.file.shouldWatch = true
147147
this.options.watchifyOptions = { ignoreWatch: ['node_modules'] }
148148
return this.run().then(() => {
149149
expect(this.bundlerApi.plugin).to.be.calledWith(watchify, {
@@ -181,7 +181,7 @@ describe('browserify preprocessor', function () {
181181

182182
it('creates write stream to output path', function () {
183183
return this.run().then(() => {
184-
expect(fs.createWriteStream).to.be.calledWith(this.config.outputPath)
184+
expect(fs.createWriteStream).to.be.calledWith(this.file.outputPath)
185185
})
186186
})
187187

@@ -193,7 +193,7 @@ describe('browserify preprocessor', function () {
193193

194194
it('resolves with the output path', function () {
195195
return this.run().then((outputPath) => {
196-
expect(outputPath).to.equal(this.config.outputPath)
196+
expect(outputPath).to.equal(this.file.outputPath)
197197
})
198198
})
199199

@@ -207,21 +207,21 @@ describe('browserify preprocessor', function () {
207207
it('emits `rerun` when there is an update', function () {
208208
this.bundlerApi.on.withArgs('update').yields()
209209
return this.run().then(() => {
210-
expect(this.config.emit).to.be.calledWith('rerun')
210+
expect(this.file.emit).to.be.calledWith('rerun')
211211
})
212212
})
213213

214214
it('closes bundler when shouldWatch is true and `close` is emitted', function () {
215-
this.config.shouldWatch = true
215+
this.file.shouldWatch = true
216216
return this.run().then(() => {
217-
this.config.on.withArgs('close').yield()
217+
this.file.on.withArgs('close').yield()
218218
expect(this.bundlerApi.close).to.be.called
219219
})
220220
})
221221

222222
it('does not close bundler when shouldWatch is false and `close` is emitted', function () {
223223
return this.run().then(() => {
224-
this.config.on.withArgs('close').yield()
224+
this.file.on.withArgs('close').yield()
225225
expect(this.bundlerApi.close).not.to.be.called
226226
})
227227
})
@@ -260,7 +260,7 @@ describe('browserify preprocessor', function () {
260260
process.on('unhandledRejection', handler)
261261
this.createWriteStreamApi.on.withArgs('finish').onFirstCall().yields()
262262

263-
this.config.emit = () => {
263+
this.file.emit = () => {
264264
setTimeout(() => {
265265
expect(handler).not.to.be.called
266266
process.removeListener('unhandledRejection', handler)
@@ -277,11 +277,11 @@ describe('browserify preprocessor', function () {
277277
it('rejects subsequent request after and update bundle errors', function () {
278278
this.createWriteStreamApi.on.withArgs('finish').onFirstCall().yields()
279279
const run = preprocessor(this.options)
280-
return run(this.config)
280+
return run(this.file)
281281
.then(() => {
282282
streamApi.on.withArgs('error').yieldsAsync(new Error('bundle error')).returns({ pipe () {} })
283283
this.bundlerApi.on.withArgs('update').yield()
284-
return run(this.config)
284+
return run(this.file)
285285
})
286286
.then(() => {
287287
throw new Error('should not resolve')

0 commit comments

Comments
 (0)