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

Commit 14c4703

Browse files
committed
add to circleci
1 parent a08dd3e commit 14c4703

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

circle.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ workflows:
4747
command: npm test
4848
store_artifacts: true
4949

50+
- cypress/run:
51+
name: Example Webpack options
52+
requires:
53+
- Install
54+
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
55+
install-command: npm install
56+
verify-command: echo 'Already verified'
57+
no-workspace: true
58+
working_directory: examples/webpack-options
59+
command: npm test
60+
store_artifacts: true
61+
5062
- cypress/run:
5163
name: Test
5264
parallelism: 4
@@ -78,6 +90,7 @@ workflows:
7890
- Test
7991
- Example React Scripts
8092
- Example Component Folder
93+
- Example Webpack options
8194
install-command: echo 'Already installed'
8295
verify-command: echo 'Already verified'
8396
no-workspace: true

examples/webpack-options/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# example: webpack-options
2+
3+
The Webpack preprocessor in [cypress/plugins/index.js](cypress/plugins/index.js) adds the Babel React preset to the list of default Webpack plugins. This allows Cypress to transpile JSX code in [cypress/component/Test.cy-spec.js](cypress/component/Test.cy-spec.js) file.
4+
5+
```js
6+
import React from 'react'
7+
import { mount } from 'cypress-react-unit-test'
8+
describe('components', () => {
9+
it('works', () => {
10+
mount(<div>Text</div>)
11+
cy.contains('Text')
12+
})
13+
})
14+
```
15+
16+
![Test screenshot](images/test.png)
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// @ts-check
22
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
3+
4+
// Cypress Webpack preprocessor includes Babel env preset,
5+
// but to transpile JSX code we need to add Babel React preset
36
module.exports = (on, config) => {
4-
on(
5-
'file:preprocessor',
6-
// @ts-ignore
7-
webpackPreprocessor(webpackPreprocessor.defaultOptions),
7+
// @ts-ignore
8+
const opts = webpackPreprocessor.defaultOptions
9+
// add React preset to be able to transpile JSX
10+
opts.webpackOptions.module.rules[0].use[0].options.presets.push(
11+
require.resolve('@babel/preset-react'),
812
)
13+
on('file:preprocessor', webpackPreprocessor(opts))
914
}
58.7 KB
Loading

0 commit comments

Comments
 (0)