Skip to content

Commit

Permalink
Merge pull request #27677 from cypress-io/fix/config-port-overriding-…
Browse files Browse the repository at this point in the history
…devserver
  • Loading branch information
ryanthemanuel authored Aug 29, 2023
2 parents 8e23148 + e684546 commit e5c7116
Show file tree
Hide file tree
Showing 49 changed files with 1,069 additions and 251 deletions.
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,
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,
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

4 comments on commit e5c7116

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e5c7116 Aug 29, 2023

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/linux-x64/develop-e5c7116eff4f1f62b6328670d147c1734b9108ec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e5c7116 Aug 29, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/darwin-arm64/develop-e5c7116eff4f1f62b6328670d147c1734b9108ec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e5c7116 Aug 29, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/darwin-x64/develop-e5c7116eff4f1f62b6328670d147c1734b9108ec/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e5c7116 Aug 29, 2023

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.0.0/linux-arm64/develop-e5c7116eff4f1f62b6328670d147c1734b9108ec/cypress.tgz

Please sign in to comment.