playwright/tests/playwright-test/assets/simple-server-with-ready-route.js
divdavem 512a245f13
feat(test-runner): wait for a url before starting tests (#10138)
The webServer configuration in @playwright/test now accepts a url as an
alternative to a port number to wait for a url to return a 2xx status code.
2022-01-26 16:32:58 -08:00

16 lines
469 B
JavaScript

const { TestServer } = require('../../../utils/testserver/');
TestServer.create(__dirname, process.argv[2] || 3000).then(server => {
console.log('listening on port', server.PORT);
let ready = false;
setTimeout(() => ready = true, 750);
server.setRoute('/ready', (message, response) => {
if (ready) {
response.statusCode = 200;
response.end('hello');
} else {
response.statusCode = 404;
response.end('not-ready');
}
});
});