Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit 6dbd3fa

Browse files
committed
rename config to file
1 parent 59ebe72 commit 6dbd3fa

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const defaultOptions = {
3333
// export a function that returns another function, making it easy for users
3434
// to configure like so:
3535
//
36-
// on('file:preprocessor', webpack(config, options))
36+
// on('file:preprocessor', webpack(options))
3737
//
3838
const preprocessor = (options = {}) => {
3939
log('user options:', options)
@@ -49,8 +49,8 @@ const preprocessor = (options = {}) => {
4949
// when running in the GUI, it will likely get called multiple times
5050
// with the same filePath, as the user could re-run the tests, causing
5151
// the supported file and spec file to be requested again
52-
return (config) => {
53-
const filePath = config.filePath
52+
return (file) => {
53+
const filePath = file.filePath
5454
log('get', filePath)
5555

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

7373
// we need to set entry and output
7474
webpackOptions = Object.assign(webpackOptions, {
@@ -132,25 +132,25 @@ const preprocessor = (options = {}) => {
132132
log('- compile finished for', filePath)
133133
// when the bundling is finished, we call `util.fileUpdated`
134134
// to let Cypress know to re-run the spec
135-
config.emit('rerun')
135+
file.emit('rerun')
136136
})
137137
})
138138

139-
if (config.shouldWatch) {
139+
if (file.shouldWatch) {
140140
log('watching')
141141
}
142142

143-
const bundler = config.shouldWatch ?
143+
const bundler = file.shouldWatch ?
144144
compiler.watch(watchOptions, handle) :
145145
compiler.run(handle)
146146

147147
// when the spec or project is closed, we need to clean up the cached
148148
// bundle promise and stop the watcher via `bundler.close()`
149-
config.on('close', () => {
149+
file.on('close', () => {
150150
log('close', filePath)
151151
delete bundles[filePath]
152152

153-
if (config.shouldWatch) {
153+
if (file.shouldWatch) {
154154
bundler.close()
155155
}
156156
})

test/index_spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('webpack preprocessor', function () {
3535
toJson () { return { warnings: [], errors: [] } },
3636
}
3737

38-
this.config = {
38+
this.file = {
3939
filePath: 'path/to/file.js',
4040
outputPath: 'output/output.js',
4141
shouldWatch: false,
@@ -50,7 +50,7 @@ describe('webpack preprocessor', function () {
5050
}
5151

5252
this.run = () => {
53-
return preprocessor(this.options)(this.config)
53+
return preprocessor(this.options)(this.file)
5454
}
5555
})
5656

@@ -67,7 +67,7 @@ describe('webpack preprocessor', function () {
6767

6868
describe('preprocessor function', function () {
6969
afterEach(function () {
70-
this.config.on.withArgs('close').yield() // resets the cached bundles
70+
this.file.on.withArgs('close').yield() // resets the cached bundles
7171
})
7272

7373
describe('when it finishes cleanly', function () {
@@ -86,14 +86,14 @@ describe('webpack preprocessor', function () {
8686
webpack.returns(this.compilerApi)
8787

8888
const run = preprocessor(this.options)
89-
run(this.config)
90-
run(this.config)
89+
run(this.file)
90+
run(this.file)
9191
expect(webpack).to.be.calledOnce
9292
})
9393

9494
it('specifies the entry file', function () {
9595
return this.run().then(() => {
96-
expect(webpack.lastCall.args[0].entry).to.equal(this.config.filePath)
96+
expect(webpack.lastCall.args[0].entry).to.equal(this.file.filePath)
9797
})
9898
})
9999

@@ -113,15 +113,15 @@ describe('webpack preprocessor', function () {
113113
})
114114

115115
it('watches when shouldWatch is true', function () {
116-
this.config.shouldWatch = true
116+
this.file.shouldWatch = true
117117
this.compilerApi.watch.yields(null, this.statsApi)
118118
return this.run().then(() => {
119119
expect(this.compilerApi.watch).to.be.called
120120
})
121121
})
122122

123123
it('includes watchOptions if provided', function () {
124-
this.config.shouldWatch = true
124+
this.file.shouldWatch = true
125125
this.compilerApi.watch.yields(null, this.statsApi)
126126
this.options.watchOptions = { poll: true }
127127
return this.run().then(() => {
@@ -133,29 +133,29 @@ describe('webpack preprocessor', function () {
133133

134134
it('resolves with the output path', function () {
135135
return this.run().then((outputPath) => {
136-
expect(outputPath).to.be.equal(this.config.outputPath)
136+
expect(outputPath).to.be.equal(this.file.outputPath)
137137
})
138138
})
139139

140140
it('emits `rerun` when there is an update', function () {
141141
this.compilerApi.plugin.withArgs('compile').yields()
142142
return this.run().then(() => {
143-
expect(this.config.emit).to.be.calledWith('rerun')
143+
expect(this.file.emit).to.be.calledWith('rerun')
144144
})
145145
})
146146

147147
it('closes bundler when shouldWatch is true and `close` is emitted', function () {
148-
this.config.shouldWatch = true
148+
this.file.shouldWatch = true
149149
this.compilerApi.watch.yields(null, this.statsApi)
150150
return this.run().then(() => {
151-
this.config.on.withArgs('close').yield()
151+
this.file.on.withArgs('close').yield()
152152
expect(this.watchApi.close).to.be.called
153153
})
154154
})
155155

156156
it('does not close bundler when shouldWatch is false and `close` is emitted', function () {
157157
return this.run().then(() => {
158-
this.config.on.withArgs('close').yield()
158+
this.file.on.withArgs('close').yield()
159159
expect(this.watchApi.close).not.to.be.called
160160
})
161161
})

0 commit comments

Comments
 (0)