Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit a08dd3e

Browse files
authored
fix: use default webpack options (#189)
1 parent 722950c commit a08dd3e

File tree

8 files changed

+48
-6
lines changed

8 files changed

+48
-6
lines changed

examples/webpack-options/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/webpack-options/cypress.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"fixturesFolder": false,
3+
"testFiles": "**/*cy-spec.js",
4+
"viewportWidth": 500,
5+
"viewportHeight": 500,
6+
"experimentalComponentTesting": true
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
import { mount } from 'cypress-react-unit-test'
3+
4+
describe('components', () => {
5+
it('works', () => {
6+
mount(<div>Text</div>)
7+
cy.contains('Text')
8+
})
9+
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference types="cypress" />
2+
describe('integration spec', () => {
3+
it('works', () => {
4+
expect(1).to.equal(1)
5+
})
6+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @ts-check
2+
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
3+
module.exports = (on, config) => {
4+
on(
5+
'file:preprocessor',
6+
// @ts-ignore
7+
webpackPreprocessor(webpackPreprocessor.defaultOptions),
8+
)
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('cypress-react-unit-test/dist/hooks')

examples/webpack-options/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "example-webpack-options",
3+
"description": "Using default Webpack options to transpile simple tests",
4+
"private": true,
5+
"scripts": {
6+
"test": "../../node_modules/.bin/cypress run",
7+
"cy:open": "../../node_modules/.bin/cypress open"
8+
},
9+
"devDependencies": {
10+
"cypress-react-unit-test": "file:../.."
11+
}
12+
}

plugins/cra-v3/file-preprocessor.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ const findWebpack = require('find-webpack')
44
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
55
const { addImageRedirect } = require('../utils/add-image-redirect')
66

7-
const getWebpackOptions = opts => {
7+
const getWebpackPreprocessorOptions = opts => {
88
debug('top level opts %o', opts)
99

1010
const webpackOptions = findWebpack.getWebpackOptions()
1111
if (!webpackOptions) {
1212
console.error('⚠️ Could not find Webpack options, using defaults')
13-
return {
14-
webpackOptions: webpackPreprocessor.defaultOptions,
15-
watchOptions: {},
16-
}
13+
return webpackPreprocessor.defaultOptions
1714
}
1815
debug('webpack options: %o', webpackOptions)
1916
findWebpack.cleanForCypress(opts, webpackOptions)
@@ -42,7 +39,7 @@ module.exports = config => {
4239
addFolderToTranspile: config.componentFolder,
4340
coverage: !coverageIsDisabled,
4441
}
45-
const preprocessorOptions = getWebpackOptions(opts)
42+
const preprocessorOptions = getWebpackPreprocessorOptions(opts)
4643

4744
debug('final webpack options %o', preprocessorOptions.webpackOptions)
4845

0 commit comments

Comments
 (0)