fix :: fix test code be foucsed on location

This commit is contained in:
osohyun0224 2024-09-17 00:14:14 +09:00
parent 905e5ffa37
commit eaaf52b683

View file

@ -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({ const result = await runInlineTest({
'reporter.ts': stepIndentReporter,
'helper.ts': ` 'helper.ts': `
import { test } from '@playwright/test'; import { test } from '@playwright/test';
export function getStepLocation() { export async function dummyStep(test, title, action, location) {
return { file: 'custom-file.ts', line: 99, column: 1 }; return await test.step(title, action, { location });
} }
export async function customStep(test, title, action) { export function getCustomLocation() {
const location = getStepLocation(); return { file: 'dummy-file.ts', line: 123, column: 45 };
return await test.step(title, action, { location });
} }
`, `,
'playwright.config.ts': ` 'playwright.config.ts': `
@ -1262,73 +1260,21 @@ test('test with custom location', async ({ runInlineTest }) => {
`, `,
'a.test.ts': ` 'a.test.ts': `
import { test } from '@playwright/test'; import { test } from '@playwright/test';
import { customStep } from './helper'; import { dummyStep, getCustomLocation } from './helper';
test('test with custom location', async ({ page }) => { test('custom location test', async () => {
await customStep(test, 'User logs in', async () => { const location = getCustomLocation();
await page.goto('http://localhost:1234/login'); await dummyStep(test, 'Perform a dummy step', async () => {
await page.fill('input#username', 'testuser'); }, location);
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();
});
}); });
` `
}, { reporter: '', workers: 1 }); }, { reporter: '', workers: 1 });
expect(result.exitCode).toBe(1); expect(result.exitCode).toBe(0);
expect(result.outputLines).toEqual([ expect(result.outputLines).toEqual([
'hook |Before Hooks', 'hook |Before Hooks',
'test.step |User logs in @ custom-file.ts:99', 'test.step |Perform a dummy step @ dummy-file.ts:123',
'test.step |↪ success: Profile is visible',
'hook |After Hooks' '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'
]);
});