Skip to content

Commit fc30118

Browse files
feat(@cypress/react): Make correct plugins for different adapters/bundlers (#15337)
* 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 * Properly exit process if react tests failed * Fix circleci reporter not found * Update nextjs plugin * react-scripts plugin for dev-server * Implement webpack-file plugin support * v0.0.502 * v0.0.503 * Implement rollup support * Implement babel plugin * Update webpack options * Fix nextjs plugin * Unmount components in beforeEach to prevent side-effects * Rename preprocessor to injectDevServer * Fix next.js example * Fix webpack-options exampel * Reproduce rollup problem * Update create-cypress-tests snapshots * Do not run examples/rollup * Uncomment test * Change paralllelism * Remove useless checks * Update snapshots Co-authored-by: Jessica Sachs <jess@jessicasachs.io>
1 parent c405ee8 commit fc30118

File tree

78 files changed

+3051
-2465
lines changed

Some content is hidden

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

78 files changed

+3051
-2465
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ build
77
.publish
88
_test-output
99
cypress.zip
10+
.babel-cache
1011

1112
# from extension
1213
Cached Theme.pak

circle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ jobs:
11081108

11091109
npm-react:
11101110
<<: *defaults
1111-
parallelism: 9
1111+
parallelism: 8
11121112
steps:
11131113
- attach_workspace:
11141114
at: ~/
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
exports['babel installation template correctly generates plugins config 1'] = `
2-
const preprocessor = require('@cypress/react/plugins/babel');
2+
const injectDevServer = require('@cypress/react/plugins/babel');
33
44
const something = require("something");
55
66
module.exports = (on, config) => {
7-
preprocessor(on, config);
7+
injectDevServer(on, config);
88
return config; // IMPORTANT to return the config object
99
};
1010
`

npm/create-cypress-tests/__snapshots__/init-component-testing.test.ts.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
exports['Injects guessed next.js template cypress.json'] = `
2-
const preprocessor = require("@cypress/react/plugins/next");
2+
const injectDevServer = require("@cypress/react/plugins/next");
33
44
module.exports = (on, config) => {
5-
preprocessor(on, config);
5+
injectDevServer(on, config);
66
return config; // IMPORTANT to return the config object
77
};
88
99
`
1010

1111
exports['Injects guessed next.js template plugins/index.js'] = `
12-
const preprocessor = require("@cypress/react/plugins/next");
12+
const injectDevServer = require("@cypress/react/plugins/next");
1313
1414
module.exports = (on, config) => {
15-
preprocessor(on, config);
15+
injectDevServer(on, config);
1616
return config; // IMPORTANT to return the config object
1717
};
1818
@@ -24,20 +24,20 @@ import "@cypress/react/support";
2424
`
2525

2626
exports['Injected overridden webpack template cypress.json'] = `
27-
const preprocessor = require("@cypress/react/plugins/react-scripts");
27+
const injectDevServer = require("@cypress/react/plugins/react-scripts");
2828
2929
module.exports = (on, config) => {
30-
preprocessor(on, config);
30+
injectDevServer(on, config);
3131
return config; // IMPORTANT to return the config object
3232
};
3333
3434
`
3535

3636
exports['Injected overridden webpack template plugins/index.js'] = `
37-
const preprocessor = require("@cypress/react/plugins/react-scripts");
37+
const injectDevServer = require("@cypress/react/plugins/react-scripts");
3838
3939
module.exports = (on, config) => {
40-
preprocessor(on, config);
40+
injectDevServer(on, config);
4141
return config; // IMPORTANT to return the config object
4242
};
4343
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
exports['next.js install template correctly generates plugins config 1'] = `
2-
const preprocessor = require('@cypress/react/plugins/next');
2+
const injectDevServer = require('@cypress/react/plugins/next');
33
44
const something = require("something");
55
66
module.exports = (on, config) => {
7-
preprocessor(on, config);
7+
injectDevServer(on, config);
88
return config; // IMPORTANT to return the config object
99
};
1010
`
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
exports['create-react-app install template correctly generates plugins config 1'] = `
2-
const preprocessor = require('@cypress/react/plugins/react-scripts');
2+
const injectDevServer = require('@cypress/react/plugins/react-scripts');
33
44
const something = require("something");
55
66
module.exports = (on, config) => {
7-
preprocessor(on, config);
7+
injectDevServer(on, config);
88
return config; // IMPORTANT to return the config object
99
};
1010
`
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
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");
2+
const injectDevServer = require("@cypress/react/plugins/load-webpack");
33
44
const something = require("something");
55
66
module.exports = (on, config) => {
77
// TODO replace with valid webpack config path
88
config.env.webpackFilename = './webpack.config.js';
9-
preprocessor(on, config);
9+
injectDevServer(on, config);
1010
return config; // IMPORTANT to return the config object
1111
};
1212
`
1313

1414
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");
15+
const injectDevServer = require("@cypress/react/plugins/load-webpack");
1616
1717
const something = require("something");
1818
1919
module.exports = (on, config) => {
2020
config.env.webpackFilename = 'config/webpack.config.js';
21-
preprocessor(on, config);
21+
injectDevServer(on, config);
2222
return config; // IMPORTANT to return the config object
2323
};
2424
`
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
exports['rollup-file install template correctly generates plugins config when webpack config path is missing 1'] = `
2-
const rollupPreprocessor = require("@bahmutov/cy-rollup");
2+
const path = require("path");
3+
4+
const {
5+
startDevServer
6+
} = require("@cypress/rollup-dev-server");
37
48
const something = require("something");
59
610
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-
11+
on("dev-server:start", async options => {
12+
return startDevServer({
13+
options,
14+
// TODO replace with valid rollup config path
15+
rollupConfig: path.resolve(__dirname, 'rollup.config.js')
16+
});
17+
});
1418
return config; // IMPORTANT to return the config object
1519
};
1620
`
1721

1822
exports['rollup-file install template correctly generates plugins config when webpack config path is provided 1'] = `
19-
const rollupPreprocessor = require("@bahmutov/cy-rollup");
23+
const path = require("path");
24+
25+
const {
26+
startDevServer
27+
} = require("@cypress/rollup-dev-server");
2028
2129
const something = require("something");
2230
2331
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-
32+
on("dev-server:start", async options => {
33+
return startDevServer({
34+
options,
35+
rollupConfig: path.resolve(__dirname, 'config/rollup.config.js')
36+
});
37+
});
3038
return config; // IMPORTANT to return the config object
3139
};
3240
`

npm/create-cypress-tests/__snapshots__/vueCli.test.ts.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
exports['vue webpack-file install template correctly generates plugins for vue-cli-service 1'] = `
2-
const preprocessor = require("@cypress/vue/dist/plugins/webpack");
2+
const injectDevServer = require("@cypress/vue/dist/plugins/webpack");
33
44
const something = require("something");
55
66
module.exports = (on, config) => {
7-
preprocessor(on, config); // IMPORTANT return the config object
7+
injectDevServer(on, config); // IMPORTANT return the config object
88
99
return config;
1010
};

npm/create-cypress-tests/__snapshots__/webpackOptions.test.ts.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
exports['webpack-options template correctly generates plugins config 1'] = `
2-
const webpackPreprocessor = require("@cypress/webpack-preprocessor");
2+
const path = require("path");
3+
4+
const {
5+
startDevServer
6+
} = require("@cypress/webpack-dev-Server");
37
48
const something = require("something");
59
@@ -15,13 +19,13 @@ module.exports = (on, config) => {
1519
publicPath: '/',
1620
chunkFilename: '[name].bundle.js'
1721
},
18-
// TODO: update with valid configuration for your app
22+
// TODO: update with valid configuration for your components
1923
module: {
2024
rules: [{
2125
test: /\\.(js|jsx|mjs|ts|tsx)$/,
2226
loader: 'babel-loader',
23-
options: { ...babelConfig,
24-
cacheDirectory: path.resolve(__dirname, '..', '..', '.babel-cache')
27+
options: {
28+
cacheDirectory: path.resolve(__dirname, '.babel-cache')
2529
}
2630
}]
2731
}

npm/create-cypress-tests/src/component-testing/templates/react/babel.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export const BabelTemplate: Template = {
1111
'webpack',
1212
)} to bundle the components for testing.`,
1313
recommendedComponentFolder: 'cypress/component',
14-
dependencies: ['@cypress/webpack-dev-server'],
14+
dependencies: ['webpack', '@cypress/webpack-dev-server'],
1515
getExampleUrl: () => 'https://github.com/cypress-io/cypress/tree/develop/npm/react/examples/babel',
1616
getPluginsCodeAst: () => {
1717
return {
18-
Require: babel.template.ast('const preprocessor = require(\'@cypress/react/plugins/babel\')'),
18+
Require: babel.template.ast('const injectDevServer = require(\'@cypress/react/plugins/babel\')'),
1919
ModuleExportsBody: babel.template.ast([
20-
'preprocessor(on, config)',
20+
'injectDevServer(on, config)',
2121
'return config // IMPORTANT to return the config object',
2222
].join('\n'), { preserveComments: true }),
2323
}

npm/create-cypress-tests/src/component-testing/templates/react/next.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export const NextTemplate: Template = {
1313
dependencies: ['@cypress/webpack-dev-server'],
1414
getPluginsCodeAst: () => {
1515
return {
16-
Require: babel.template.ast('const preprocessor = require(\'@cypress/react/plugins/next\')'),
16+
Require: babel.template.ast('const injectDevServer = require(\'@cypress/react/plugins/next\')'),
1717
ModuleExportsBody: babel.template.ast([
18-
'preprocessor(on, config)',
18+
'injectDevServer(on, config)',
1919
'return config // IMPORTANT to return the config object',
2020
].join('\n'), { preserveComments: true }),
2121
}

npm/create-cypress-tests/src/component-testing/templates/react/react-scripts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export const ReactScriptsTemplate: Template = {
1616
},
1717
getPluginsCodeAst: () => {
1818
return {
19-
Require: babel.template.ast('const preprocessor = require(\'@cypress/react/plugins/react-scripts\')'),
19+
Require: babel.template.ast('const injectDevServer = require(\'@cypress/react/plugins/react-scripts\')'),
2020
ModuleExportsBody: babel.template.ast([
21-
'preprocessor(on, config)',
21+
'injectDevServer(on, config)',
2222
'return config // IMPORTANT to return the config object',
2323
].join('\n'), { preserveComments: true }),
2424
}

npm/create-cypress-tests/src/component-testing/templates/react/reactWebpackFile.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ export const WebpackTemplate: Template<{ webpackConfigPath: string }> = {
1818
: './webpack.config.js'
1919

2020
return {
21-
Require: babel.template.ast('const preprocessor = require("@cypress/react/plugins/load-webpack")'),
21+
Require: babel.template.ast('const injectDevServer = require("@cypress/react/plugins/load-webpack")'),
2222
ModuleExportsBody: babel.template.ast([
2323
includeWarnComment
2424
? '// TODO replace with valid webpack config path'
2525
: '',
2626
`config.env.webpackFilename = '${webpackConfigPath}'`,
27-
'preprocessor(on, config)',
27+
'injectDevServer(on, config)',
2828
'return config // IMPORTANT to return the config object',
2929
].join('\n'), { preserveComments: true }),
3030
}

npm/create-cypress-tests/src/component-testing/templates/react/rollup.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function extractRollupConfigPathFromScript (script: string) {
2121

2222
export const RollupTemplate: Template<{ rollupConfigPath: string }> = {
2323
message:
24-
'It looks like you have custom `rollup.config.js`. We can use it to bundle the components for testing.',
24+
'It looks like you have custom `rollup.config.js`. We can use it to bundle components for testing.',
2525
getExampleUrl: () => {
2626
return 'https://github.com/cypress-io/cypress/tree/develop/npm/react/examples/rollup'
2727
},
@@ -34,19 +34,21 @@ export const RollupTemplate: Template<{ rollupConfigPath: string }> = {
3434
: 'rollup.config.js'
3535

3636
return {
37-
Require: babel.template.ast('const rollupPreprocessor = require("@bahmutov/cy-rollup")'),
37+
Require: babel.template.ast([
38+
'const path = require("path")',
39+
'const { startDevServer } = require("@cypress/rollup-dev-server")',
40+
].join('\n')),
3841
ModuleExportsBody: babel.template.ast([
39-
`on(`,
40-
` 'file:preprocessor',`,
41-
` rollupPreprocessor({`,
42+
`on("dev-server:start", async (options) => {`,
43+
` return startDevServer({`,
44+
` options,`,
4245
includeWarnComment
43-
? ' // TODO replace with valid rollup config path'
46+
? ' // TODO replace with valid rollup config path'
4447
: '',
45-
` configFile: '${rollupConfigPath}',`,
46-
` }),`,
47-
`)`,
48+
` rollupConfig: path.resolve(__dirname, '${rollupConfigPath}'),`,
49+
` })`,
50+
`})`,
4851
``,
49-
`require('@cypress/code-coverage/task')(on, config)`,
5052
`return config // IMPORTANT to return the config object`,
5153
].join('\n'), { preserveComments: true }),
5254
}

npm/create-cypress-tests/src/component-testing/templates/react/webpack-options-module-exports.template.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const webpackConfig = {
99
publicPath: '/',
1010
chunkFilename: '[name].bundle.js',
1111
},
12-
// TODO: update with valid configuration for your app
12+
// TODO: update with valid configuration for your components
1313
module: {
1414
rules: [
1515
{
1616
test: /\.(js|jsx|mjs|ts|tsx)$/,
1717
loader: 'babel-loader',
18-
options: { ...babelConfig, cacheDirectory: path.resolve(__dirname, '..', '..', '.babel-cache') },
18+
options: { cacheDirectory: path.resolve(__dirname, '.babel-cache') },
1919
},
2020
]
2121
},

npm/create-cypress-tests/src/component-testing/templates/react/webpack-options.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ export const WebpackOptions: Template = {
1212
},
1313
test: () => ({ success: false }),
1414
recommendedComponentFolder: 'src',
15-
dependencies: ['@cypress/webpack-dev-server'],
15+
dependencies: ['webpack', '@cypress/webpack-dev-server'],
1616
getPluginsCodeAst: () => {
1717
return {
18-
Require: babel.template.ast('const webpackPreprocessor = require("@cypress/webpack-preprocessor")'),
18+
Require: babel.template.ast([
19+
'const path = require("path")',
20+
'const { startDevServer } = require("@cypress/webpack-dev-Server")',
21+
].join('\n')),
1922
ModuleExportsBody: babel.template.ast(
2023
fs.readFileSync(path.resolve(__dirname, 'webpack-options-module-exports.template.js'), { encoding: 'utf-8' }),
2124
{ preserveComments: true },

npm/create-cypress-tests/src/component-testing/templates/vue/vueCli.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export const VueCliTemplate: Template = {
1111
getPluginsCodeAst: () => {
1212
return {
1313
Require: babel.template.ast(
14-
'const preprocessor = require("@cypress/vue/dist/plugins/webpack");',
14+
'const injectDevServer = require("@cypress/vue/dist/plugins/webpack");',
1515
),
1616
ModuleExportsBody: babel.template.ast([
17-
'preprocessor(on, config);',
17+
'injectDevServer(on, config);',
1818
'// IMPORTANT return the config object',
1919
'return config',
2020
].join('\n'), { preserveComments: true }),

npm/react/cypress/plugins/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ const webpackConfig = {
6161
* @type Cypress.PluginConfig
6262
*/
6363
module.exports = (on, config) => {
64-
on('dev-server:start', (options) => startDevServer({ options, webpackConfig, disableLazyCompilation: false }))
64+
on('dev-server:start', (options) => {
65+
return startDevServer({ options, webpackConfig, disableLazyCompilation: false })
66+
})
6567

6668
return config
6769
}

npm/react/examples/a11y/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Testing component accessibility",
44
"private": true,
55
"scripts": {
6-
"cy:open": "node ../../../../scripts/cypress open",
7-
"test": "node ../../../../scripts/cypress run"
6+
"cy:open": "node ../../../../scripts/cypress open-ct",
7+
"test": "node ../../../../scripts/cypress run-ct"
88
},
99
"devDependencies": {
1010
"@cypress/react": "file:../../dist",

0 commit comments

Comments
 (0)