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

Commit a8fa4ff

Browse files
committed
expose default options
1 parent df443e0 commit a8fa4ff

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const createDeferred = require('./deferred')
77
const bundles = {}
88

99
// by default, we transform JavaScript (up to anything at stage-4) and JSX
10-
const defaults = {
10+
const defaultOptions = {
1111
webpackOptions: {
1212
module: {
1313
rules: [
@@ -35,7 +35,7 @@ const defaults = {
3535
//
3636
// register('on:spec:file:preprocessor', webpack(config, userOptions))
3737
//
38-
module.exports = (config, userOptions = {}) => {
38+
const preprocessor = (config, userOptions = {}) => {
3939
if (!config || typeof config.isTextTerminal !== 'boolean') {
4040
throw new Error(`Cypress Webpack Preprocessor must be called with the Cypress config as its first argument. You passed: ${JSON.stringify(config, null, 2)}`)
4141
}
@@ -74,8 +74,8 @@ module.exports = (config, userOptions = {}) => {
7474
const outputPath = util.getOutputPath(filePath)
7575

7676
// user can override the default options
77-
let webpackOptions = Object.assign({}, defaults.webpackOptions, userOptions.webpackOptions)
78-
let watchOptions = Object.assign({}, defaults.watchOptions, userOptions.watchOptions)
77+
let webpackOptions = Object.assign({}, defaultOptions.webpackOptions, userOptions.webpackOptions)
78+
let watchOptions = Object.assign({}, defaultOptions.watchOptions, userOptions.watchOptions)
7979

8080
// we need to set entry and output
8181
webpackOptions = Object.assign(webpackOptions, {
@@ -167,3 +167,8 @@ module.exports = (config, userOptions = {}) => {
167167
return bundles[filePath]
168168
}
169169
}
170+
171+
// provide a clone of the default options
172+
preprocessor.defaultOptions = JSON.parse(JSON.stringify(defaultOptions))
173+
174+
module.exports = preprocessor

test/index_spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ describe('webpack preprocessor', function () {
6060
it('throws error if config is not the first argument', function () {
6161
expect(preprocessor).to.throw('must be called with the Cypress config')
6262
})
63+
64+
it('has defaultOptions attached to it', function () {
65+
expect(preprocessor.defaultOptions).to.be.an('object')
66+
expect(preprocessor.defaultOptions.webpackOptions.module.rules).to.be.an('array')
67+
})
6368
})
6469

6570
describe('preprocessor function', function () {

0 commit comments

Comments
 (0)