From c7e1a1681e62abb00ea1a4f6aa5d41595efb81b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Wed, 24 Jul 2024 21:48:59 +0200 Subject: [PATCH] fix(testing): use taskkill to kill web server process when running cypress on windows (#27068) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes #26599 --- packages/cypress/plugins/cypress-preset.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/cypress/plugins/cypress-preset.ts b/packages/cypress/plugins/cypress-preset.ts index 31ee3da34f..95879c1730 100644 --- a/packages/cypress/plugins/cypress-preset.ts +++ b/packages/cypress/plugins/cypress-preset.ts @@ -1,11 +1,11 @@ import { workspaceRoot } from '@nx/devkit'; import { dirname, join, relative } from 'path'; -import { existsSync, lstatSync } from 'fs'; +import { lstatSync } from 'fs'; import vitePreprocessor from '../src/plugins/preprocessor-vite'; import { NX_PLUGIN_OPTIONS } from '../src/utils/constants'; -import { spawn } from 'child_process'; +import { execSync, spawn } from 'child_process'; import { request as httpRequest } from 'http'; import { request as httpsRequest } from 'https'; import type { InlineConfig } from 'vite'; @@ -82,7 +82,13 @@ function startWebServer(webServerCommand: string) { return () => { if (process.platform === 'win32') { - serverProcess.kill(); + try { + execSync('taskkill /pid ' + serverProcess.pid + ' /T /F'); + } catch (e) { + if (process.env.NX_VERBOSE_LOGGING === 'true') { + console.error(e); + } + } } else { // child.kill() does not work on linux // process.kill will kill the whole process group on unix