Skip to content

Commit a1f82b0

Browse files
authored
fix(trace): do not corrupt test runner actions when no library trace is present (microsoft#31564)
Recent logic that matches either by `stepId` or by `apiName`+`wallTime` did not account for "no library trace" scenario.
1 parent ce2b138 commit a1f82b0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/trace-viewer/src/ui/modelUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function mergeActionsAndUpdateTimingSameTrace(contexts: ContextEntry[]) {
223223
// library context actions.
224224
// - In the older versions the step id is not stored and the match is perfomed based on
225225
// action name and wallTime.
226-
const matchByStepId = libraryContexts.some(c => c.actions.some(a => !!a.stepId));
226+
const matchByStepId = !libraryContexts.length || libraryContexts.some(c => c.actions.some(a => !!a.stepId));
227227

228228
for (const context of libraryContexts) {
229229
for (const action of context.actions) {

tests/playwright-test/playwright.trace.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,39 @@ test('trace:retain-on-first-failure should create trace if request context is di
11181118
expect(result.failed).toBe(1);
11191119
});
11201120

1121+
test('should not corrupt actions when no library trace is present', async ({ runInlineTest }) => {
1122+
const result = await runInlineTest({
1123+
'a.spec.ts': `
1124+
import { test as base, expect } from '@playwright/test';
1125+
const test = base.extend({
1126+
foo: async ({}, use) => {
1127+
expect(1).toBe(1);
1128+
await use();
1129+
expect(2).toBe(2);
1130+
},
1131+
});
1132+
test('fail', async ({ foo }) => {
1133+
expect(1).toBe(2);
1134+
});
1135+
`,
1136+
}, { trace: 'on' });
1137+
expect(result.exitCode).toBe(1);
1138+
expect(result.failed).toBe(1);
1139+
1140+
const tracePath = test.info().outputPath('test-results', 'a-fail', 'trace.zip');
1141+
const trace = await parseTrace(tracePath);
1142+
expect(trace.actionTree).toEqual([
1143+
'Before Hooks',
1144+
' fixture: foo',
1145+
' expect.toBe',
1146+
'expect.toBe',
1147+
'After Hooks',
1148+
' fixture: foo',
1149+
' expect.toBe',
1150+
'Worker Cleanup',
1151+
]);
1152+
});
1153+
11211154
test('should record trace in workerStorageState', async ({ runInlineTest }) => {
11221155
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30287' });
11231156

0 commit comments

Comments
 (0)