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: reload every spec file when support updated #17598

Merged
merged 1 commit into from
Aug 4, 2021
Merged
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
19 changes: 12 additions & 7 deletions npm/vite-dev-server/src/makeCypressPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ const INIT_FILEPATH = resolve(__dirname, '../client/initCypressTests.js')

const HMR_DEPENDENCY_LOOKUP_MAX_ITERATION = 50

function getSpecsPathsSet (specs: Spec[], supportFile?: string | null) {
function getSpecsPathsSet (specs: Spec[]) {
return new Set<string>(
supportFile
? [...specs.map((spec) => spec.absolute), supportFile]
: specs.map((spec) => spec.absolute),
specs.map((spec) => spec.absolute),
)
}

Expand All @@ -42,10 +40,10 @@ export const makeCypressPlugin = (
): Plugin => {
let base = '/'

let specsPathsSet = getSpecsPathsSet(specs, supportFilePath)
let specsPathsSet = getSpecsPathsSet(specs)

devServerEvents.on('dev-server:specs:changed', (specs: Spec[]) => {
specsPathsSet = getSpecsPathsSet(specs, supportFilePath)
specsPathsSet = getSpecsPathsSet(specs)
})

const posixSupportFilePath = supportFilePath ? convertPathToPosix(resolve(projectRoot, supportFilePath)) : undefined
Expand Down Expand Up @@ -106,8 +104,15 @@ export const makeCypressPlugin = (
// as soon as we find one of the specs, we trigger the re-run of tests
for (const mod of moduleImporters.values()) {
debug('handleHotUpdate - mod.file', mod.file)
if (mod.file === supportFilePath) {
debug('handleHotUpdate - support compile success')
devServerEvents.emit('dev-server:compile:success')

return []
}

if (mod.file && specsPathsSet.has(mod.file)) {
debug('handleHotUpdate - compile success')
debug('handleHotUpdate - spec compile success', mod.file)
devServerEvents.emit('dev-server:compile:success', { specFile: mod.file })

return []
Expand Down