diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 81d87119a487..791b474e4e84 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,4 +1,5 @@ + ## 12.6.1 _Released 03/1/2023 (PENDING)_ @@ -7,6 +8,7 @@ _Released 03/1/2023 (PENDING)_ - Fixed an issue where cookies were being duplicated with the same hostname, but a prepended dot. Fixed an issue where cookies may not be expiring correctly. Fixes [#25174](https://github.com/cypress-io/cypress/issues/25174), [#25205](https://github.com/cypress-io/cypress/issues/25205) and [#25495](https://github.com/cypress-io/cypress/issues/25495). - Added missing TypeScript type definitions for the [`cy.reload()`](https://docs.cypress.io/api/commands/reload) command. Addressed in [#25779](https://github.com/cypress-io/cypress/pull/25779). +- Fix a bug where files outside the project root in a monorepo are not correctly served when using Vite. Addressed in [#25801](https://github.com/cypress-io/cypress/pull/25801) **Misc:** diff --git a/npm/vite-dev-server/client/initCypressTests.js b/npm/vite-dev-server/client/initCypressTests.js index 4406c9ab636d..57b983ca8fd2 100644 --- a/npm/vite-dev-server/client/initCypressTests.js +++ b/npm/vite-dev-server/client/initCypressTests.js @@ -32,13 +32,17 @@ if (supportFile) { }) } +// Using relative path wouldn't allow to load tests outside Vite project root folder +// So we use the "@fs" bit to load the test file using its absolute path +const testFileAbsolutePathRoute = `${devServerPublicPathRoute}/@fs${CypressInstance.spec.absolute}` + /* Spec file import logic */ // We need a slash before /src/my-spec.js, this does not happen by default. importsToLoad.push({ - load: () => import(`${devServerPublicPathRoute}/${CypressInstance.spec.relative}`), + load: () => import(testFileAbsolutePathRoute), absolute: CypressInstance.spec.absolute, relative: CypressInstance.spec.relative, - relativeUrl: `${devServerPublicPathRoute}/${CypressInstance.spec.relative}`, + relativeUrl: testFileAbsolutePathRoute, }) if (!CypressInstance) { diff --git a/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js b/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js index 8931e848a97c..d115d4b88dc6 100644 --- a/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js +++ b/system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js @@ -60,7 +60,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite4.0.4- 1) An uncaught error was detected outside of a test: TypeError: The following error originated from your test code, not from Cypress. - > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/src/AppCompilationError.cy.jsx + > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/@fs/foo/bar/.projects/vite4.0.4-react/src/AppCompilationError.cy.jsx When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. @@ -499,7 +499,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.8.6- 1) An uncaught error was detected outside of a test: TypeError: The following error originated from your test code, not from Cypress. - > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/src/AppCompilationError.cy.jsx + > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/@fs/foo/bar/.projects/vite2.8.6-react/src/AppCompilationError.cy.jsx When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. @@ -938,7 +938,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite2.9.1- 1) An uncaught error was detected outside of a test: TypeError: The following error originated from your test code, not from Cypress. - > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/src/AppCompilationError.cy.jsx + > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/@fs/foo/bar/.projects/vite2.9.1-react/src/AppCompilationError.cy.jsx When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. @@ -1377,7 +1377,7 @@ exports['@cypress/vite-dev-server react executes all of the tests for vite3.0.2- 1) An uncaught error was detected outside of a test: TypeError: The following error originated from your test code, not from Cypress. - > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/src/AppCompilationError.cy.jsx + > Failed to fetch dynamically imported module: http://localhost:xxxx/__cypress/src/@fs/foo/bar/.projects/vite3.0.2-react/src/AppCompilationError.cy.jsx When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.