fix :: fix test code be foucsed on location
This commit is contained in:
parent
905e5ffa37
commit
eaaf52b683
|
|
@ -1240,19 +1240,17 @@ fixture | fixture: context
|
|||
`);
|
||||
});
|
||||
|
||||
test('test with custom location', async ({ runInlineTest }) => {
|
||||
test('test custom location functionality', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'reporter.ts': stepIndentReporter,
|
||||
'helper.ts': `
|
||||
import { test } from '@playwright/test';
|
||||
|
||||
export function getStepLocation() {
|
||||
return { file: 'custom-file.ts', line: 99, column: 1 };
|
||||
export async function dummyStep(test, title, action, location) {
|
||||
return await test.step(title, action, { location });
|
||||
}
|
||||
|
||||
export async function customStep(test, title, action) {
|
||||
const location = getStepLocation();
|
||||
return await test.step(title, action, { location });
|
||||
export function getCustomLocation() {
|
||||
return { file: 'dummy-file.ts', line: 123, column: 45 };
|
||||
}
|
||||
`,
|
||||
'playwright.config.ts': `
|
||||
|
|
@ -1262,73 +1260,21 @@ test('test with custom location', async ({ runInlineTest }) => {
|
|||
`,
|
||||
'a.test.ts': `
|
||||
import { test } from '@playwright/test';
|
||||
import { customStep } from './helper';
|
||||
import { dummyStep, getCustomLocation } from './helper';
|
||||
|
||||
test('test with custom location', async ({ page }) => {
|
||||
await customStep(test, 'User logs in', async () => {
|
||||
await page.goto('http://localhost:1234/login');
|
||||
await page.fill('input#username', 'testuser');
|
||||
await page.fill('input#password', 'testpass');
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForSelector('.profile');
|
||||
const profileVisible = await page.isVisible('.profile');
|
||||
expect(profileVisible).toBeTruthy();
|
||||
});
|
||||
test('custom location test', async () => {
|
||||
const location = getCustomLocation();
|
||||
await dummyStep(test, 'Perform a dummy step', async () => {
|
||||
}, location);
|
||||
});
|
||||
`
|
||||
}, { reporter: '', workers: 1 });
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.outputLines).toEqual([
|
||||
'hook |Before Hooks',
|
||||
'test.step |User logs in @ custom-file.ts:99',
|
||||
'test.step |↪ success: Profile is visible',
|
||||
'test.step |Perform a dummy step @ dummy-file.ts:123',
|
||||
'hook |After Hooks'
|
||||
]);
|
||||
});
|
||||
|
||||
test('nested step test with custom locations', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'reporter.ts': stepIndentReporter,
|
||||
'helper.ts': `
|
||||
import { test } from '@playwright/test';
|
||||
|
||||
export function getStepLocation(line) {
|
||||
return { file: 'nested-steps.ts', line: line, column: 1 };
|
||||
}
|
||||
|
||||
export async function customStep(test, title, line, action) {
|
||||
const location = getStepLocation(line);
|
||||
return await test.step(title, action, { location });
|
||||
}
|
||||
`,
|
||||
'playwright.config.ts': `
|
||||
module.exports = {
|
||||
reporter: './reporter',
|
||||
};
|
||||
`,
|
||||
'a.test.ts': `
|
||||
import { test } from '@playwright/test';
|
||||
import { customStep } from './helper';
|
||||
|
||||
test('nested step test with custom locations', async ({ page }) => {
|
||||
await customStep(test, 'Outer step', 10, async () => {
|
||||
await page.goto('http://localhost:1234');
|
||||
await customStep(test, 'Inner step', 20, async () => {
|
||||
const buttonVisible = await page.isVisible('button#submit');
|
||||
expect(buttonVisible).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
`
|
||||
}, { reporter: '', workers: 1 });
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.outputLines).toEqual([
|
||||
'hook |Before Hooks',
|
||||
'test.step |Outer step @ nested-steps.ts:10',
|
||||
'test.step |Inner step @ nested-steps.ts:20',
|
||||
'test.step |↪ success: Button is visible',
|
||||
'hook |After Hooks'
|
||||
]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue