allow disabling

This commit is contained in:
Simon Knott 2024-11-06 14:11:48 +01:00
parent 9480b7cdfd
commit 8c341d1499
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 46 additions and 27 deletions

View file

@ -108,6 +108,9 @@ export class WebServerPlugin implements TestRunnerPlugin {
if (process.platform === 'win32')
throw new Error('Graceful shutdown is not supported on Windows');
if (this._options.shutdownTimeout === 0)
throw new Error('skip graceful shutdown');
const success = launchedProcess.kill('SIGINT');
if (!success)
throw new Error(`SIGINT didn't succeed, fall back to non-graceful shutdown`);

View file

@ -745,12 +745,12 @@ test('should forward stdout when set to "pipe" before server is ready', async ({
expect(result.output).not.toContain('Timed out waiting 3000ms');
});
test('should gracefully kill server', async ({ interactWithTestRunner }, { workerIndex }) => {
test.describe('graceful shutdown', () => {
test.skip(process.platform === 'win32', 'No sending SIGINT on Windows');
const port = workerIndex * 2 + 10510;
const testProcess = await interactWithTestRunner({
const files = (additionalOptions = {}) => {
const port = test.info().workerIndex * 2 + 10510;
return {
'web-server.js': `
process.on('SIGINT', () => { console.log('%%webserver received SIGINT but stubbornly refuses to wind down') })
const server = require('http').createServer((req, res) => { res.end("ok"); })
@ -767,14 +767,30 @@ test('should gracefully kill server', async ({ interactWithTestRunner }, { worke
port: ${port},
stdout: 'pipe',
timeout: 3000,
...${JSON.stringify(additionalOptions)}
},
};
`,
}, { workers: 1 });
};
};
test('sends SIGINT by default', async ({ interactWithTestRunner }) => {
const testProcess = await interactWithTestRunner(files(), { workers: 1 });
await testProcess.waitForOutput('webserver started');
process.kill(testProcess.process.pid!, 'SIGINT');
await testProcess.exited;
expect(testProcess.outputLines({ prefix: '[WebServer] ' })).toEqual(['webserver received SIGINT but stubbornly refuses to wind down']);
});
test('can be disabled', async ({ interactWithTestRunner }) => {
const testProcess = await interactWithTestRunner(files({ shutdownTimeout: 0 }), { workers: 1 });
await testProcess.waitForOutput('webserver started');
process.kill(testProcess.process.pid!, 'SIGINT');
await testProcess.exited;
expect(testProcess.outputLines({ prefix: '[WebServer] ' })).toEqual([]);
});
});