Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow cypress config.port to override devServer.port for proxying assets #27677

Merged
merged 30 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f82fdf0
fix: allow cypress config.port to override devServer.port for proxyin…
brian-mann Aug 28, 2023
4c54f20
changelog
lmiller1990 Aug 28, 2023
e90de0e
update snapshots
brian-mann Aug 28, 2023
f842e3f
Merge branch 'fix/config-port-overriding-devserver' of https://github…
brian-mann Aug 28, 2023
8e03114
chore: bump cache version
AtofStryker Aug 28, 2023
c30ce10
fix cy in cy tests
ryanthemanuel Aug 28, 2023
ee912fa
fix tests
ryanthemanuel Aug 28, 2023
ed303ba
fix issue where vite config was set properly
mschile Aug 28, 2023
fbd86e1
additional fixes
ryanthemanuel Aug 28, 2023
0bda09b
fix require
mschile Aug 28, 2023
837a19c
fix launchpad tests
ryanthemanuel Aug 28, 2023
078319e
Update system-tests/test/vite_dev_server_fresh_spec.ts
brian-mann Aug 28, 2023
37dd857
fix additional tests
ryanthemanuel Aug 28, 2023
b6f8794
fix tests
ryanthemanuel Aug 28, 2023
c697b80
always strip ansi from stdout BEFORE calling options.onStdout
brian-mann Aug 28, 2023
b141c20
Merge branch 'fix/config-port-overriding-devserver' of https://github…
brian-mann Aug 28, 2023
da36aa5
updating configFile in react system test
mschile Aug 28, 2023
5b621de
fix additional cy in cy tests
ryanthemanuel Aug 28, 2023
8322f14
fix cy in cy test
ryanthemanuel Aug 28, 2023
35523a2
fix tests
ryanthemanuel Aug 28, 2023
3bacf34
update snapshot
brian-mann Aug 28, 2023
8a60770
Merge branch 'fix/config-port-overriding-devserver' of https://github…
brian-mann Aug 28, 2023
3a441c5
fix for enabling turning off stripping ansi for that 1 special report…
brian-mann Aug 28, 2023
9a0481f
fix last flake
ryanthemanuel Aug 29, 2023
ca7bad2
fix last flake
ryanthemanuel Aug 29, 2023
0a0eebd
Merge branch 'develop' into fix/config-port-overriding-devserver
ryanthemanuel Aug 29, 2023
568e2a1
fix system tests
ryanthemanuel Aug 29, 2023
ee0fbd9
fix typo
ryanthemanuel Aug 29, 2023
181b27c
let's try this again
ryanthemanuel Aug 29, 2023
e684546
fix tests
ryanthemanuel Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/cache-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Bump this version to force CI to re-create the cache from scratch.

