Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reuse): disable tracing #319

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/reusedBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ export class ReusedBrowser implements vscodeTypes.Disposable {
browserServerEnv(debug: boolean): NodeJS.ProcessEnv | undefined {
return (debug || this._shouldReuseBrowserForTests) && this._browserServerWS ? {
PW_TEST_REUSE_CONTEXT: this._shouldReuseBrowserForTests ? '1' : undefined,
// "Show browser" mode forces context reuse that survives over multiple test runs.
// Playwright Test sets up `tracesDir` inside the `test-results` folder, so it will be removed between runs.
// When context is reused, its ongoing tracing will fail with ENOENT because trace files
// were suddenly removed. So we disable tracing in this case.
PW_TEST_DISABLE_TRACING: this._shouldReuseBrowserForTests ? '1' : undefined,
PW_TEST_CONNECT_WS_ENDPOINT: this._browserServerWS,
} : undefined;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/run-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { expect, test } from './utils';
import { TestRun } from './mock/vscode';
import fs from 'fs';

test('should run all tests', async ({ activate }) => {
const { vscode, testController } = await activate({
Expand Down Expand Up @@ -1002,3 +1003,21 @@ test('should produce output twice', async ({ activate }) => {

`);
});

test('should disable tracing when reusing context', async ({ activate, mode }) => {
test.skip(mode !== 'reuse');

const { testController } = await activate({
'playwright.config.js': `module.exports = { testDir: 'tests', use: { trace: 'on' } }`,
'tests/test.spec.ts': `
import { test } from '@playwright/test';
test('one', async ({ page }) => {});
`,
});

const testItems = testController.findTestItems(/test.spec.ts/);
expect(testItems.length).toBe(1);
await testController.run(testItems);

expect(fs.existsSync(test.info().outputPath('test-results', 'test-one', 'trace.zip'))).toBe(false);
});