Skip to content

Commit

Permalink
fix: reload every spec file when support updated (#17598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barthélémy Ledoux authored Aug 4, 2021
1 parent ab35d0f commit efc38b6
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit efc38b6

Please sign in to comment.