Skip to content

Commit bb8251b

Browse files
feat: Use plugins on config files (#18798)
Co-authored-by: Tim Griesser <tgriesser10@gmail.com>
1 parent 8a2acdc commit bb8251b

File tree

259 files changed

+2657
-2636
lines changed

Some content is hidden

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

259 files changed

+2657
-2636
lines changed

circle.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ jobs:
10321032
runner-integration-tests-chrome,
10331033
runner-ct-integration-tests-chrome,
10341034
reporter-integration-tests,
1035+
run-app-integration-tests-chrome,
1036+
run-launchpad-integration-tests-chrome
10351037
- run: yarn percy build:finalize
10361038

10371039
cli-visual-tests:
@@ -1914,7 +1916,21 @@ jobs:
19141916
CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1"
19151917
command: |
19161918
rm -rf cypress.json
1917-
echo 'export default {}' > cypress.config.ts
1919+
echo "export default {
1920+
e2e: {
1921+
setupNodeEvents (on, config) {
1922+
on('task', {
1923+
log (x) {
1924+
console.log(x)
1925+
1926+
return null
1927+
},
1928+
})
1929+
1930+
return config
1931+
},
1932+
},
1933+
}" > cypress.config.ts
19181934
- run:
19191935
name: Run project tests 🗳
19201936
working_directory: <<parameters.wd>>

cli/test/spec_helper.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const mockfs = require('mock-fs')
66
const Promise = require('bluebird')
77
const util = require('../lib/util')
88
const { MockChildProcess } = require('spawn-mock')
9+
910
const _kill = MockChildProcess.prototype.kill
1011

1112
const patchMockSpawn = () => {

cli/types/cypress.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,11 @@ declare namespace Cypress {
28132813
* An array of objects defining the certificates
28142814
*/
28152815
clientCertificates: ClientCertificate[]
2816+
2817+
/**
2818+
* Handle Cypress plugins
2819+
*/
2820+
setupNodeEvents: (on: PluginEvents, config: PluginConfigOptions) => Promise<PluginConfigOptions> | PluginConfigOptions
28162821
}
28172822

28182823
/**

npm/angular/cypress.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export default defineConfig({
99
'component': {
1010
'componentFolder': 'src/app',
1111
'testFiles': '**/*cy-spec.ts',
12+
'setupNodeEvents': require('./cypress/plugins'),
1213
},
1314
})

npm/design-system/cypress.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,13 @@ module.exports = {
1313
],
1414
componentFolder: 'src',
1515
fixturesFolder: false,
16+
component: {
17+
setupNodeEvents (on, config) {
18+
const { startDevServer } = require('@cypress/vite-dev-server')
19+
20+
on('dev-server:start', (options) => startDevServer({ options }))
21+
22+
return config
23+
},
24+
},
1625
}

npm/design-system/cypress/plugins/index.js

-11
This file was deleted.

npm/react/cypress.config.js

+68
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @ts-check
2+
13
module.exports = {
24
'viewportWidth': 400,
35
'viewportHeight': 400,
@@ -12,4 +14,70 @@ module.exports = {
1214
'**/__image_snapshots__/*',
1315
],
1416
'experimentalFetchPolyfill': true,
17+
'component': {
18+
setupNodeEvents (on, config) {
19+
const { startDevServer } = require('@cypress/webpack-dev-server')
20+
const path = require('path')
21+
const babelConfig = require('./babel.config.js')
22+
23+
const webpackConfig = {
24+
resolve: {
25+
extensions: ['.js', '.ts', '.jsx', '.tsx'],
26+
},
27+
mode: 'development',
28+
devtool: false,
29+
output: {
30+
publicPath: '/',
31+
chunkFilename: '[name].bundle.js',
32+
},
33+
module: {
34+
rules: [
35+
{
36+
test: /\.(js|jsx|mjs|ts|tsx)$/,
37+
loader: 'babel-loader',
38+
options: { ...babelConfig, cacheDirectory: path.resolve(__dirname, '..', '..', '.babel-cache') },
39+
},
40+
{
41+
test: /\.modules\.css$/i,
42+
exclude: [/node_modules/],
43+
use: [
44+
'style-loader',
45+
{
46+
loader: 'css-loader',
47+
options: {
48+
modules: true,
49+
},
50+
},
51+
],
52+
},
53+
{
54+
test: /\.css$/,
55+
exclude: [/node_modules/, /\.modules\.css$/i],
56+
use: ['style-loader', 'css-loader'],
57+
},
58+
{
59+
// some of our examples import SVG
60+
test: /\.svg$/,
61+
loader: 'svg-url-loader',
62+
},
63+
{
64+
// some of our examples import SVG
65+
test: /\.svg$/,
66+
loader: 'svg-url-loader',
67+
},
68+
{
69+
test: /\.(png|jpg)$/,
70+
use: ['file-loader'],
71+
},
72+
],
73+
},
74+
}
75+
76+
on('dev-server:start', (options) => {
77+
return startDevServer({ options, webpackConfig, disableLazyCompilation: false })
78+
})
79+
80+
return config
81+
},
82+
},
1583
}

