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

Commit 32b4416

Browse files
committed
fix: use better cloning method to preserve regexes
1 parent a9973f1 commit 32b4416

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const cloneDeep = require('lodash.clonedeep')
12
const path = require('path')
23
const webpack = require('webpack')
34
const log = require('debug')('cypress:webpack')
@@ -167,6 +168,6 @@ const preprocessor = (options = {}) => {
167168
}
168169

169170
// provide a clone of the default options
170-
preprocessor.defaultOptions = JSON.parse(JSON.stringify(defaultOptions))
171+
preprocessor.defaultOptions = cloneDeep(defaultOptions)
171172

172173
module.exports = preprocessor

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"babel-preset-react": "6.24.1",
6565
"bluebird": "3.5.0",
6666
"debug": "3.1.0",
67+
"lodash.clonedeep": "4.5.0",
6768
"webpack": "3.6.0"
6869
},
6970
"release": {

test/index_spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ describe('webpack preprocessor', function () {
6464
expect(preprocessor.defaultOptions).to.be.an('object')
6565
expect(preprocessor.defaultOptions.webpackOptions.module.rules).to.be.an('array')
6666
})
67+
68+
it('defaultOptions are deeply cloned, preserving regexes', () => {
69+
expect(preprocessor.defaultOptions.webpackOptions.module.rules[0].test).to.be.an.instanceOf(RegExp)
70+
})
6771
})
6872

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

0 commit comments

Comments
 (0)