allow disabling
This commit is contained in:
parent
9480b7cdfd
commit
8c341d1499
|
|
@ -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`);
|
||||
|
|
|
|||
|
|
@ -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([]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue