From 53fd537a0486caedc7faccacff7c6433ebc2601f Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 4 Aug 2023 14:54:38 +1000 Subject: [PATCH] fix(cypress/webpack-dev-server): correct path for `indexHtmlFile` (#27320) * fix: correct path for indexHtmlt * changelog --- cli/CHANGELOG.md | 1 + .../cypress/e2e/webpack-dev-server.cy.ts | 11 + .../src/makeDefaultWebpackConfig.ts | 2 +- .../cypress/cypress.config.js | 10 + .../cypress/support/component-index.html | 11 + .../webpack-react-nested-config/package.json | 7 + .../webpack-react-nested-config/src/foo.cy.js | 3 + .../webpack-react-nested-config/yarn.lock | 3203 +++++++++++++++++ 8 files changed, 3247 insertions(+), 1 deletion(-) create mode 100644 system-tests/projects/webpack-react-nested-config/cypress/cypress.config.js create mode 100644 system-tests/projects/webpack-react-nested-config/cypress/support/component-index.html create mode 100644 system-tests/projects/webpack-react-nested-config/package.json create mode 100644 system-tests/projects/webpack-react-nested-config/src/foo.cy.js create mode 100644 system-tests/projects/webpack-react-nested-config/yarn.lock diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 4940e8fcf5..70ef0e7fb2 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -20,6 +20,7 @@ _Released 07/20/2023_ - Fixed an issue where commands would fail with the error `must only be invoked from the spec file or support file` if their arguments were mutated. Fixes [#27200](https://github.com/cypress-io/cypress/issues/27200). - Fixed an issue where `cy.writeFile()` would erroneously fail with the error `cy.writeFile() must only be invoked from the spec file or support file`. Fixes [#27097](https://github.com/cypress-io/cypress/issues/27097). - Fixed an issue where web workers could not be created within a spec. Fixes [#27298](https://github.com/cypress-io/cypress/issues/27298). +- Fixed an issue where having `cypress.config` in a nested directory would cause problems with locating the `component-index.html` file when using component testing. Fixes [#26400](https://github.com/cypress-io/cypress/issues/26400). ## 12.17.1 diff --git a/npm/webpack-dev-server/cypress/e2e/webpack-dev-server.cy.ts b/npm/webpack-dev-server/cypress/e2e/webpack-dev-server.cy.ts index 06e85369ea..a5585a2c65 100644 --- a/npm/webpack-dev-server/cypress/e2e/webpack-dev-server.cy.ts +++ b/npm/webpack-dev-server/cypress/e2e/webpack-dev-server.cy.ts @@ -12,6 +12,17 @@ describe('Config options', () => { cy.get('.passed > .num').should('contain', 1) }) + it('supports nested config', () => { + cy.scaffoldProject('webpack-react-nested-config') + cy.openProject('webpack-react-nested-config', ['--config-file', 'cypress/cypress.config.js']) + cy.startAppServer('component') + + cy.visitApp() + cy.contains('foo.cy.js').click() + cy.waitForSpecToFinish() + cy.get('.passed > .num').should('contain', 1) + }) + 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']) diff --git a/npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts b/npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts index e251968c59..a942f89b21 100644 --- a/npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts +++ b/npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts @@ -78,7 +78,7 @@ export function makeCypressWebpackConfig ( }, plugins: [ new (HtmlWebpackPlugin as typeof import('html-webpack-plugin-5'))({ - template: indexHtmlFile, + template: indexHtmlFile ? path.join(projectRoot, indexHtmlFile) : undefined, // Angular generates all of it's scripts with