diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf1ba4e04..cecbfb39c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: - run: npx playwright install chromium - run: npm run lint - run: npm run build - - run: npm run test -- --workers=1 + - run: npm run test -- --project=cli --project=cli-reuse --workers=1 - run: npx vsce package if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20' - uses: actions/upload-artifact@v3 diff --git a/package.json b/package.json index 5916af9ad..d51e6120f 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,10 @@ "type": "boolean", "default": false, "description": "%configuration.playwright.showTrace%" + }, + "playwright.useTestServer": { + "type": "boolean", + "default": false } } }, diff --git a/playwright.config.ts b/playwright.config.ts index e8cd3fd46..6faa0f55d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -30,15 +30,33 @@ const config: PlaywrightTestConfig = { ], projects: [ { - name: 'default', + name: 'cli', + use: { + useTestServer: false, + showBrowser: false, + } + }, + { + name: 'cli-reuse', + use: { + useTestServer: false, + showBrowser: true, + } }, { - name: 'reuse', - testIgnore: '**/settings.spec.ts', + name: 'server', use: { - mode: 'reuse', + useTestServer: true, + showBrowser: false, } - } + }, + { + name: 'server-reuse', + use: { + useTestServer: true, + showBrowser: true, + } + }, ] }; export default config; diff --git a/src/extension.ts b/src/extension.ts index 30f2c0140..c2a30f3a5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -244,6 +244,7 @@ export class Extension implements RunHooks { private async _rebuildModel(showWarnings: boolean): Promise { this._testTree.startedLoading(); this._workspaceObserver.reset(); + this._testServerController.reset(); this._models = []; const configFiles = await this._vscode.workspace.findFiles('**/*playwright*.config.{ts,js,mjs}', '**/node_modules/**'); diff --git a/src/playwrightTest.ts b/src/playwrightTest.ts index c8c2b142a..33aaaa058 100644 --- a/src/playwrightTest.ts +++ b/src/playwrightTest.ts @@ -171,7 +171,7 @@ export class PlaywrightTest { } private async _test(config: TestConfig, locations: string[], mode: 'list' | 'run', options: PlaywrightTestOptions, listener: TestListener, token: vscodeTypes.CancellationToken): Promise { - if (process.env.PWTEST_VSCODE_SERVER) + if (this._settingsModel.useTestServer.get()) await this._testWithServer(config, locations, mode, options, listener, token); else await this._testWithCLI(config, locations, mode, options, listener, token); diff --git a/src/settingsModel.ts b/src/settingsModel.ts index 2fea10646..6de95c2eb 100644 --- a/src/settingsModel.ts +++ b/src/settingsModel.ts @@ -24,6 +24,7 @@ export class SettingsModel implements vscodeTypes.Disposable { private _disposables: vscodeTypes.Disposable[] = []; showBrowser: Setting; showTrace: Setting; + useTestServer: Setting; constructor(vscode: vscodeTypes.VSCode) { this._vscode = vscode; @@ -32,6 +33,7 @@ export class SettingsModel implements vscodeTypes.Disposable { this.showBrowser = this._createSetting('reuseBrowser'); this.showTrace = this._createSetting('showTrace'); + this.useTestServer = this._createSetting('useTestServer'); this.showBrowser.onChange(enabled => { if (enabled && this.showTrace.get()) diff --git a/src/testServerController.ts b/src/testServerController.ts index 01e30a49d..30a99be12 100644 --- a/src/testServerController.ts +++ b/src/testServerController.ts @@ -36,7 +36,12 @@ export class TestServerController implements vscodeTypes.Disposable { const testServerBackend = new BackendServer(this._vscode, { args, cwd: config.workspaceFolder, - envProvider: this._envProvider, + envProvider: () => { + return { + ...this._envProvider(), + FORCE_COLOR: '1', + }; + }, clientFactory: () => new TestServer(this._vscode), dumpIO: false, }); @@ -48,6 +53,10 @@ export class TestServerController implements vscodeTypes.Disposable { } dispose() { + this.reset(); + } + + reset() { for (const backend of this._testServers.values()) backend.close(); this._testServers.clear(); diff --git a/tests/auto-close.spec.ts b/tests/auto-close.spec.ts index 5f70c3a50..0ab4a7e38 100644 --- a/tests/auto-close.spec.ts +++ b/tests/auto-close.spec.ts @@ -16,8 +16,8 @@ import { connectToSharedBrowser, expect, test, waitForPage } from './utils'; -test.beforeEach(async ({ mode }) => { - test.skip(mode !== 'reuse'); +test.beforeEach(async ({ showBrowser }) => { + test.skip(!showBrowser); process.env.PW_DEBUG_CONTROLLER_HEADLESS = '1'; }); diff --git a/tests/highlight-locators.spec.ts b/tests/highlight-locators.spec.ts index 8308b7414..a71814bb5 100644 --- a/tests/highlight-locators.spec.ts +++ b/tests/highlight-locators.spec.ts @@ -17,9 +17,9 @@ import { chromium } from '@playwright/test'; import { expect, test } from './utils'; -test.beforeEach(({ mode }) => { +test.beforeEach(({ showBrowser }) => { // Locator highlighting is only relevant when the browser stays open. - test.skip(mode !== 'reuse'); + test.skip(!showBrowser); // the x-pw-highlight element has otherwise a closed shadow root. process.env.PWTEST_UNDER_TEST = '1'; process.env.PW_DEBUG_CONTROLLER_HEADLESS = '1'; diff --git a/tests/run-tests.spec.ts b/tests/run-tests.spec.ts index 8a33f0ddc..3c836e765 100644 --- a/tests/run-tests.spec.ts +++ b/tests/run-tests.spec.ts @@ -436,8 +436,8 @@ test('should group projects by config', async ({ activate }) => { `); }); -test('should stop', async ({ activate, mode }) => { - test.fixme(mode === 'reuse', 'Times out'); +test('should stop', async ({ activate, showBrowser }) => { + test.fixme(showBrowser, 'Times out'); const { vscode, testController } = await activate({ 'playwright.config.js': `module.exports = { testDir: 'tests' }`, 'tests/test.spec.ts': ` @@ -1004,8 +1004,8 @@ test('should produce output twice', async ({ activate }) => { `); }); -test('should disable tracing when reusing context', async ({ activate, mode }) => { - test.skip(mode !== 'reuse'); +test('should disable tracing when reusing context', async ({ activate, showBrowser }) => { + test.skip(!showBrowser); const { testController } = await activate({ 'playwright.config.js': `module.exports = { testDir: 'tests', use: { trace: 'on' } }`, @@ -1022,8 +1022,8 @@ test('should disable tracing when reusing context', async ({ activate, mode }) = expect(fs.existsSync(test.info().outputPath('test-results', 'test-one', 'trace.zip'))).toBe(false); }); -test('should force workers=1 when reusing the browser', async ({ activate, mode }) => { - test.skip(mode !== 'reuse'); +test('should force workers=1 when reusing the browser', async ({ activate, showBrowser }) => { + test.skip(!showBrowser); const { testController } = await activate({ 'playwright.config.js': `module.exports = { testDir: 'tests', workers: 2 }`, diff --git a/tests/settings.spec.ts b/tests/settings.spec.ts index fe9933935..5d6f19b0e 100644 --- a/tests/settings.spec.ts +++ b/tests/settings.spec.ts @@ -16,6 +16,10 @@ import { expect, test } from './utils'; +test.beforeEach(async ({ showBrowser }) => { + test.skip(showBrowser); +}); + test('should toggle settings', async ({ activate }) => { const { vscode } = await activate({ 'playwright.config.js': `module.exports = {}`, diff --git a/tests/utils.ts b/tests/utils.ts index 079da1e1d..15b183940 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -30,7 +30,8 @@ type TestFixtures = { }; export type WorkerOptions = { - mode: 'default' | 'reuse'; + useTestServer: boolean; + showBrowser: boolean; }; // Make sure connect tests work with the locally-rolled version. @@ -50,7 +51,7 @@ export const expect = baseExpect.extend({ }, toHaveExecLog(vscode: VSCode, expectedLog: string) { - if (process.env.PWTEST_VSCODE_SERVER) + if (vscode.extensions[0]._settingsModel.useTestServer.get()) return { pass: true, message: () => '' }; try { expect(vscode.renderExecLog(' ')).toBe(expectedLog); @@ -65,9 +66,10 @@ export const expect = baseExpect.extend({ }); export const test = baseTest.extend({ - mode: ['default', { option: true, scope: 'worker' }], + useTestServer: [false, { option: true, scope: 'worker' }], + showBrowser: [false, { option: true, scope: 'worker' }], - activate: async ({ browser, mode }, use, testInfo) => { + activate: async ({ browser, showBrowser, useTestServer }, use, testInfo) => { const instances: VSCode[] = []; await use(async (files: { [key: string]: string }, options?: { rootDir?: string, workspaceFolders?: [string, any][] }) => { const vscode = new VSCode(path.resolve(__dirname, '..'), browser); @@ -81,10 +83,14 @@ export const test = baseTest.extend({ vscode.extensions.push(extension); await vscode.activate(); - if (mode === 'reuse') { + if (showBrowser) { const configuration = vscode.workspace.getConfiguration('playwright'); configuration.update('reuseBrowser', true); } + if (useTestServer) { + const configuration = vscode.workspace.getConfiguration('playwright'); + configuration.update('useTestServer', true); + } instances.push(vscode); return {