From 1433b64d25f186774471593892c1c03aa954c4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20Ledoux?= Date: Sun, 25 Jul 2021 20:52:59 -0500 Subject: [PATCH] fix: only rerun if current spec+deps changed (#17269) Co-authored-by: Lachlan Miller --- npm/vite-dev-server/src/makeCypressPlugin.ts | 2 +- packages/runner-shared/src/event-manager.js | 6 ++++++ packages/server-ct/src/socket-ct.ts | 4 ++-- packages/server/lib/plugins/child/dev-server.js | 4 ++-- packages/server/lib/plugins/dev-server.js | 4 ++-- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/npm/vite-dev-server/src/makeCypressPlugin.ts b/npm/vite-dev-server/src/makeCypressPlugin.ts index 8393d01281be..ff791dfd5c38 100644 --- a/npm/vite-dev-server/src/makeCypressPlugin.ts +++ b/npm/vite-dev-server/src/makeCypressPlugin.ts @@ -103,7 +103,7 @@ export const makeCypressPlugin = ( for (const mod of moduleImporters.values()) { if (specsPathsSet.has(mod.file)) { debug('handleHotUpdate - compile success') - devServerEvents.emit('dev-server:compile:success') + devServerEvents.emit('dev-server:compile:success', { specFile: mod.file }) return [] } diff --git a/packages/runner-shared/src/event-manager.js b/packages/runner-shared/src/event-manager.js index 6cce44751a83..775dac63d480 100644 --- a/packages/runner-shared/src/event-manager.js +++ b/packages/runner-shared/src/event-manager.js @@ -113,6 +113,12 @@ export const eventManager = { localBus.emit('script:error', error) }) + ws.on('dev-server:compile:success', ({ specFile }) => { + if (!specFile || specFile === state.spec.absolute) { + rerun() + } + }) + _.each(socketRerunEvents, (event) => { ws.on(event, rerun) }) diff --git a/packages/server-ct/src/socket-ct.ts b/packages/server-ct/src/socket-ct.ts index 88be652b903f..b21406ab631d 100644 --- a/packages/server-ct/src/socket-ct.ts +++ b/packages/server-ct/src/socket-ct.ts @@ -16,8 +16,8 @@ export class SocketCt extends SocketBase { // should we use this option at all for component testing 😕? if (config.watchForFileChanges) { - devServer.emitter.on('dev-server:compile:success', () => { - this.toRunner('runner:restart') + devServer.emitter.on('dev-server:compile:success', ({ specFile }) => { + this.toRunner('dev-server:compile:success', { specFile }) }) } } diff --git a/packages/server/lib/plugins/child/dev-server.js b/packages/server/lib/plugins/child/dev-server.js index 47fe56d34939..2d8d140022f1 100644 --- a/packages/server/lib/plugins/child/dev-server.js +++ b/packages/server/lib/plugins/child/dev-server.js @@ -12,8 +12,8 @@ const wrap = (ipc, invoke, ids, [options]) => { ipc.send('dev-server:compile:error', error) }) - devServerEvents.on('dev-server:compile:success', () => { - ipc.send('dev-server:compile:success') + devServerEvents.on('dev-server:compile:success', ({ specFile } = {}) => { + ipc.send('dev-server:compile:success', { specFile }) }) options.devServerEvents = devServerEvents diff --git a/packages/server/lib/plugins/dev-server.js b/packages/server/lib/plugins/dev-server.js index 194b626d1e0f..385e1b1bb89e 100644 --- a/packages/server/lib/plugins/dev-server.js +++ b/packages/server/lib/plugins/dev-server.js @@ -16,8 +16,8 @@ plugins.registerHandler((ipc) => { baseEmitter.emit('dev-server:compile:error', error) }) - ipc.on('dev-server:compile:success', () => { - baseEmitter.emit('dev-server:compile:success') + ipc.on('dev-server:compile:success', ({ specFile } = {}) => { + baseEmitter.emit('dev-server:compile:success', { specFile }) }) return baseEmitter.on('dev-server:close', () => {