Skip to content

Commit

Permalink
test(e2e): improve onExit test case (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Aug 1, 2024
1 parent 87600a7 commit f946b7d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions e2e/cases/plugin-api/plugin-on-exit-hook/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@ const distFile = path.join(__dirname, 'node_modules/hooksTempFile');
rspackOnlyTest('should run onExit hook before process exit', async () => {
fs.rmSync(distFile, { force: true });

await new Promise<void>((resolve) => {
const process = exec('node ./run.mjs', { cwd: __dirname }, () => {
expect(fs.readFileSync(distFile, 'utf-8')).toEqual('1');
resolve();
await new Promise<void>((resolve, reject) => {
const timeoutId = setTimeout(() => {
process.kill();
reject(new Error('Process timeout'));
}, 3000);

const process = exec('node ./run.mjs', { cwd: __dirname }, (error) => {
if (error) {
clearTimeout(timeoutId);
reject(error);
return;
}

try {
expect(fs.readFileSync(distFile, 'utf-8')).toEqual('1');
clearTimeout(timeoutId);
resolve();
} catch (err) {
clearTimeout(timeoutId);
reject(err);
}
});
});
});

0 comments on commit f946b7d

Please sign in to comment.