From 821f8af2bbd63fc547166f8fff511ac2287a26b5 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 2 Oct 2023 12:33:42 -0700 Subject: [PATCH] feat: stringify non-string values in `playwright.env` setting (#380) --- src/extension.ts | 7 ++++--- tests/settings.spec.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index c531e5e5e..65f30a17b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -289,9 +289,10 @@ export class Extension { } private _envProvider(): NodeJS.ProcessEnv { - return { - ...this._vscode.workspace.getConfiguration('playwright').get('env', {}), - }; + const env = this._vscode.workspace.getConfiguration('playwright').get('env', {}); + return Object.fromEntries(Object.entries(env).map(entry => { + return typeof entry[1] === 'string' ? entry : [entry[0], JSON.stringify(entry[1])]; + })) as NodeJS.ProcessEnv; } private async _createRunProfile(project: TestProject, usedProfiles: Set) { diff --git a/tests/settings.spec.ts b/tests/settings.spec.ts index dc2c7bec4..fe9933935 100644 --- a/tests/settings.spec.ts +++ b/tests/settings.spec.ts @@ -64,3 +64,29 @@ test('should open test results', async ({ activate }) => { await webView.getByText('Reveal test output').click(); expect(vscode.commandLog.filter(f => f !== 'testing.getExplorerSelection')).toEqual(['testing.showMostRecentOutput']); }); + +test('should support playwright.env', async ({ activate }) => { + const { vscode, testController } = await activate({ + 'playwright.config.js': `module.exports = {}`, + 'example.spec.ts': ` + import { test } from '@playwright/test'; + test('one', async () => { + console.log('foo=' + process.env.FOO); + console.log('bar=' + process.env.BAR); + }); + `, + }); + const configuration = vscode.workspace.getConfiguration('playwright'); + configuration.update('env', { + 'FOO': 'foo-value', + 'BAR': { prop: 'bar-value' }, + }); + + const testItems = testController.findTestItems(/example.spec.ts/); + expect(testItems.length).toBe(1); + + const testRun = await testController.run(testItems); + const output = testRun.renderLog({ output: true }); + expect(output).toContain(`foo=foo-value`); + expect(output).toContain(`bar={"prop":"bar-value"}`); +});