Skip to content

Commit

Permalink
force relative pathing wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker committed May 15, 2024
1 parent 8a913dd commit 2777140
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions npm/vite-dev-server/client/initCypressTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const supportFile = CypressInstance.config('supportFile')
const projectRoot = CypressInstance.config('projectRoot')
const devServerPublicPathRoute = CypressInstance.config('devServerPublicPathRoute')

let devServerPublicPathBase = devServerPublicPathRoute

if (devServerPublicPathRoute === '') {
devServerPublicPathBase = '.'
}

if (supportFile) {
let supportRelativeToProjectRoot = supportFile.replace(projectRoot, '')

Expand All @@ -22,21 +28,26 @@ if (supportFile) {
supportRelativeToProjectRoot = supportFile.replace(platformProjectRoot, '')
}

// We need a slash before /cypress/supportFile.js, this happens by default
// with the current string replacement logic.
// path lookups are done with unix style operators. Not replacing ha
supportRelativeToProjectRoot = supportRelativeToProjectRoot.replaceAll('\\', '/')

// We need a slash before /cypress/supportFile.js if the devServerPublicPathRoute is populated, this happens by default
// with the current string replacement logic. Otherwise, we need to specify the relative path to look up if devServerPublicPathRoute
// if not defined as it would be in the base directory

importsToLoad.push({
load: () => import(`${devServerPublicPathRoute}${supportRelativeToProjectRoot}`),
load: () => import(`${devServerPublicPathBase}${supportRelativeToProjectRoot}`),
absolute: supportFile,
relative: supportRelativeToProjectRoot,
relativeUrl: `${devServerPublicPathRoute}${supportRelativeToProjectRoot}`,
relativeUrl: `${devServerPublicPathBase}${supportRelativeToProjectRoot}`,
})
}

// 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
// Normalize path to not include a leading slash (different on Win32 vs Unix)
const normalizedAbsolutePath = CypressInstance.spec.absolute.replace(/^\//, '')
const testFileAbsolutePathRoute = `${devServerPublicPathRoute}/@fs/${normalizedAbsolutePath}`
const testFileAbsolutePathRoute = `${devServerPublicPathBase}/@fs/${normalizedAbsolutePath}`

/* Spec file import logic */
// We need a slash before /src/my-spec.js, this does not happen by default.
Expand Down

0 comments on commit 2777140

Please sign in to comment.