Skip to content

Commit e0cab10

Browse files
authored
Merge branch '10.0-release' into zachw/small-browserlist-ui-fix
2 parents 77c535c + ba93023 commit e0cab10

File tree

147 files changed

+20835
-1254
lines changed

Some content is hidden

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

147 files changed

+20835
-1254
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,6 @@ system-tests/projects/nuxtjs-vue2-unconfigured/**/*
9191
system-tests/projects/nuxtjs-vue2-configured/**/*
9292

9393
system-tests/projects/react-app-webpack-5-unconfigured/**/*
94+
95+
system-tests/project-fixtures/**
96+
system-tests/projects/**/*/expected-cypress*/**/*

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ system-tests/fixtures/large-img
7979
/npm/design-system/cypress/videos
8080
/npm/design-system/.babel-cache
8181

82+
# from npm/webpack-dev-server-fresh
83+
/npm/webpack-dev-server-fresh/cypress/videos
84+
8285
# from runner-ct
8386
/packages/runner-ct/cypress/screenshots
8487

circle.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,8 @@ jobs:
10981098
run-app-integration-tests-chrome,
10991099
run-frontend-shared-component-tests-chrome,
11001100
run-launchpad-component-tests-chrome,
1101-
run-launchpad-integration-tests-chrome
1101+
run-launchpad-integration-tests-chrome,
1102+
run-webpack-dev-server-fresh-integration-tests
11021103
- run:
11031104
command: |
11041105
PERCY_PARALLEL_NONCE=$CIRCLE_SHA1 \
@@ -1433,6 +1434,28 @@ jobs:
14331434
path: /tmp/artifacts
14341435
- store-npm-logs
14351436

1437+
run-webpack-dev-server-fresh-integration-tests:
1438+
<<: *defaults
1439+
# parallelism: 3 TODO: Add parallelism once we have more specs
1440+
steps:
1441+
- restore_cached_workspace
1442+
- restore_cached_system_tests_deps
1443+
- run:
1444+
command: |
1445+
CYPRESS_KONFIG_ENV=production \
1446+
CYPRESS_RECORD_KEY=$MAIN_RECORD_KEY \
1447+
PERCY_PARALLEL_NONCE=$CIRCLE_SHA1 \
1448+
PERCY_ENABLE=${PERCY_TOKEN:-0} \
1449+
PERCY_PARALLEL_TOTAL=-1 \
1450+
yarn percy exec --parallel -- -- \
1451+
yarn cypress:run --record --parallel --group webpack-dev-server-fresh
1452+
working_directory: npm/webpack-dev-server-fresh
1453+
- store_test_results:
1454+
path: /tmp/cypress
1455+
- store_artifacts:
1456+
path: /tmp/artifacts
1457+
- store-npm-logs
1458+
14361459
ui-components-integration-tests:
14371460
<<: *defaults
14381461
steps:
@@ -1494,9 +1517,13 @@ jobs:
14941517
<<: *defaults
14951518
steps:
14961519
- restore_cached_workspace
1520+
- restore_cached_system_tests_deps
14971521
- run:
14981522
name: Run tests
14991523
command: yarn workspace @cypress/webpack-dev-server test
1524+
- run:
1525+
name: Run tests
1526+
command: yarn workspace @cypress/webpack-dev-server-fresh test
15001527

15011528
npm-vite-dev-server:
15021529
<<: *defaults
@@ -2226,6 +2253,10 @@ linux-workflow: &linux-workflow
22262253
percy: true
22272254
requires:
22282255
- build
2256+
- run-webpack-dev-server-fresh-integration-tests:
2257+
context: [test-runner:cypress-record-key, test-runner:percy]
2258+
requires:
2259+
- system-tests-node-modules-install
22292260
- run-app-component-tests-chrome:
22302261
context: [test-runner:launchpad-tests, test-runner:percy]
22312262
percy: true
@@ -2241,7 +2272,7 @@ linux-workflow: &linux-workflow
22412272
- build
22422273
- npm-webpack-dev-server:
22432274
requires:
2244-
- build
2275+
- system-tests-node-modules-install
22452276
- npm-vite-dev-server:
22462277
requires:
22472278
- build

