mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
fix(test-runner): toHaveURL respect baseURL (#9050)
This commit is contained in:
parent
9b0e0c2273
commit
f9c5279c3a
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
import { Locator, Page } from '../../..';
|
import { Locator, Page } from '../../..';
|
||||||
import { constructURLBasedOnBaseURL, isString } from '../../utils/utils';
|
import { constructURLBasedOnBaseURL, isString } from '../../utils/utils';
|
||||||
import { currentTestInfo } from '../globals';
|
|
||||||
import type { Expect } from '../types';
|
import type { Expect } from '../types';
|
||||||
import { toBeTruthy } from './toBeTruthy';
|
import { toBeTruthy } from './toBeTruthy';
|
||||||
import { toEqual } from './toEqual';
|
import { toEqual } from './toEqual';
|
||||||
@ -239,10 +238,7 @@ export function toHaveURL(
|
|||||||
expected: string | RegExp,
|
expected: string | RegExp,
|
||||||
options?: { timeout?: number },
|
options?: { timeout?: number },
|
||||||
) {
|
) {
|
||||||
const testInfo = currentTestInfo();
|
const baseURL = (page.context() as any)._options.baseURL;
|
||||||
if (!testInfo)
|
|
||||||
throw new Error(`toHaveURL must be called during the test`);
|
|
||||||
const baseURL = testInfo.project.use.baseURL;
|
|
||||||
|
|
||||||
return toMatchText.call(this, 'toHaveURL', page, 'Page', async () => {
|
return toMatchText.call(this, 'toHaveURL', page, 'Page', async () => {
|
||||||
return page.url();
|
return page.url();
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import http from 'http';
|
import path from 'path';
|
||||||
import { test, expect, stripAscii } from './playwright-test-fixtures';
|
import { test, expect, stripAscii } from './playwright-test-fixtures';
|
||||||
|
|
||||||
test('should support toHaveCount', async ({ runInlineTest }) => {
|
test('should support toHaveCount', async ({ runInlineTest }) => {
|
||||||
@ -166,12 +166,8 @@ test('should support toHaveURL', async ({ runInlineTest }) => {
|
|||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should support toHaveURL with baseURL', async ({ runInlineTest }, testInfo) => {
|
test('should support toHaveURL with baseURL from webServer', async ({ runInlineTest }, testInfo) => {
|
||||||
const port = testInfo.workerIndex + 10500;
|
const port = testInfo.workerIndex + 10500;
|
||||||
const server = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => {
|
|
||||||
res.end('<html><body>hello</body></html>');
|
|
||||||
});
|
|
||||||
await new Promise(resolve => server.listen(port, resolve));
|
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
const { test } = pwt;
|
const { test } = pwt;
|
||||||
@ -189,9 +185,10 @@ test('should support toHaveURL with baseURL', async ({ runInlineTest }, testInfo
|
|||||||
`,
|
`,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
use: {
|
webServer: {
|
||||||
baseURL: 'http://localhost:${port}',
|
command: 'node ${JSON.stringify(path.join(__dirname, 'assets', 'simple-server.js'))} ${port}',
|
||||||
}
|
port: ${port},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
`,
|
`,
|
||||||
}, { workers: 1 });
|
}, { workers: 1 });
|
||||||
@ -201,7 +198,6 @@ test('should support toHaveURL with baseURL', async ({ runInlineTest }, testInfo
|
|||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
expect(result.failed).toBe(1);
|
expect(result.failed).toBe(1);
|
||||||
expect(result.exitCode).toBe(1);
|
expect(result.exitCode).toBe(1);
|
||||||
await new Promise(resolve => server.close(resolve));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should support respect expect.timeout', async ({ runInlineTest }) => {
|
test('should support respect expect.timeout', async ({ runInlineTest }) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user