From efc38b67497b48db5b3a636acac3be45dd930593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20Ledoux?= Date: Wed, 4 Aug 2021 12:14:13 -0500 Subject: [PATCH] fix: reload every spec file when support updated (#17598) --- npm/vite-dev-server/src/makeCypressPlugin.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/npm/vite-dev-server/src/makeCypressPlugin.ts b/npm/vite-dev-server/src/makeCypressPlugin.ts index 5b908253cabd..de369b018b6e 100644 --- a/npm/vite-dev-server/src/makeCypressPlugin.ts +++ b/npm/vite-dev-server/src/makeCypressPlugin.ts @@ -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( - supportFile - ? [...specs.map((spec) => spec.absolute), supportFile] - : specs.map((spec) => spec.absolute), + specs.map((spec) => spec.absolute), ) } @@ -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 @@ -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 []