cli/scripts/start-build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ includeTypes.forEach((folder) => {
2424

2525
shell.exec('babel lib -d build/lib')
2626
shell.exec('babel index.js -o build/index.js')
27+
shell.cp('index.mjs', 'build/index.mjs')

cli/types/cypress.d.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,7 @@ declare namespace Cypress {
28682868
/**
28692869
* Handle Cypress plugins
28702870
*/
2871-
setupNodeEvents: (on: PluginEvents, config: PluginConfigOptions) => Promise<PluginConfigOptions> | PluginConfigOptions
2871+
setupNodeEvents: (on: PluginEvents, config: PluginConfigOptions) => Promise<PluginConfigOptions | void> | PluginConfigOptions | void
28722872

28732873
indexHtmlFile: string
28742874
}
@@ -2919,6 +2919,7 @@ declare namespace Cypress {
29192919
namespace: string
29202920
projectRoot: string
29212921
devServerPublicPathRoute: string
2922+
cypressBinaryRoot: string
29222923
}
29232924

29242925
/**
@@ -2964,9 +2965,34 @@ declare namespace Cypress {
29642965
*/
29652966
type CoreConfigOptions = Partial<Omit<ResolvedConfigOptions, TestingType>>
29662967

2968+
interface DefineDevServerConfig {
2969+
// This interface can be extended by the user, to inject the types for their
2970+
// preferred bundler: e.g.
2971+
//
2972+
// import type * as webpack from 'webpack'
2973+
//
2974+
// declare global {
2975+
// namespace Cypress {
2976+
// interface DefineDevServerConfig {
2977+
// webpackConfig?: webpack.Configuration
2978+
// }
2979+
// }
2980+
// }
2981+
[key: string]: any
2982+
}
2983+
2984+
type PickConfigOpt<T> = T extends keyof DefineDevServerConfig ? DefineDevServerConfig[T] : any
2985+
29672986
type DevServerFn<ComponentDevServerOpts = any> = (cypressDevServerConfig: DevServerConfig, devServerConfig: ComponentDevServerOpts) => ResolvedDevServerConfig | Promise<ResolvedDevServerConfig>
2987+
2988+
interface DevServerConfigObject {
2989+
bundler: 'webpack'
2990+
framework: 'react'
2991+
webpackConfig?: PickConfigOpt<'webpackConfig'>
2992+
}
2993+
29682994
interface ComponentConfigOptions<ComponentDevServerOpts = any> extends Omit<CoreConfigOptions, 'baseUrl'> {
2969-
devServer: DevServerFn<ComponentDevServerOpts>
2995+
devServer: DevServerFn<ComponentDevServerOpts> | DevServerConfigObject
29702996
devServerConfig?: ComponentDevServerOpts
29712997
}
29722998

@@ -5428,7 +5454,7 @@ declare namespace Cypress {
54285454

54295455
interface ResolvedDevServerConfig {
54305456
port: number
5431-
close: (done?: () => any) => void
5457+
close: (done?: (err?: Error) => any) => void
54325458
}
54335459

54345460
interface PluginEvents {

npm/webpack-dev-server-fresh/CHANGELOG.md

Whitespace-only changes.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# @cypress/webpack-dev-server-fresh
2+
3+
Implements the APIs for the object-syntax of the Cypress Component-testing "webpack dev server".
4+
5+
Object syntax:
6+
7+
```ts
8+
import { defineConfig } from 'cypress'
9+
10+
export default defineConfig({
11+
component: {
12+
devServer: {
13+
framework: 'create-react-app',
14+
bundler: 'webpack',
15+
// webpackConfig?: Will try to infer, if passed it will be used as is
16+
}
17+
}
18+
})
19+
```
20+
21+
Function syntax:
22+
23+
```ts
24+
import { devServer } from '@cypress/webpack-dev-server'
25+
import { defineConfig } from 'cypress'
26+
27+
export default defineConfig({
28+
component: {
29+
devServer(cypressConfig) {
30+
return devServer({
31+
cypressConfig,
32+
framework: 'react',
33+
webpackConfig: require('./webpack.config.js')
34+
})
35+
}
36+
}
37+
})
38+
```
39+
40+
## Testing
41+
42+
Unit tests can be run with `npm test`. Integration tests can be run with `yarn cypress:run`
43+
44+
This module should be primarily covered by system-tests / open-mode tests. All system-tests directories should be created using the notation:
45+
46+
`webpack${major}_wds${devServerMajor}-$framework{-$variant}`
47+
48+
- webpack4_wds3-react
49+
- webpack4_wds4-next-11
50+
- webpack5_wds3-next-12
51+
- webpack4_wds4-create-react-app
52+
53+
## Architecture
54+
55+
There should be a single publicly-exported entrypoint for the module, `devServer`, all other types and functions should be considered internal/implementation details, and types stripped from the output.
56+
57+
The `devServer` will first source the modules from the user's project, falling back to our own bundled versions of libraries. This ensures that the user has installed the current modules, and throws an error if the user does not have the library installed.
58+
59+
From there, we check the "framework" field to source or define any known webpack transforms to aid in the compilation.
60+
61+
We then merge the sourced config with the user's webpack config, and layer on our own transforms, and provide this to a webpack instance. The webpack instance used to create a webpack-dev-server, which is returned.
62+
63+
## Changelog
64+
65+
[Changelog](./CHANGELOG.md)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports['makeWebpackConfig ignores userland webpack `output.publicPath` 1'] = {
2+
"output": {
3+
"publicPath": "/test-public-path/",
4+
"filename": "[name].js"
5+
},
6+
"mode": "development",
7+
"optimization": {
8+
"splitChunks": {
9+
"chunks": "all"
10+
}
11+
},
12+
"plugins": [
13+
"HtmlWebpackPlugin",
14+
"CypressCTWebpackPlugin"
15+
]
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
projectId: 'ypt4pf',
5+
e2e: {
6+
defaultCommandTimeout: 10000, // these take a bit longer b/c they're e2e open mode test
7+
async setupNodeEvents (on, config) {
8+
if (!process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS) {
9+
throw new Error('HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS is missing. Close Cypress and run tests using the `yarn cypress:*` commands from the `packages/app` directory')
10+
}
11+
12+
// Delete this as we only want to honor it on parent Cypress when doing E2E Cypress in Cypress testing
13+
delete process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS
14+
process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF = 'true'
15+
const { e2ePluginSetup } = require('@packages/frontend-shared/cypress/e2e/e2ePluginSetup') as typeof import('@packages/frontend-shared/cypress/e2e/e2ePluginSetup')
16+
17+
return await e2ePluginSetup(on, config)
18+
},
19+
},
20+
// @ts-ignore We are setting these namespaces in order to properly test Cypress in Cypress
21+
clientRoute: '/__app/',
22+
namespace: '__cypress-app',
23+
socketIoRoute: '/__app-socket',
24+
socketIoCookie: '__app-socket',
25+
devServerPublicPathRoute: '/__cypress-app/src',
26+
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/// <reference types="cypress" />
2+
/// <reference path="../support/e2e.ts" />
3+
import type { e2eProjectDirs } from '@packages/frontend-shared/cypress/e2e/support/e2eProjectDirs'
4+
5+
type ProjectDirs = typeof e2eProjectDirs
6+
7+
const WEBPACK_REACT: ProjectDirs[number][] = ['webpack4_wds3-react', 'webpack4_wds4-react', 'webpack5_wds3-react', 'webpack5_wds4-react']
8+
9+
// Add to this list to focus on a particular permutation
10+
const ONLY_PROJECTS: ProjectDirs[number][] = []
11+
12+
for (const project of WEBPACK_REACT) {
13+
if (ONLY_PROJECTS.length && !ONLY_PROJECTS.includes(project)) {
14+
continue
15+
}
16+
17+
describe(`Working with ${project}`, () => {
18+
beforeEach(() => {
19+
cy.scaffoldProject(project)
20+
cy.openProject(project)
21+
cy.startAppServer('component')
22+
})
23+
24+
it('should mount a passing test', () => {
25+
cy.visitApp()
26+
cy.contains('App.cy.jsx').click()
27+
cy.get('.passed > .num').should('contain', 1)
28+
})
29+
30+
it('MissingReact: should fail, rerun, succeed', () => {
31+
cy.once('uncaught:exception', () => {
32+
// Ignore the uncaught exception in the AUT
33+
return false
34+
})
35+
36+
cy.visitApp()
37+
cy.contains('MissingReact.cy.jsx').click()
38+
cy.get('.failed > .num').should('contain', 1)
39+
cy.withCtx(async (ctx) => {
40+
await ctx.actions.file.writeFileInProject(`src/MissingReact.jsx`,
41+
`import React from 'react';
42+
${await ctx.actions.file.readFileInProject('src/MissingReact.jsx')}`)
43+
})
44+
45+
cy.get('.passed > .num').should('contain', 1)
46+
})
47+
48+
it('MissingReactInSpec: should fail, rerun, succeed', () => {
49+
cy.visitApp()
50+
cy.contains('MissingReactInSpec.cy.jsx').click()
51+
cy.get('.failed > .num').should('contain', 1)
52+
cy.withCtx(async (ctx) => {
53+
await ctx.actions.file.writeFileInProject(`src/MissingReactInSpec.cy.jsx`,
54+
await ctx.actions.file.readFileInProject('src/App.cy.jsx'))
55+
})
56+
57+
cy.get('.passed > .num').should('contain', 1)
58+
})
59+
})
60+
}

0 commit comments

Comments
 (0)