Skip to content

Commit 21ee591

Browse files
feat: create-cypress-tests wizard (#8857)
Co-authored-by: Jessica Sachs <jess@jessicasachs.io>
1 parent 2ceda49 commit 21ee591

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3139
-443
lines changed

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ npm/webpack-preprocessor/examples/use-babelrc/cypress/integration/spec.js
4242
**/.git
4343

4444
/npm/react/bin/*
45+
/npm/react/**/coverage
46+
**/.next/**
47+
/npm/create-cypress-tests/initial-template
48+
/npm/create-cypress-tests/**/*.template.*

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ npm/**/cypress/screenshots
2626
# from example
2727
packages/example/app
2828
packages/example/build
29-
packages/example/cypress
29+
packages/example/cypress/integration
3030

3131
# from server
3232
packages/server/.cy
@@ -39,6 +39,10 @@ packages/server/test/support/fixtures/server/libs
3939
/npm/react/bin/*
4040
/npm/react/cypress/videos
4141

42+
# from npm/create-cypress-tests
43+
/npm/create-cypress-tests/initial-template
44+
/npm/create-cypress-tests/src/test-output
45+
4246
# Building app binary
4347
scripts/support
4448
package-lock.json

circle.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,18 @@ jobs:
992992
name: Run e2e example tests
993993
command: yarn test
994994
working_directory: npm/react/<<parameters.path>>
995-
995+
996+
997+
npm-create-cypress-tests:
998+
<<: *defaults
999+
steps:
1000+
- attach_workspace:
1001+
at: ~/
1002+
- run: yarn workspace create-cypress-tests build
1003+
- run:
1004+
name: Run unit test
1005+
command: yarn workspace create-cypress-tests test
1006+
9961007
npm-eslint-plugin-dev:
9971008
<<: *defaults
9981009
steps:
@@ -1822,6 +1833,10 @@ linux-workflow: &linux-workflow
18221833
path: examples/webpack-options
18231834
requires:
18241835
- npm-react
1836+
1837+
- npm-create-cypress-tests:
1838+
requires:
1839+
- build
18251840

18261841
- npm-eslint-plugin-dev:
18271842
requires:

npm/create-cypress-tests/.eslintrc

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"plugins": [
3+
"cypress",
4+
"@cypress/dev"
5+
],
6+
"extends": [
7+
"plugin:@cypress/dev/general",
8+
"plugin:@cypress/dev/tests"
9+
],
10+
"parser": "@typescript-eslint/parser",
11+
"env": {
12+
"cypress/globals": true
13+
},
14+
"rules": {
15+
"no-console": "off",
16+
"mocha/no-global-tests": "off",
17+
"@typescript-eslint/no-unused-vars": "off"
18+
},
19+
"overrides": [
20+
{
21+
"files": [
22+
"lib/*"
23+
],
24+
"rules": {
25+
"no-console": 1
26+
}
27+
},
28+
{
29+
"files": [
30+
"**/*.json"
31+
],
32+
"rules": {
33+
"quotes": "off",
34+
"comma-dangle": "off"
35+
}
36+
}
37+
]
38+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"watch-ignore": [
3+
"node_modules"
4+
],
5+
"require": "ts-node/register",
6+
"exit": true
7+
}

npm/create-cypress-tests/.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
./src/
2+
./initial-template/
3+
scripts/
4+
__snapshots__/

