Skip to content

Commit

Permalink
fix(screenshot): reject pixel match process on exit (#5167)
Browse files Browse the repository at this point in the history
refs #4866
STENCIL-962
  • Loading branch information
christian-bromann committed Dec 13, 2023
1 parent f6903a8 commit c2ee40d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/screenshot/screenshot-compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ async function getMismatchedPixels(pixelmatchModulePath: string, pixelMatchInput
}, timeout);

try {
let error: string | undefined;
const filteredExecArgs = process.execArgv.filter((v) => !/^--(debug|inspect)/.test(v));

const options = {
Expand All @@ -168,6 +169,25 @@ async function getMismatchedPixels(pixelmatchModulePath: string, pixelMatchInput
reject(err);
});

pixelMatchProcess.stderr.on('data', (data) => {
error = data.toString();
});

/**
* Make sure we reject the promise if the process exits due to an error
* or prematurely for some other reason. Note that in order to resolve
* the promise we expect a message to be sent containing information about
* the mismatched pixels.
*/
pixelMatchProcess.on('exit', (code) => {
clearTimeout(tmr);
const exitError =
code === 0
? new Error('Pixelmatch process exited unexpectedly')
: new Error(`Pixelmatch process exited with code ${code}: ${error || 'unknown error'}`);
return reject(exitError);
});

pixelMatchProcess.send(pixelMatchInput);
} catch (e) {
clearTimeout(tmr);
Expand Down

0 comments on commit c2ee40d

Please sign in to comment.