Skip to content

Commit

Permalink
chore: running tests should create workspace-settings (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Dec 22, 2024
1 parent f71f051 commit 2b5464f
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/testModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ export class TestModel extends DisposableBase {
if (token?.isCancellationRequested)
return;

this._collection._saveSettings();

// Run global setup with the first test.
let globalSetupResult: reporterTypes.FullResult['status'] = 'passed';
if (this.canRunGlobalHooks('setup'))
Expand Down Expand Up @@ -567,6 +569,8 @@ export class TestModel extends DisposableBase {
if (token?.isCancellationRequested)
return;

this._collection._saveSettings();

// Underlying debugTest implementation will run the global setup.
await this.runGlobalHooks('teardown', reporter, token);
if (token?.isCancellationRequested)
Expand Down Expand Up @@ -837,7 +841,7 @@ export class TestModelCollection extends DisposableBase {
this._didUpdate.fire();
}

private _saveSettings() {
_saveSettings() {
const workspaceSettings: WorkspaceSettings = { configs: [] };
for (const model of this._models) {
workspaceSettings.configs!.push({
Expand Down
96 changes: 96 additions & 0 deletions tests/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,99 @@ test('should reload when playwright.env changes', async ({ activate }) => {
expect(output).toContain(`foo=foo-value`);
expect(output).toContain(`bar={"prop":"bar-value"}`);
});

test('should sync project enabled state to workspace settings', async ({ activate }) => {
const { vscode, testController } = await activate({
'playwright.config.ts': `
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{ name: 'foo', testMatch: 'foo.ts' },
{ name: 'bar', testMatch: 'bar.ts' },
]
});
`,
});

const webView = vscode.webViews.get('pw.extension.settingsView')!;

await expect(webView.locator('body')).toMatchAriaSnapshot(`
- text: PROJECTS
- checkbox "foo" [checked]
- checkbox "bar" [checked=false]
`);
await testController.run(testController.findTestItems(/example.spec.ts/));
expect(vscode.context.workspaceState.get('pw.workspace-settings')).toEqual({
configs: [
{
enabled: true,
projects: [
{
enabled: true,
name: 'foo',
},
{
enabled: false,
name: 'bar',
},
],
relativeConfigFile: 'playwright.config.ts',
selected: true,
},
],
});

await webView.getByRole('checkbox', { name: 'bar' }).check();
await expect(webView.locator('body')).toMatchAriaSnapshot(`
- checkbox "foo" [checked]
- checkbox "bar" [checked]
`);
expect(vscode.context.workspaceState.get('pw.workspace-settings')).toEqual(expect.objectContaining({
configs: [
expect.objectContaining({
enabled: true,
projects: [
expect.objectContaining({ name: 'foo', enabled: true }),
expect.objectContaining({ name: 'bar', enabled: true }),
]
})
]
}));
});

test('should read project enabled state from workspace settings', async ({ vscode, activate }) => {
vscode.context.workspaceState.update('pw.workspace-settings', {
configs: [
{
relativeConfigFile: 'playwright.config.ts',
selected: true,
enabled: true,
projects: [
{ name: 'foo', enabled: true },
{ name: 'bar', enabled: false }
]
}
]
});

await activate({
'playwright.config.ts': `
import { defineConfig } from '@playwright/test';
export default defineConfig({
projects: [
{ name: 'foo', testMatch: 'foo.ts' },
{ name: 'bar', testMatch: 'bar.ts' },
{ name: 'baz', testMatch: 'baz.ts' },
]
});
`,
});

const webView = vscode.webViews.get('pw.extension.settingsView')!;
await expect(webView.locator('body')).toMatchAriaSnapshot(`
- text: PROJECTS
- checkbox "foo" [checked]
- checkbox "bar" [checked=false]
- checkbox "baz" [checked=false]
`);
});

0 comments on commit 2b5464f

Please sign in to comment.