npm/create-cypress-tests/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Create Cypress Tests
2+
3+
Installs and injects all the required configuration to run cypress tests.
4+
5+
## Quick overview
6+
7+
```
8+
cd my-app
9+
npx create-cypress-test
10+
npx cypress open
11+
```
12+
13+
![demo](./demo.gif)
14+
15+
## Package manager
16+
17+
This wizard will automatically determine which package do you use. If `yarn` available as global dependency it will use yarn to install dependencies and create lock file.
18+
19+
If you need to use `npm` over `yarn` you can do the following
20+
21+
```
22+
npx create-cypress-tests --use-npm
23+
```
24+
25+
By the way you can use yarn to run the installation wizard 😉
26+
27+
```
28+
yarn create cypress tests
29+
```
30+
31+
## Typescript
32+
33+
This package will also automatically determine if typescript if available in this project and inject the required typescript configuration for cypress. If you are starting a new project and want to create typescript configuration, please do the following:
34+
35+
```
36+
npm init
37+
npm install typescript
38+
npx create-cypress-tests
39+
```
40+
41+
## Configuration
42+
43+
Here is a list of available configuration options:
44+
45+
`--use-npm` – use npm if yarn available
46+
`--ignore-typescript` – will not create typescript configuration if available
47+
`--ignore-examples` – will create a 1 empty spec file (`cypress/integration/spec.js`) to start with
48+
`--component-tests` – will not ask should setup component testing or not
49+
50+
## License
51+
52+
The project is licensed under the terms of [MIT license](../../LICENSE)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exports['babel installation template correctly generates plugins config 1'] = `
2+
const preprocessor = require('@cypress/react/plugins/babel');
3+
4+
const something = require("something");
5+
6+
module.exports = (on, config) => {
7+
preprocessor(on, config);
8+
return config; // IMPORTANT to return the config object
9+
};
10+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
exports['Injects guessed next.js template cypress.json'] = `
2+
const preprocessor = require("@cypress/react/plugins/next");
3+
4+
module.exports = (on, config) => {
5+
preprocessor(on, config);
6+
return config; // IMPORTANT to return the config object
7+
};
8+
9+
`
10+
11+
exports['Injects guessed next.js template plugins/index.js'] = `
12+
const preprocessor = require("@cypress/react/plugins/next");
13+
14+
module.exports = (on, config) => {
15+
preprocessor(on, config);
16+
return config; // IMPORTANT to return the config object
17+
};
18+
19+
`
20+
21+
exports['Injects guessed next.js template support/index.js'] = `
22+
import "@cypress/react/support";
23+
24+
`
25+
26+
exports['Injected overridden webpack template cypress.json'] = `
27+
const preprocessor = require("@cypress/react/plugins/react-scripts");
28+
29+
module.exports = (on, config) => {
30+
preprocessor(on, config);
31+
return config; // IMPORTANT to return the config object
32+
};
33+
34+
`
35+
36+
exports['Injected overridden webpack template plugins/index.js'] = `
37+
const preprocessor = require("@cypress/react/plugins/react-scripts");
38+
39+
module.exports = (on, config) => {
40+
preprocessor(on, config);
41+
return config; // IMPORTANT to return the config object
42+
};
43+
44+
`
45+
46+
exports['Injected overridden webpack template support/index.js'] = `
47+
import "./commands.js";
48+
import "@cypress/react/support";
49+
50+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exports['next.js install template correctly generates plugins config 1'] = `
2+
const preprocessor = require('@cypress/react/plugins/next');
3+
4+
const something = require("something");
5+
6+
module.exports = (on, config) => {
7+
preprocessor(on, config);
8+
return config; // IMPORTANT to return the config object
9+
};
10+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
exports['create-react-app install template correctly generates plugins config 1'] = `
2+
const preprocessor = require('@cypress/react/plugins/react-scripts');
3+
4+
const something = require("something");
5+
6+
module.exports = (on, config) => {
7+
preprocessor(on, config);
8+
return config; // IMPORTANT to return the config object
9+
};
10+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
exports['webpack-file install template correctly generates plugins config when webpack config path is missing 1'] = `
2+
const preprocessor = require("@cypress/react/plugins/load-webpack");
3+
4+
const something = require("something");
5+
6+
module.exports = (on, config) => {
7+
// TODO replace with valid webpack config path
8+
config.env.webpackFilename = './webpack.config.js';
9+
preprocessor(on, config);
10+
return config; // IMPORTANT to return the config object
11+
};
12+
`
13+
14+
exports['webpack-file install template correctly generates plugins config when webpack config path is provided 1'] = `
15+
const preprocessor = require("@cypress/react/plugins/load-webpack");
16+
17+
const something = require("something");
18+
19+
module.exports = (on, config) => {
20+
config.env.webpackFilename = 'config/webpack.config.js';
21+
preprocessor(on, config);
22+
return config; // IMPORTANT to return the config object
23+
};
24+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
exports['rollup-file install template correctly generates plugins config when webpack config path is missing 1'] = `
2+
const rollupPreprocessor = require("@bahmutov/cy-rollup");
3+
4+
const something = require("something");
5+
6+
module.exports = (on, config) => {
7+
on('file:preprocessor', rollupPreprocessor({
8+
// TODO replace with valid rollup config path
9+
configFile: 'rollup.config.js'
10+
}));
11+
12+
require('@cypress/code-coverage/task')(on, config);
13+
14+
return config; // IMPORTANT to return the config object
15+
};
16+
`
17+
18+
exports['rollup-file install template correctly generates plugins config when webpack config path is provided 1'] = `
19+
const rollupPreprocessor = require("@bahmutov/cy-rollup");
20+
21+
const something = require("something");
22+
23+
module.exports = (on, config) => {
24+
on('file:preprocessor', rollupPreprocessor({
25+
configFile: 'config/rollup.config.js'
26+
}));
27+
28+
require('@cypress/code-coverage/task')(on, config);
29+
30+
return config; // IMPORTANT to return the config object
31+
};
32+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
exports['vue webpack-file install template correctly generates plugins for vue-cli-service 1'] = `
2+
const preprocessor = require("@cypress/vue/dist/plugins/webpack");
3+
4+
const something = require("something");
5+
6+
module.exports = (on, config) => {
7+
preprocessor(on, config); // IMPORTANT return the config object
8+
9+
return config;
10+
};
11+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
exports['vue webpack-file install template correctly generates plugins config when webpack config path is missing 1'] = `
2+
const {
3+
onFilePreprocessor
4+
} = require('@cypress/vue/dist/preprocessor/webpack');
5+
6+
const something = require("something");
7+
8+
module.exports = (on, config) => {
9+
// TODO replace with valid webpack config path
10+
on('file:preprocessor', onFilePreprocessor('./webpack.config.js'));
11+
};
12+
`
13+
14+
exports['vue webpack-file install template correctly generates plugins config when webpack config path is provided 1'] = `
15+
const {
16+
onFilePreprocessor
17+
} = require('@cypress/vue/dist/preprocessor/webpack');
18+
19+
const something = require("something");
20+
21+
module.exports = (on, config) => {
22+
on('file:preprocessor', onFilePreprocessor('build/webpack.config.js'));
23+
};
24+
`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
exports['webpack-options template correctly generates plugins config 1'] = `
2+
const webpackPreprocessor = require("@cypress/webpack-preprocessor");
3+
4+
const something = require("something");
5+
6+
module.exports = (on, config) => {
7+
const opts = webpackPreprocessor.defaultOptions;
8+
const babelLoader = opts.webpackOptions.module.rules[0].use[0]; // add React preset to be able to transpile JSX
9+
10+
babelLoader.options.presets.push(require.resolve('@babel/preset-react')); // We can also push Babel istanbul plugin to instrument the code on the fly
11+
// and get code coverage reports from component tests (optional)
12+
13+
if (!babelLoader.options.plugins) {
14+
babelLoader.options.plugins = [];
15+
}
16+
17+
babelLoader.options.plugins.push(require.resolve('babel-plugin-istanbul')); // in order to mock named imports, need to include a plugin
18+
19+
babelLoader.options.plugins.push([require.resolve('@babel/plugin-transform-modules-commonjs'), {
20+
loose: true
21+
}]); // add code coverage plugin
22+
23+
require('@cypress/code-coverage/task')(on, config);
24+
25+
on('file:preprocessor', webpackPreprocessor(opts)); // if adding code coverage, important to return updated config
26+
27+
return config;
28+
};
29+
`

npm/create-cypress-tests/demo.gif

29.6 MB
Loading

0 commit comments

Comments
 (0)