cherry-pick(#21844): chore: update test locations when merging

This commit is contained in:
Pavel Feldman 2023-03-21 12:13:20 -07:00 committed by Pavel
parent b8f802910c
commit 75b429d143
4 changed files with 65 additions and 1 deletions

View file

@ -301,6 +301,7 @@ export class TeleReporterReceiver {
test.id = payload.testId;
test.expectedStatus = payload.expectedStatus;
test.timeout = payload.timeout;
test.location = payload.location;
test.annotations = payload.annotations;
test.retries = payload.retries;
return test;

View file

@ -59,7 +59,7 @@ export const SourceTab: React.FunctionComponent<{
const highlight: SourceHighlight[] = source.errors.map(e => ({ type: 'error', line: e.location.line, message: e.error!.message }));
highlight.push({ line: targetLine, type: 'running' });
if (source.content === undefined) {
if (source.content === undefined || fallbackLocation) {
const sha1 = await calculateSha1(location.file);
try {
let response = await fetch(`sha1/src@${sha1}.txt`);

View file

@ -614,6 +614,10 @@ const sendMessage = async (method: string, params: any) => {
};
const sendMessageNoReply = (method: string, params?: any) => {
if ((window as any)._overrideProtocolForTest) {
(window as any)._overrideProtocolForTest({ method, params }).catch(() => {});
return;
}
sendMessage(method, params).catch((e: Error) => {
// eslint-disable-next-line no-console
console.error(e);

View file

@ -168,3 +168,62 @@ test('should pick new / deleted nested tests', async ({ runUITest, writeFiles, d
inner fails
`);
});
test('should update test locations', async ({ runUITest, writeFiles, deleteFile }) => {
const page = await runUITest({
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('passes', () => {});
`,
});
await expect.poll(dumpTestTree(page), { timeout: 15000 }).toContain(`
a.test.ts
passes
`);
const messages: any = [];
await page.exposeBinding('_overrideProtocolForTest', (_, data) => messages.push(data));
const passesItemLocator = page.getByRole('listitem').filter({ hasText: 'passes' });
await passesItemLocator.hover();
await passesItemLocator.getByTitle('Open in VS Code').click();
expect(messages).toEqual([{
method: 'open',
params: {
location: expect.stringContaining('a.test.ts:3'),
},
}]);
await writeFiles({
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('new-test', () => {});
test('passes', () => {});
`
});
await expect.poll(dumpTestTree(page), { timeout: 15000 }).toContain(`
a.test.ts
new-test
passes <=
`);
messages.length = 0;
await passesItemLocator.hover();
await passesItemLocator.getByTitle('Open in VS Code').click();
expect(messages).toEqual([{
method: 'open',
params: {
location: expect.stringContaining('a.test.ts:5'),
},
}]);
await expect(
page.getByTestId('source-code').locator('.source-tab-file-name')
).toHaveText('a.test.ts');
await expect(page.locator('.CodeMirror-code')).toContainText(`3 test('new-test', () => {});`);
});