This PR cherry-picks the following commits:
- bd698efaef
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
ce33ec23c7
commit
cb419e75cd
|
|
@ -595,7 +595,7 @@ export default defineConfig({
|
||||||
- type: ?<[Object]|[Array]<[Object]>>
|
- type: ?<[Object]|[Array]<[Object]>>
|
||||||
- `command` <[string]> Shell command to start. For example `npm run start`..
|
- `command` <[string]> Shell command to start. For example `npm run start`..
|
||||||
- `port` ?<[int]> The port that your http server is expected to appear on. It does wait until it accepts connections. Exactly one of `port` or `url` is required.
|
- `port` ?<[int]> The port that your http server is expected to appear on. It does wait until it accepts connections. Exactly one of `port` or `url` is required.
|
||||||
- `url` ?<[string]> The url on your http server that is expected to return a 2xx, 3xx, 400, 401, 402, or 403 status code when the server is ready to accept connections. Exactly one of `port` or `url` is required.
|
- `url` ?<[string]> The url on your http server that is expected to return a 2xx, 3xx, 400, 401, 402, or 403 status code when the server is ready to accept connections. Redirects (3xx status codes) are being followed and the new location is checked. Exactly one of `port` or `url` is required.
|
||||||
- `ignoreHTTPSErrors` ?<[boolean]> Whether to ignore HTTPS errors when fetching the `url`. Defaults to `false`.
|
- `ignoreHTTPSErrors` ?<[boolean]> Whether to ignore HTTPS errors when fetching the `url`. Defaults to `false`.
|
||||||
- `timeout` ?<[int]> How long to wait for the process to start up and be available in milliseconds. Defaults to 60000.
|
- `timeout` ?<[int]> How long to wait for the process to start up and be available in milliseconds. Defaults to 60000.
|
||||||
- `reuseExistingServer` ?<[boolean]> If true, it will re-use an existing server on the `port` or `url` when available. If no server is running on that `port` or `url`, it will run the command to start a new server. If `false`, it will throw if an existing process is listening on the `port` or `url`. This should be commonly set to `!process.env.CI` to allow the local dev server when running tests locally.
|
- `reuseExistingServer` ?<[boolean]> If true, it will re-use an existing server on the `port` or `url` when available. If no server is running on that `port` or `url`, it will run the command to start a new server. If `false`, it will throw if an existing process is listening on the `port` or `url`. This should be commonly set to `!process.env.CI` to allow the local dev server when running tests locally.
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ export function httpRequest(params: HTTPRequestParams, onResponse: (r: http.Inco
|
||||||
const requestCallback = (res: http.IncomingMessage) => {
|
const requestCallback = (res: http.IncomingMessage) => {
|
||||||
const statusCode = res.statusCode || 0;
|
const statusCode = res.statusCode || 0;
|
||||||
if (statusCode >= 300 && statusCode < 400 && res.headers.location)
|
if (statusCode >= 300 && statusCode < 400 && res.headers.location)
|
||||||
httpRequest({ ...params, url: res.headers.location }, onResponse, onError);
|
httpRequest({ ...params, url: new URL.URL(res.headers.location, params.url).toString() }, onResponse, onError);
|
||||||
else
|
else
|
||||||
onResponse(res);
|
onResponse(res);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
3
packages/playwright-test/types/test.d.ts
vendored
3
packages/playwright-test/types/test.d.ts
vendored
|
|
@ -5887,7 +5887,8 @@ interface TestConfigWebServer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The url on your http server that is expected to return a 2xx, 3xx, 400, 401, 402, or 403 status code when the
|
* The url on your http server that is expected to return a 2xx, 3xx, 400, 401, 402, or 403 status code when the
|
||||||
* server is ready to accept connections. Exactly one of `port` or `url` is required.
|
* server is ready to accept connections. Redirects (3xx status codes) are being followed and the new location is
|
||||||
|
* checked. Exactly one of `port` or `url` is required.
|
||||||
*/
|
*/
|
||||||
url?: string;
|
url?: string;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -457,6 +457,32 @@ test('should send Accept header', async ({ runInlineTest, server }) => {
|
||||||
expect(acceptHeader).toBe('*/*');
|
expect(acceptHeader).toBe('*/*');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should follow redirects', async ({ runInlineTest, server }) => {
|
||||||
|
server.setRedirect('/redirect', '/redirected-to');
|
||||||
|
server.setRoute('/redirected-to', (req, res) => {
|
||||||
|
res.end('<html><body>hello</body></html>');
|
||||||
|
});
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'test.spec.ts': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('connect to the server', async ({baseURL, page}) => {
|
||||||
|
await page.goto('http://localhost:${server.PORT}/redirect');
|
||||||
|
expect(await page.textContent('body')).toBe('hello');
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
'playwright.config.ts': `
|
||||||
|
module.exports = {
|
||||||
|
webServer: {
|
||||||
|
command: 'node ${JSON.stringify(SIMPLE_SERVER_PATH)} ${server.PORT}',
|
||||||
|
url: 'http://localhost:${server.PORT}/redirect',
|
||||||
|
reuseExistingServer: true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
test('should create multiple servers', async ({ runInlineTest }, { workerIndex }) => {
|
test('should create multiple servers', async ({ runInlineTest }, { workerIndex }) => {
|
||||||
const port = workerIndex * 2 + 10500;
|
const port = workerIndex * 2 + 10500;
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue