Skip to content

Commit 53fd537

Browse files
authored
fix(cypress/webpack-dev-server): correct path for indexHtmlFile (#27320)
* fix: correct path for indexHtmlt * changelog
1 parent 14a7416 commit 53fd537

File tree

8 files changed

+3247
-1
lines changed

8 files changed

+3247
-1
lines changed

cli/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ _Released 07/20/2023_
2020
- 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).
2121
- 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).
2222
- Fixed an issue where web workers could not be created within a spec. Fixes [#27298](https://github.com/cypress-io/cypress/issues/27298).
23+
- 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).
2324

2425
## 12.17.1
2526

npm/webpack-dev-server/cypress/e2e/webpack-dev-server.cy.ts

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ describe('Config options', () => {
1212
cy.get('.passed > .num').should('contain', 1)
1313
})
1414

15+
it('supports nested config', () => {
16+
cy.scaffoldProject('webpack-react-nested-config')
17+
cy.openProject('webpack-react-nested-config', ['--config-file', 'cypress/cypress.config.js'])
18+
cy.startAppServer('component')
19+
20+
cy.visitApp()
21+
cy.contains('foo.cy.js').click()
22+
cy.waitForSpecToFinish()
23+
cy.get('.passed > .num').should('contain', 1)
24+
})
25+
1526
it('supports @cypress/webpack-dev-server', () => {
1627
cy.scaffoldProject('webpack5_wds4-react')
1728
cy.openProject('webpack5_wds4-react', ['--config-file', 'cypress-webpack-dev-server-function.config.ts'])

npm/webpack-dev-server/src/makeDefaultWebpackConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function makeCypressWebpackConfig (
7878
},
7979
plugins: [
8080
new (HtmlWebpackPlugin as typeof import('html-webpack-plugin-5'))({
81-
template: indexHtmlFile,
81+
template: indexHtmlFile ? path.join(projectRoot, indexHtmlFile) : undefined,
8282
// Angular generates all of it's scripts with <script type="module">. Live-reloading breaks without this option.
8383
// We need to manually set the base here to `/__cypress/src/` so that static assets load with our proxy
8484
...(framework === 'angular' ? { scriptLoading: 'module', base: '/__cypress/src/' } : {}),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { devServer } = require('@cypress/webpack-dev-server')
2+
3+
module.exports = {
4+
component: {
5+
supportFile: false,
6+
devServer: (args) => {
7+
return devServer({ ...args, webpackConfig: {} })
8+
},
9+
},
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<div data-cy-root></div>
10+
</body>
11+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"devDependencies": {
3+
"@cypress/webpack-dev-server": "file:../../../npm/webpack-dev-server",
4+
"webpack": "^5",
5+
"webpack-dev-server": "^4"
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it('renders hello world', () => {
2+
expect(1).to.eq(1)
3+
})

system-tests/projects/webpack-react-nested-config/yarn.lock

+3,203
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)