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

chore: rebuild model on changing playwright.env #425

Merged
merged 1 commit into from
Feb 23, 2024
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
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export class Extension implements RunHooks {
this._executionLinesChanged();
}
}),
vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration('playwright.env'))
this._rebuildModel(false);
}),
this._treeItemObserver.onTreeItemSelected(item => this._treeItemSelected(item)),
this._settingsView,
this._testController,
Expand Down
37 changes: 37 additions & 0 deletions tests/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ test('should open test results', async ({ activate }) => {
});

test('should support playwright.env', async ({ activate }) => {
const { 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);
});
`,
}, {
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"}`);
});

test('should reload when playwright.env changes', async ({ activate }) => {
const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = {}`,
'example.spec.ts': `
Expand All @@ -79,13 +105,24 @@ test('should support playwright.env', async ({ activate }) => {
console.log('bar=' + process.env.BAR);
});
`,
}, {
env: {
'FOO': 'foo-value',
'BAR': { prop: 'bar-value' },
}
});

const configuration = vscode.workspace.getConfiguration('playwright');
configuration.update('env', {
'FOO': 'foo-value',
'BAR': { prop: 'bar-value' },
});

// Changes to settings will trigger async update.
await expect.poll(() => testController.findTestItems(/Loading/)).toHaveLength(1);
// That will finish.
await expect.poll(() => testController.findTestItems(/Loading/)).toHaveLength(0);

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

Expand Down
15 changes: 7 additions & 8 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ActivateResult = {

type TestFixtures = {
vscode: VSCode,
activate: (files: { [key: string]: string }, options?: { rootDir?: string, workspaceFolders?: [string, any][] }) => Promise<ActivateResult>;
activate: (files: { [key: string]: string }, options?: { rootDir?: string, workspaceFolders?: [string, any][], env?: Record<string, any> }) => Promise<ActivateResult>;
};

export type WorkerOptions = {
Expand Down Expand Up @@ -76,22 +76,21 @@ export const test = baseTest.extend<TestFixtures, WorkerOptions>({

activate: async ({ vscode, showBrowser, useTestServer }, use, testInfo) => {
const instances: VSCode[] = [];
await use(async (files: { [key: string]: string }, options?: { rootDir?: string, workspaceFolders?: [string, any][] }) => {
await use(async (files: { [key: string]: string }, options?: { rootDir?: string, workspaceFolders?: [string, any][], env?: Record<string, any> }) => {
if (options?.workspaceFolders) {
for (const wf of options?.workspaceFolders)
await vscode.addWorkspaceFolder(wf[0], wf[1]);
} else {
await vscode.addWorkspaceFolder(options?.rootDir || testInfo.outputDir, files);
}

if (showBrowser) {
const configuration = vscode.workspace.getConfiguration('playwright');
const configuration = vscode.workspace.getConfiguration('playwright');
if (options?.env)
configuration.update('env', options.env);
if (showBrowser)
configuration.update('reuseBrowser', true);
}
if (useTestServer) {
const configuration = vscode.workspace.getConfiguration('playwright');
if (useTestServer)
configuration.update('useTestServer', true);
}

const extension = new Extension(vscode);
vscode.extensions.push(extension);
Expand Down
Loading