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 running tests outside Vite project root folder #25801

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->

## 12.6.1

_Released 03/1/2023 (PENDING)_
Expand All @@ -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:**

Expand Down
8 changes: 6 additions & 2 deletions npm/vite-dev-server/client/initCypressTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like @fs is a Vite thing - I couldn't find much documentation outside of https://vitejs.dev/config/server-options.html#server-fs-allow.

I'll update the snapshots - I don't know if this breaks anything, but I always thought the src/src duplication was kind of weird.

/* 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) {
Expand Down
8 changes: 4 additions & 4 deletions system-tests/__snapshots__/vite_dev_server_fresh_spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down