feat(server): consider 3XX, 400-403 responses as started server

This commit is contained in:
Pavel Feldman 2022-06-10 13:47:29 -08:00 committed by GitHub
parent 7c0bff15ca
commit 30f3d526eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -153,7 +153,7 @@ async function isURLAvailable(url: URL, ignoreHTTPSErrors: boolean, onStdErr: Re
indexUrl.pathname = '/index.html';
statusCode = await httpStatusCode(indexUrl, ignoreHTTPSErrors, onStdErr);
}
return statusCode >= 200 && statusCode < 300;
return statusCode >= 200 && statusCode < 404;
}
async function httpStatusCode(url: URL, ignoreHTTPSErrors: boolean, onStdErr: Reporter['onStdErr']): Promise<number> {

View File

@ -13,5 +13,9 @@ setTimeout(() => {
server.setRoute('/port', (_, response) => {
response.end('' + server.PORT);
});
server.setRoute('/redirect', (_, response) => {
response.writeHead(301, 'Moved');
response.end();
});
});
}, process.argv[3] ? +process.argv[3] : 0);

View File

@ -546,3 +546,26 @@ test.describe('baseURL with plugins', () => {
expect(result.passed).toBe(1);
});
});
test('should treat 3XX as available server', async ({ runInlineTest }, { workerIndex }) => {
const port = workerIndex + 10500;
const result = await runInlineTest({
'test.spec.ts': `
const { test } = pwt;
test('pass', async ({}) => {});
`,
'playwright.config.ts': `
module.exports = {
webServer: {
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${port}',
url: 'http://localhost:${port}/redirect',
}
};
`,
}, {}, { DEBUG: 'pw:webserver' });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
expect(result.output).toContain('[WebServer] listening');
expect(result.output).toContain('[WebServer] error from server');
});