npm/react/cypress/plugins/index.js

-73
This file was deleted.

npm/react/examples/a11y/cypress.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,17 @@ module.exports = {
44
'testFiles': '**/*spec.js',
55
'viewportWidth': 500,
66
'viewportHeight': 500,
7+
'component': {
8+
setupNodeEvents (on, config) {
9+
// load file devServer that comes with this plugin
10+
// https://github.com/bahmutov/cypress-react-unit-test#install
11+
const devServer = require('@cypress/react/plugins/react-scripts')
12+
13+
devServer(on, config)
14+
15+
// IMPORTANT to return the config object
16+
// with the any changed environment variables
17+
return config
18+
},
19+
},
720
}

npm/react/examples/a11y/cypress/plugins/index.js

-16
This file was deleted.

npm/react/examples/craco/cypress.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@ module.exports = {
22
'component': {
33
'testFiles': '**/*.test.{js,ts,jsx,tsx}',
44
'componentFolder': 'src',
5+
setupNodeEvents (on, config) {
6+
const cracoConfig = require('./craco.config.js')
7+
const devServer = require('@cypress/react/plugins/craco')
8+
9+
devServer(on, config, cracoConfig)
10+
11+
return config
12+
},
513
},
614
}

npm/react/examples/craco/cypress/plugins/index.js

-13
This file was deleted.

npm/react/examples/find-webpack/cypress.config.ts

+24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@ export default defineConfig({
66
'component': {
77
'testFiles': '**/*.spec.{js,ts,jsx,tsx}',
88
'componentFolder': 'src',
9+
setupNodeEvents (on, config) {
10+
const findReactScriptsWebpackConfig = require('@cypress/react/plugins/react-scripts/findReactScriptsWebpackConfig')
11+
const { startDevServer } = require('@cypress/webpack-dev-server')
12+
const _ = require('lodash')
13+
14+
const map = _.map([4, 8], (n) => n * 2)
15+
16+
console.log(map)
17+
require('@cypress/code-coverage/task')(on, config)
18+
const webpackConfig = findReactScriptsWebpackConfig(config)
19+
20+
const rules = webpackConfig.module.rules.find((rule) => !!rule.oneOf).oneOf
21+
const babelRule = rules.find((rule) => typeof rule.loader === 'string' && /babel-loader/.test(rule.loader))
22+
23+
typeof babelRule.options !== 'string' && babelRule.options.plugins.push(require.resolve('babel-plugin-istanbul'))
24+
25+
on('dev-server:start', (options) => {
26+
return startDevServer({ options, webpackConfig })
27+
})
28+
29+
// IMPORTANT to return the config object
30+
// with the any changed environment variables
31+
return config
32+
},
933
},
1034
'env': {
1135
'cypress-react-selector': {

npm/react/examples/find-webpack/cypress/plugins/index.js

-29
This file was deleted.

npm/react/examples/nextjs-webpack-5/cypress.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,13 @@ module.exports = {
55
'viewportHeight': 800,
66
'componentFolder': 'cypress/components',
77
'pluginsFile': 'cypress/plugins.js',
8+
'component': {
9+
setupNodeEvents (on, config) {
10+
const devServer = require('@cypress/react/plugins/next')
11+
12+
devServer(on, config)
13+
14+
return config
15+
},
16+
},
817
}

npm/react/examples/nextjs-webpack-5/cypress/plugins.js

-10
This file was deleted.

npm/react/examples/nextjs/cypress.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ module.exports = {
88
'env': {
99
'coverage': true,
1010
},
11+
'component': {
12+
setupNodeEvents (on, config) {
13+
const devServer = require('@cypress/react/plugins/next')
14+
15+
devServer(on, config)
16+
17+
return config
18+
},
19+
},
1120
}

0 commit comments

Comments
 (0)