Skip to content

Commit c405ee8

Browse files
feat: create-cypress-tests installation wizard (#9563)
* Remove unused stuff * Fix eslint errors * Use local cypress running script * Fix dependency resolution * Revert "Fix dependency resolution" This reverts commit 01a70be. * Add @cypress/react CI * Properly resolve @types pacakges * Run tests with mocha * Fix cypress tests * Fix or skip some specs * Add retries to the card-spec.js * Remove jest mocks * Run e2e examples on CI * Fix yarn cache key * Fix e2e examples jobs * Rename cypress-react-unit-test with @cypress/react * Fix circleci.yml * Revert "Fix e2e examples jobs" This reverts commit efcc7c4. * Revert " Rename cypress-react-unit-test with @cypress/react" This reverts commit 4febfcc. * Replce cypress-react-unit-test with @cypress/react * Persist build artifacts * Fix working directory paths circle.yml * Fix more CI * adding yarn.lock files * Make package.json for folder * Remove .npmrc * Update circle.yml * Remove unused files * Copy plugins files to the "dist" folder * Fix links to the github repos * Move init wizard from npm/react/init to npm/wizard * Move init wizard from npm/react/init to npm/wizard * Implement initial vue template * Run wizard tests on CI * Refactor continue: bool to success: bool for better code readability * Fix circleci.yml * Use only absolute paths for tests * Stub process.exit calls * Remove useless comments * Add installation cypress to the wizard logic * More improvements * Include packages/examples/cypress into git * Commit new files * Use packages/example as SST for generated files * Last improvements for wizard * Update packages/server/lib/scaffold.js * Rename wizard to create-cypress-tests * Fix circleci config * Fix snapshot tests * Run all create-cypress-tests on ci * Do not install plugins and scaffold files from kitchensink * Ignore integration/examples folder for packages/example * Run create-cypress-tests-tests on CI * Add copy example cross-platform script * Use copy example script in tests * feat: create-cypress-tests auto-inject config (#9116) * Implement the basic babel code transformation for configs * Add more tests for edge-cases * Add snapshot tests for autogenerated code for each template * Add git status guard * Add git status guard * Fix last test * Fix tests * Revert changes for packages/example * Revert changes for packages/example/tsconfig.json * Prepeare package for the release * Fix inquirer name * v0.0.125 * v0.0.127 * v0.0.128 * v0.0.130 * v0.0.131 * Add more UX features * Add vue-cli template * Make src as default folder for vue-cli template * Revert dev-time changes * Run appveyour windows build * Run full appveyour build * Fix circle.yml * Update plugins * Join paths for windows * Revert example/lib changes * Fix tests * Revert unnecessary changes * Implement dev-server dependency installation * Update npm/create-cypress-tests/README.md * Include webpack-options template in dist Co-authored-by: Jessica Sachs <jess@jessicasachs.io>
1 parent cce08d2 commit c405ee8

Some content is hidden

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

77 files changed

+3384
-61
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

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ packages/server/test/support/fixtures/server/libs
4848
# from runner-ct
4949
/packages/runner-ct/cypress/screenshots
5050

51+
# from npm/create-cypress-tests
52+
/npm/create-cypress-tests/initial-template
53+
/npm/create-cypress-tests/src/test-output
54+
5155
# Building app binary
5256
scripts/support
5357
package-lock.json

appveyor.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ branches:
44
- develop
55
- sem-next-ver
66
- /win*/
7+
- feature/cross-platform-wizard
78

89
# https://www.appveyor.com/docs/lang/nodejs-iojs/
910
environment:

circle.yml

+14
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,17 @@ jobs:
11291129
path: npm/react/test_results
11301130
- store-npm-logs
11311131

1132+
1133+
npm-create-cypress-tests:
1134+
<<: *defaults
1135+
steps:
1136+
- attach_workspace:
1137+
at: ~/
1138+
- run: yarn workspace create-cypress-tests build
1139+
- run:
1140+
name: Run unit test
1141+
command: yarn workspace create-cypress-tests test
1142+
11321143
npm-eslint-plugin-dev:
11331144
<<: *defaults
11341145
steps:
@@ -1758,6 +1769,9 @@ linux-workflow: &linux-workflow
17581769
- npm-react:
17591770
requires:
17601771
- build
1772+
- npm-create-cypress-tests:
1773+
requires:
1774+
- build
17611775
- npm-eslint-plugin-dev:
17621776
requires:
17631777
- build

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,13 @@
1+
exports['vue: vite template correctly generates plugins config 1'] = `
2+
const {
3+
startDevServer
4+
} = require("@cypress/vite-dev-server");
5+
6+
const something = require("something");
7+
8+
module.exports = (on, config) => {
9+
on("dev-server:start", async options => startDevServer({
10+
options
11+
}));
12+
};
13+
`
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,34 @@
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+
/** @type import("webpack").Configuration */
8+
const webpackConfig = {
9+
resolve: {
10+
extensions: ['.js', '.ts', '.jsx', '.tsx']
11+
},
12+
mode: 'development',
13+
devtool: false,
14+
output: {
15+
publicPath: '/',
16+
chunkFilename: '[name].bundle.js'
17+
},
18+
// TODO: update with valid configuration for your app
19+
module: {
20+
rules: [{
21+
test: /\\.(js|jsx|mjs|ts|tsx)$/,
22+
loader: 'babel-loader',
23+
options: { ...babelConfig,
24+
cacheDirectory: path.resolve(__dirname, '..', '..', '.babel-cache')
25+
}
26+
}]
27+
}
28+
};
29+
on('dev-server:start', options => startDevServer({
30+
options,
31+
webpackConfig
32+
}));
33+
};
34+
`

npm/create-cypress-tests/demo.gif

29.6 MB
Loading

0 commit comments

Comments
 (0)