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