Skip to content

Commit

Permalink
feat: stringify non-string values in playwright.env setting (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Oct 2, 2023
1 parent 467ad78 commit 821f8af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscodeTypes.TestRunProfile>) {
Expand Down
26 changes: 26 additions & 0 deletions tests/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"}`);
});

0 comments on commit 821f8af

Please sign in to comment.