Skip to content

Commit

Permalink
fix(middleware-code-coverage): kill subprocess and remove shell
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Sep 11, 2023
1 parent fde88d8 commit e9cd25d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/middleware-code-coverage/test/integration/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const globalCoverageMap = {

function exec(command, args=[]) {
return execa(command, args, {
shell: true,
cwd: path.join(__dirname, "fixtures", "ui5-app")
})
.pipeStdout(process.stdout)
Expand All @@ -73,13 +72,16 @@ function exec(command, args=[]) {

function setup() {
if (!install) {
install = exec("npm i --install-links=false");
install = exec("npm", ["i", "--install-links=false"]);
}
return install;
}

function startUI5Server(configPath, port) {
const child = exec("npm start", ["--", "--config", configPath, "--port", port]);
// Starting the app this way would allow us to directly kill the "ui5 serve".
// Using App's 'npm start' script would require config to be passed with -- to the underlying 'ui5 serve'
// this would start a (detached) subprocess and that would require more efforts to find and kill it.
const child = exec("./node_modules/@ui5/cli/bin/ui5.cjs", ["serve", "--config", configPath, "--port", port]);

return new Promise( (resolve, reject) => {
const onError = (errMessage = "Start of UI5 Server failed.") => {
Expand Down Expand Up @@ -114,8 +116,9 @@ async function startUI5App(config = "./ui5.yaml") {
}

function endUI5App(proc) {
proc.stdout.pause();
proc.kill();
// Magic number! A (random) timeout to forcefully try to kill the process
const forceKillAfterTimeout = 200;
proc.kill("SIGKILL", {forceKillAfterTimeout}); // SIGKILL kills the process immediately
}

test.before(async (t) => {
Expand Down

0 comments on commit e9cd25d

Please sign in to comment.