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

Commit 7ebe714

Browse files
New rollup example and template (#444)
Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
1 parent 5733f5d commit 7ebe714

File tree

18 files changed

+1046
-466
lines changed

18 files changed

+1046
-466
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ Folder Name | Description
221221
[visual-testing-with-happo](examples/visual-testing-with-happo) | [Visual testing](#visual-testing) for components using 3rd party service [Happo](https://happo.io/)
222222
[visual-testing-with-applitools](examples/visual-testing-with-applitools) | [Visual testing](#visual-testing) for components using 3rd party service [Applitools.com](https://applitools.com/)
223223
[using-babel](examples/using-babel) | Bundling specs and loaded source files using project's existing `.babelrc` file
224+
[webpack-file](examples/rollup) | Bundle component and specs using [rollup](http://rollupjs.org/guide/en/).
224225
[webpack-file](examples/webpack-file) | Load existing `webpack.config.js` file
225226
[webpack-options](examples/webpack-options) | Using the default Webpack options from `@cypress/webpack-preprocessor` to transpile JSX specs
226227
<!-- prettier-ignore-end -->

circle.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ workflows:
172172
npm run only-covered
173173
working_directory: examples/webpack-file
174174

175+
- cypress/run:
176+
name: Example Rollup
177+
requires:
178+
- Install
179+
# each example installs "cypress-react-unit-test" as a local dependency (symlink)
180+
executor: cypress/base-12
181+
install-command: npm install --no-bin-links
182+
verify-command: echo 'Already verified'
183+
no-workspace: true
184+
working_directory: examples/rollup
185+
command: npm test
186+
store_artifacts: true
187+
175188
- cypress/run:
176189
name: Example Webpack options
177190
requires:
@@ -338,6 +351,7 @@ workflows:
338351
- Example Tailwind
339352
- Example Webpack file
340353
- Example Webpack options
354+
- Example Rollup
341355
- Visual Sudoku
342356
- Visual with Percy
343357
- Visual with Happo

examples/rollup/.npmrc

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

examples/rollup/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# example: rollup
2+
3+
> Compiling component tests using Rollup bundler
4+
5+
## Usage
6+
7+
1. Make sure the root project has been built .
8+
9+
```bash
10+
# in the root of the project
11+
npm install
12+
npm run build
13+
```
14+
15+
2. Run `npm install` in this folder to symlink the `cypress-react-unit-test` dependency.
16+
17+
```bash
18+
# in this folder
19+
npm install
20+
npm run build
21+
```
22+
23+
3. Start Cypress
24+
25+
```bash
26+
npm run cy:open
27+
# or just run headless tests
28+
npm test
29+
```

examples/rollup/babel.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
presets: [
3+
'@babel/preset-env',
4+
'@babel/preset-typescript',
5+
'@babel/preset-react',
6+
],
7+
plugins: ['@babel/plugin-proposal-class-properties'],
8+
}

examples/rollup/cypress.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"testFiles": "**/*spec.{ts,tsx}",
3+
"experimentalComponentTesting": true,
4+
"experimentalFetchPolyfill": true,
5+
"componentFolder": "src",
6+
"fixturesFolder": false
7+
}
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const rollupPreprocessor = require('@bahmutov/cy-rollup')
2+
3+
module.exports = (on, config) => {
4+
on(
5+
'file:preprocessor',
6+
rollupPreprocessor({
7+
configFile: 'rollup.config.js',
8+
}),
9+
)
10+
11+
require('@cypress/code-coverage/task')(on, config)
12+
// IMPORTANT to return the config object
13+
// with the any changed environment variables
14+
return config
15+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import 'cypress-react-unit-test/support'
2+
import '@cypress/code-coverage/support'

examples/rollup/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "example-rollup",
3+
"description": "Component testing using Rollup bundler",
4+
"private": true,
5+
"scripts": {
6+
"build": "../../node_modules/.bin/rollup -c",
7+
"test": "../../node_modules/.bin/cypress-expect run --passing 1",
8+
"cy:open": "../../node_modules/.bin/cypress open"
9+
},
10+
"devDependencies": {
11+
"cypress-react-unit-test": "file:../.."
12+
}
13+
}

0 commit comments

Comments
 (0)