08-19-23
08-28-23
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ _Released 08/22/2023 (PENDING)_
- Resolve the `process/browser` global inside `@cypress/webpack-batteries-included-preprocessor` to resolve to `process/browser.js` in order to explicitly provide the file extension. File resolution must include the extension for `.mjs` and `.js` files inside ESM packages in order to resolve correctly. Fixes[#27599](https://github.com/cypress-io/cypress/issues/27599).
- Fixed an issue where the correct `pnp` process was not being discovered. Fixes [#27562](https://github.com/cypress-io/cypress/issues/27562).
- Fixed incorrect type declarations for Cypress and Chai globals that asserted them to be local variables of the global scope rather than properties on the global object. Fixes [#27539](https://github.com/cypress-io/cypress/issues/27539). Fixed in [#27540](https://github.com/cypress-io/cypress/pull/27540).
- Dev Servers will now respect and use the `port` configuration option if present. Fixes [#27675](https://github.com/cypress-io/cypress/issues/27675).

**Dependency Updates:**

Expand Down
2 changes: 1 addition & 1 deletion npm/vite-dev-server/cypress/e2e/react.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for (const project of VITE_REACT) {
describe(`Working with ${project}`, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project, ['--config-file', 'cypress-vite.config.ts'])
cy.openProject(project, ['--config-file', 'cypress-vite.config.ts', '--component'])
cy.startAppServer('component')
})

Expand Down
29 changes: 6 additions & 23 deletions npm/vite-dev-server/cypress/e2e/vite-dev-server.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dedent from 'dedent'
describe('Config options', () => {
it('works with tailwind', () => {
cy.scaffoldProject('tailwind-vite')
cy.openProject('tailwind-vite')
cy.openProject('tailwind-vite', ['--component'])
cy.startAppServer('component')

cy.visitApp()
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Config options', () => {

it('supports supportFile = false', () => {
cy.scaffoldProject('vite2.9.1-react')
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-no-support.config.ts'])
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-no-support.config.ts', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand All @@ -53,28 +53,11 @@ describe('Config options', () => {
cy.get('.passed > .num').should('contain', 1)
})

it('chooses new port when specified port is in use', () => {
cy.scaffoldProject('vite2.9.1-react')
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-port-in-use.config.ts'])
cy.startAppServer('component')

cy.visitApp()

cy.contains('App.cy.jsx').click()
cy.get('.passed > .num').should('contain', 2)

cy.withCtx(async (ctx) => {
const config = ctx.lifecycleManager.loadedFullConfig

expect(config.baseUrl).to.equal('http://localhost:3001')
})
})

it('supports serving files with whitespace', () => {
const specWithWhitespace = 'spec with whitespace.cy.jsx'

cy.scaffoldProject('vite2.9.1-react')
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite.config.ts'])
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite.config.ts', '--component'])
cy.startAppServer('component')

cy.withCtx(async (ctx, { specWithWhitespace }) => {
Expand All @@ -91,7 +74,7 @@ describe('Config options', () => {

it('supports @cypress/vite-dev-server', () => {
cy.scaffoldProject('vite2.9.1-react')
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-dev-server-function.config.ts'])
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-dev-server-function.config.ts', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand All @@ -102,7 +85,7 @@ describe('Config options', () => {

it('supports viteConfig as an async function', () => {
cy.scaffoldProject('vite2.9.1-react')
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-async-function-config.config.ts'])
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite-async-function-config.config.ts', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand Down Expand Up @@ -132,7 +115,7 @@ describe('sourcemaps', () => {
`

cy.scaffoldProject('vite3.0.2-react')
cy.openProject('vite3.0.2-react', ['--config-file', 'cypress-vite.config.ts'])
cy.openProject('vite3.0.2-react', ['--config-file', 'cypress-vite.config.ts', '--component'])
cy.startAppServer('component')

cy.withCtx(async (ctx, o) => {
Expand Down
4 changes: 4 additions & 0 deletions npm/vite-dev-server/src/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const createViteDevServerConfig = async (config: ViteDevServerConfig, vit
function makeCypressViteConfig (config: ViteDevServerConfig, vite: Vite): InlineConfig {
const {
cypressConfig: {
port,
projectRoot,
devServerPublicPathRoute,
supportFile,
Expand All @@ -74,6 +75,8 @@ function makeCypressViteConfig (config: ViteDevServerConfig, vite: Vite): Inline
specs,
} = config

const vitePort = port ?? undefined

// Vite caches its output in the .vite directory in the node_modules where vite lives.
// So we want to find that node_modules path and ensure it's added to the "allow" list
const vitePathNodeModules = path.dirname(path.dirname(require.resolve(`vite/package.json`, {
Expand Down Expand Up @@ -122,6 +125,7 @@ function makeCypressViteConfig (config: ViteDevServerConfig, vite: Vite): Inline
vite.searchForWorkspaceRoot?.(process.cwd()),
],
},
port: vitePort,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just be port - if port is provided, it's a number, otherwise it'll be undefined. No need for the vitePort variable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it’s needed because of types. Cypress provided types are number or null. Vite is number or undefined. Switch it and it’ll yell at you.

host: '127.0.0.1',
// Disable file watching and HMR when executing tests in `run` mode
...(isTextTerminal
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/angular.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for (const project of WEBPACK_ANGULAR) {
context(project, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project)
cy.openProject(project, ['--component'])
})

describe('configuration handling', () => {
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/create-react-app.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for (const project of WEBPACK_REACT) {
describe(`Working with ${project}`, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project)
cy.openProject(project, ['--component'])
cy.startAppServer('component')
})

Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/next.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for (const project of WEBPACK_REACT) {
describe(`Working with ${project}`, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project)
cy.openProject(project, ['--component'])
cy.startAppServer('component')
})

Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/nuxt.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ for (const project of PROJECTS) {
describe(`Working with ${project}`, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project)
cy.openProject(project, ['--component'])
cy.startAppServer('component')
})

Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/react.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for (const project of WEBPACK_REACT) {
describe(`Working with ${project}`, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project, ['--config-file', 'cypress-webpack.config.ts'])
cy.openProject(project, ['--config-file', 'cypress-webpack.config.ts', '--component'])
cy.startAppServer('component')
})

Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/vue-cli.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for (const project of PROJECTS) {
describe(`Working with ${project}`, () => {
beforeEach(() => {
cy.scaffoldProject(project)
cy.openProject(project)
cy.openProject(project, ['--component'])
cy.startAppServer('component')
})

Expand Down
12 changes: 6 additions & 6 deletions npm/webpack-dev-server/cypress/e2e/webpack-dev-server.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe('Config options', () => {
it('supports supportFile = false', () => {
cy.scaffoldProject('webpack5_wds4-react')
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-no-support.config.ts'])
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-no-support.config.ts', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand All @@ -14,7 +14,7 @@ describe('Config options', () => {

it('supports nested config', () => {
cy.scaffoldProject('webpack-react-nested-config')
cy.openProject('webpack-react-nested-config', ['--config-file', 'cypress/cypress.config.js'])
cy.openProject('webpack-react-nested-config', ['--config-file', 'cypress/cypress.config.js', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand All @@ -25,7 +25,7 @@ describe('Config options', () => {

it('supports @cypress/webpack-dev-server', () => {
cy.scaffoldProject('webpack5_wds4-react')
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-dev-server-function.config.ts'])
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-dev-server-function.config.ts', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand All @@ -36,7 +36,7 @@ describe('Config options', () => {

it('supports webpackConfig as an async function', () => {
cy.scaffoldProject('webpack5_wds4-react')
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-dev-server-async-config.config.ts'])
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-dev-server-async-config.config.ts', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand All @@ -53,7 +53,7 @@ describe('Config options', () => {

it('recompiles with new spec and custom indexHtmlFile', () => {
cy.scaffoldProject('webpack5_wds4-react')
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-dev-server-custom-index.config.ts'])
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-dev-server-custom-index.config.ts', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand All @@ -71,7 +71,7 @@ describe('Config options', () => {

it('supports loading assets via relative urls', () => {
cy.scaffoldProject('webpack-dev-server-relative')
cy.openProject('webpack-dev-server-relative')
cy.openProject('webpack-dev-server-relative', ['--component'])
cy.startAppServer('component')

cy.visitApp()
Expand Down
5 changes: 4 additions & 1 deletion npm/webpack-dev-server/src/devServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ export function devServer (devServerConfig: WebpackDevServerConfig): Promise<Cyp
return new Promise(async (resolve, reject) => {
const result = await devServer.create(devServerConfig) as DevServerCreateResult

// @ts-expect-error
const { port } = result.server?.options

if (result.version === 3) {
const srv = result.server.listen(0, '127.0.0.1', () => {
const srv = result.server.listen(port || 0, '127.0.0.1', () => {
const port = (srv.address() as AddressInfo).port

debug('Component testing webpack server 3 started on port %s', port)
Expand Down
5 changes: 5 additions & 0 deletions npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function makeCypressWebpackConfig (
const {
devServerConfig: {
cypressConfig: {
port,
projectRoot,
devServerPublicPathRoute,
supportFile,
Expand All @@ -43,6 +44,8 @@ export function makeCypressWebpackConfig (
},
} = config

const webpackDevServerPort = port ?? undefined

debug(`Using HtmlWebpackPlugin version ${htmlWebpackPluginVersion} from ${htmlWebpackPluginImportPath}`)

const optimization: Record<string, any> = {
Expand Down Expand Up @@ -106,6 +109,7 @@ export function makeCypressWebpackConfig (
return {
...finalConfig,
devServer: {
port: webpackDevServerPort,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again just port is okay, but this is more explicit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types problem without coercing to undefined

client: {
overlay: false,
},
Expand All @@ -117,6 +121,7 @@ export function makeCypressWebpackConfig (
return {
...finalConfig,
devServer: {
port: webpackDevServerPort,
overlay: false,
},
}
Expand Down
8 changes: 4 additions & 4 deletions packages/app/cypress/e2e/create-from-component.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('Create from component card', () => {
context('project with default spec pattern', () => {
validateCreateFromVueComponentCard(() => {
cy.scaffoldProject('no-specs-vue-2')
cy.openProject('no-specs-vue-2')
cy.openProject('no-specs-vue-2', ['--component'])
cy.startAppServer('component')
cy.visitApp()

Expand All @@ -219,7 +219,7 @@ describe('Create from component card', () => {
context('project with custom spec pattern', () => {
validateCreateFromVueComponentCard(() => {
cy.scaffoldProject('no-specs-vue-2')
cy.openProject('no-specs-vue-2', ['--config-file', 'cypress-custom-spec-pattern.config.js'])
cy.openProject('no-specs-vue-2', ['--config-file', 'cypress-custom-spec-pattern.config.js', '--component'])
cy.startAppServer('component')
cy.visitApp()

Expand All @@ -233,7 +233,7 @@ describe('Create from component card', () => {
context('project with default spec pattern', () => {
validateCreateFromReactComponentCard(() => {
cy.scaffoldProject('no-specs')
cy.openProject('no-specs')
cy.openProject('no-specs', ['--component'])
cy.startAppServer('component')
cy.visitApp()

Expand All @@ -244,7 +244,7 @@ describe('Create from component card', () => {
context('project with custom spec pattern', () => {
validateCreateFromReactComponentCard(() => {
cy.scaffoldProject('no-specs')
cy.openProject('no-specs', ['--config-file', 'cypress-custom-spec-pattern.config.ts'])
cy.openProject('no-specs', ['--config-file', 'cypress-custom-spec-pattern.config.ts', '--component'])
cy.startAppServer('component')
cy.visitApp()

Expand Down
4 changes: 2 additions & 2 deletions packages/app/cypress/e2e/cypress-in-cypress-component.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Cypress In Cypress CT', { viewportWidth: 1500, defaultCommandTimeout:
beforeEach(() => {
cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')
cy.openProject('cypress-in-cypress', ['--component'])
cy.startAppServer('component')
})

Expand Down Expand Up @@ -187,7 +187,7 @@ describe('Cypress In Cypress CT', { viewportWidth: 1500, defaultCommandTimeout:
})

it('set the correct viewport values from CLI', () => {
cy.openProject('cypress-in-cypress', ['--config', 'viewportWidth=333,viewportHeight=333'])
cy.openProject('cypress-in-cypress', ['--config', 'viewportWidth=333,viewportHeight=333', '--component'])
cy.startAppServer('component')

cy.visitApp()
Expand Down
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/cypress-in-cypress-run-mode.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Cypress In Cypress - run mode', { viewportWidth: 1200 }, () => {
it('component testing run mode spec runner header is correct', () => {
cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')
cy.openProject('cypress-in-cypress', ['--component'])
cy.startAppServer('component')
cy.visitApp(`/specs/runner?file=src/TestComponent.spec.jsx&${CY_IN_CY_SIMULATE_RUN_MODE}`)

Expand Down
14 changes: 12 additions & 2 deletions packages/app/cypress/e2e/cypress-in-cypress.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@ const dragHandleToClientX = (panel: DraggablePanel, x: number) => {
function startAtSpecsPage (testingType: typeof testingTypes[number]) {
cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')

openProject(testingType)

cy.startAppServer(testingType)
cy.visitApp()
}

function openProject (testingType: typeof testingTypes[number]) {
if (testingType === 'e2e') {
cy.openProject('cypress-in-cypress')
} else {
cy.openProject('cypress-in-cypress', ['--component'])
}
}

// For Cypress-in-Cypress tests that do not vary based on testing type
describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 10000 }, () => {
testingTypes.forEach((testingType) => {
Expand Down Expand Up @@ -103,7 +113,7 @@ describe('Cypress in Cypress', { viewportWidth: 1500, defaultCommandTimeout: 100

cy.scaffoldProject('cypress-in-cypress')
cy.findBrowsers()
cy.openProject('cypress-in-cypress')
openProject(testingType)
cy.withCtx((ctx) => {
ctx.coreData.localSettings.preferences.reporterWidth = 800
ctx.coreData.localSettings.preferences.specListWidth = 250
Expand Down
2 changes: 1 addition & 1 deletion packages/app/cypress/e2e/debug.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Cypress.on('window:before:load', (win) => {
describe('App - Debug Page', () => {
beforeEach(() => {
cy.scaffoldProject('cypress-in-cypress')
cy.openProject('cypress-in-cypress')
cy.openProject('cypress-in-cypress', ['--component'])
cy.startAppServer('component')

cy.loginUser()
Expand Down
4 changes: 2 additions & 2 deletions packages/app/cypress/e2e/runner/ct-framework-errors.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function verifyErrorOnlyCapturedOnce (err: string) {
function loadErrorSpec (options: Options): VerifyFunc {
const { projectName, filePath, failCount, passCount = '--', configFile } = options

cy.openProject(projectName, ['--config-file', configFile])
cy.openProject(projectName, ['--config-file', configFile, '--component'])
cy.startAppServer('component')
cy.visitApp(`specs/runner?file=${filePath}`)

Expand Down Expand Up @@ -68,7 +68,7 @@ reactVersions.forEach((reactVersion) => {
it('error conditions', () => {
const verify = loadErrorSpec({
projectName: `react${reactVersion}`,
configFile: 'cypress-vite.config.ts',
configFile: 'cypress-vite-default.config.ts',
filePath: 'src/Errors.cy.jsx',
failCount: 4,
})
Expand Down
Loading