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

Commit 0d7a99b

Browse files
committed
attach default options to exported function
1 parent 01cfcdb commit 0d7a99b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const bundles = {}
1313

1414
// by default, we transform JavaScript (up to anything at stage-4), JSX,
1515
// CoffeeScript, and CJSX (CoffeeScript + JSX)
16-
const defaults = {
16+
const defaultOptions = {
1717
extensions: ['.js', '.jsx', '.coffee', '.cjsx'],
1818
watchOptions: {
1919
// ignore watching the following or the user's system can get bogged down
@@ -52,15 +52,15 @@ const defaults = {
5252
//
5353
// register('on:spec:file:preprocessor', browserify(config, userOptions))
5454
//
55-
module.exports = (config, userOptions = {}) => {
55+
const preprocessor = (config, userOptions = {}) => {
5656
log('received user options', userOptions)
5757

5858
if (!config || typeof config.isTextTerminal !== 'boolean') {
5959
throw new Error(`Cypress Browserify Preprocessor must be called with the Cypress config as its first argument. You passed: ${JSON.stringify(config, null, 2)}`)
6060
}
6161

6262
// allow user to override default options
63-
const options = Object.assign({}, defaults, userOptions)
63+
const options = Object.assign({}, defaultOptions, userOptions)
6464

6565
// we return function that accepts the arguments provided by
6666
// the event 'on:spec:file:preprocessor'
@@ -187,3 +187,8 @@ module.exports = (config, userOptions = {}) => {
187187
return bundlePromise
188188
}
189189
}
190+
191+
// provide a clone of the default options
192+
preprocessor.defaultOptions = JSON.parse(JSON.stringify(defaultOptions))
193+
194+
module.exports = preprocessor

test/index_spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ describe('browserify preprocessor', function () {
7070
it('throws error if config is not the first argument', function () {
7171
expect(preprocessor).to.throw('must be called with the Cypress config')
7272
})
73+
74+
it('has defaultOptions attached to it', function () {
75+
expect(preprocessor.defaultOptions).to.be.an('object')
76+
expect(preprocessor.defaultOptions.extensions).to.be.an('array')
77+
})
7378
})
7479

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

0 commit comments

Comments
 (0)