Skip to content

Commit 427d611

Browse files
authored
chore: revert #728 and #733 (#771)
1 parent 1416b2a commit 427d611

13 files changed

Lines changed: 131 additions & 153 deletions

CLAUDE.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,30 @@ Semantic commit messages: `label(scope): description`
55
Labels: `fix`, `feat`, `chore`, `docs`, `test`, `devops`
66

77
```bash
8-
git checkout -b fix-39562
8+
git checkout -b fix-12345
99
# ... make changes ...
1010
git add <changed-files>
1111
git commit -m "$(cat <<'EOF'
12-
fix(proxy): handle SOCKS proxy authentication
12+
fix: ask for 127.0.0.1 host when launching test server
1313
14-
Fixes: https://github.com/microsoft/playwright/issues/39562
14+
Fixes: https://github.com/microsoft/playwright-vscode/issues/12345
1515
EOF
1616
)"
17-
git push origin fix-39562
18-
gh pr create --repo microsoft/playwright --head username:fix-39562 \
19-
--title "fix(proxy): handle SOCKS proxy authentication" \
17+
git push origin fix-12345
18+
gh pr create --repo microsoft/playwright-vscdoe --head username:fix-12345 \
19+
--title "fix: ask for 127.0.0.1 host when launching test server" \
2020
--body "$(cat <<'EOF'
2121
## Summary
2222
- <describe the change very! briefly>
2323
24-
Fixes https://github.com/microsoft/playwright/issues/39562
24+
Fixes https://github.com/microsoft/playwright/issues/12345
2525
EOF
2626
)"
2727
```
2828

2929
Never add Co-Authored-By agents in commit message.
30+
Never add "Generated with" in commit message.
31+
Never add test plan to PR description. Keep PR description short — a few bullet points at most.
3032
Branch naming for issue fixes: `fix-<issue-number>`
3133

34+
**Never `git push` without an explicit instruction to push.** Applies even when a PR is already open for the branch — additional commits are immediately visible to reviewers. Commit locally, report what was committed, and wait. Only push when the user's message contains "push", "upload", "create PR", "ship it", or equivalent.

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export class Extension implements RunHooks {
505505
}
506506

507507
private async _runGlobalHooks(type: 'setup' | 'teardown') {
508-
if (!this._models.selectedModel()?.canRunGlobalHooks(type))
508+
if (!this._models.selectedModel()?.needsGlobalHooks(type))
509509
return 'passed';
510510
const request = new this._vscode.TestRunRequest();
511511
const testRun = this._testController.createTestRun(request);

src/playwrightTestServer.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export class PlaywrightTestServer {
6161
private _model: TestModel;
6262
private _testServerPromise: Promise<TestServerConnectionWrapper> | undefined;
6363
private _config?: JsonConfig;
64-
private _globalSetupEnv: { [key: string]: string | undefined } = {};
6564

6665
constructor(vscode: vscodeTypes.VSCode, model: TestModel, options: PlaywrightTestOptions) {
6766
this._vscode = vscode;
@@ -152,10 +151,10 @@ export class PlaywrightTestServer {
152151
const { connection } = await this._testServer();
153152
if (!connection)
154153
return 'failed';
155-
return await this._runGlobalHooksInServer(connection, type, testListener, token, true);
154+
return await this._runGlobalHooksInServer(connection, type, testListener, token);
156155
}
157156

158-
private async _runGlobalHooksInServer(testServer: TestServerConnection, type: 'setup' | 'teardown', testListener: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken, saveEnv: boolean): Promise<'passed' | 'failed' | 'interrupted' | 'timedout'> {
157+
private async _runGlobalHooksInServer(testServer: TestServerConnection, type: 'setup' | 'teardown', testListener: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken): Promise<'passed' | 'failed' | 'interrupted' | 'timedout'> {
159158
const teleReceiver = new TeleReporterReceiver(testListener, {
160159
mergeProjects: true,
161160
mergeTestCases: true,
@@ -166,17 +165,13 @@ export class PlaywrightTestServer {
166165
try {
167166
if (type === 'setup' && (!this._config || this._config.globalSetup))
168167
testListener.onStdOut?.('\x1b[2mRunning global setup if any\u2026\x1b[0m\n');
169-
const result = await Promise.race([
170-
type === 'setup' ? testServer.runGlobalSetup({}) : testServer.runGlobalTeardown({}).then(result => ({ ...result, env: [] })),
168+
const { report, status } = await Promise.race([
169+
type === 'setup' ? testServer.runGlobalSetup({}) : testServer.runGlobalTeardown({}),
171170
new Promise<{ status: 'interrupted', report: [] }>(f => token.onCancellationRequested(() => f({ status: 'interrupted', report: [] }))),
172171
]);
173-
for (const message of result.report)
172+
for (const message of report)
174173
void teleReceiver.dispatch(message);
175-
if (type === 'setup' && saveEnv && 'env' in result)
176-
this._globalSetupEnv = Object.fromEntries(result.env.map(([key, value]) => [key, value ?? undefined]));
177-
if (type === 'teardown' && saveEnv)
178-
this._globalSetupEnv = {};
179-
return result.status;
174+
return status;
180175
} finally {
181176
disposable.dispose();
182177
}
@@ -263,7 +258,7 @@ export class PlaywrightTestServer {
263258
};
264259
}
265260

266-
async debugTests(request: vscodeTypes.TestRunRequest, runOptions: PlaywrightTestRunOptions, reporter: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken, debugGlobalSetup: boolean): Promise<void> {
261+
async debugTests(request: vscodeTypes.TestRunRequest, runOptions: PlaywrightTestRunOptions, reporter: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken): Promise<void> {
267262
const addressPromise = new Promise<string>(f => {
268263
const disposable = this._options.onStdOut(output => {
269264
const match = output.match(/Listening on (.*)/);
@@ -308,7 +303,6 @@ export class PlaywrightTestServer {
308303
...process.env,
309304
CI: this._options.isUnderTest ? undefined : process.env.CI,
310305
...this._options.envProvider(this._model.config.configFile),
311-
...(debugGlobalSetup ? {} : this._globalSetupEnv),
312306
// Reset VSCode's options that affect nested Electron.
313307
ELECTRON_RUN_AS_NODE: undefined,
314308
FORCE_COLOR: '1',
@@ -335,11 +329,9 @@ export class PlaywrightTestServer {
335329
if (!locations && !testIds)
336330
return;
337331

338-
if (debugGlobalSetup) {
339-
const result = await this._runGlobalHooksInServer(debugTestServer, 'setup', reporter, token, false);
340-
if (result !== 'passed')
341-
return;
342-
}
332+
const result = await this._runGlobalHooksInServer(debugTestServer, 'setup', reporter, token);
333+
if (result !== 'passed')
334+
return;
343335

344336
// Locations are regular expressions.
345337
const locationPatterns = locations ? locations.map(escapeRegex) : [];
@@ -364,8 +356,8 @@ export class PlaywrightTestServer {
364356
}
365357
} finally {
366358
disposables.forEach(disposable => disposable.dispose());
367-
if (debugGlobalSetup && !token.isCancellationRequested && debugTestServer && !debugTestServer.isClosed())
368-
await this._runGlobalHooksInServer(debugTestServer, 'teardown', reporter, token, false);
359+
if (!token.isCancellationRequested && debugTestServer && !debugTestServer.isClosed())
360+
await this._runGlobalHooksInServer(debugTestServer, 'teardown', reporter, token);
369361
if (debugTestServer) {
370362
// Should exit upon close automatically.
371363
debugTestServer.close();

src/testModel.ts

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class TestModel extends DisposableBase {
109109
if (!this.isEnabled)
110110
return;
111111
await this._listFiles();
112-
if (configSettings && configSettings.projects.length) { // there's a race where we save config settings before projects are loaded, ignore them
112+
if (configSettings) {
113113
let firstProject = true;
114114
for (const project of this.projects()) {
115115
const projectSettings = configSettings.projects.find(p => p.name === project.name);
@@ -120,22 +120,8 @@ export class TestModel extends DisposableBase {
120120
firstProject = false;
121121
}
122122
} else {
123-
if (this.projects().length === 0)
124-
return;
125-
126-
let foundFirstBrowserProject = false;
127-
for (const p of this.projects()) {
128-
if (isBogStandardBrowserProject(p.name)) {
129-
if (foundFirstBrowserProject) {
130-
p[kIsEnabled] = false;
131-
} else {
132-
p[kIsEnabled] = true;
133-
foundFirstBrowserProject = true;
134-
}
135-
} else {
136-
p[kIsEnabled] = true;
137-
}
138-
}
123+
if (this.projects().length)
124+
this.projects()[0][kIsEnabled] = true;
139125
}
140126
}
141127

@@ -479,6 +465,14 @@ export class TestModel extends DisposableBase {
479465
return !this._ranGlobalSetup;
480466
}
481467

468+
needsGlobalHooks(type: 'setup' | 'teardown'): boolean {
469+
if (type === 'setup' && !this._ranGlobalSetup)
470+
return true;
471+
if (type === 'teardown' && this._ranGlobalSetup)
472+
return true;
473+
return false;
474+
}
475+
482476
async runGlobalHooks(type: 'setup' | 'teardown', testListener: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken): Promise<reporterTypes.FullResult['status']> {
483477
if (type === 'setup') {
484478
if (this._ranGlobalSetup && !this._embedder.settingsModel.runGlobalSetupOnEachRun.get())
@@ -533,8 +527,6 @@ export class TestModel extends DisposableBase {
533527
const globalSetupResult = await this.runGlobalHooks('setup', reporter, token);
534528
if (globalSetupResult !== 'passed')
535529
return;
536-
if (token?.isCancellationRequested)
537-
return;
538530

539531
const externalOptions = await this._embedder.runHooks.onWillRunTests(this.config, false);
540532
const showBrowser = this._embedder.settingsModel.showBrowser.get() && !!externalOptions.connectWsEndpoint;
@@ -579,17 +571,8 @@ export class TestModel extends DisposableBase {
579571

580572
this._collection._saveSettings();
581573

582-
// Toggling "run global setup on each run" allows user to debug global setup/teardown code.
583-
const debugShouldRunGlobalSetup = !!this._embedder.settingsModel.runGlobalSetupOnEachRun.get();
584-
if (debugShouldRunGlobalSetup) {
585-
const globalTeardownResult = await this.runGlobalHooks('teardown', reporter, token);
586-
if (globalTeardownResult !== 'passed')
587-
return;
588-
} else {
589-
const globalSetupResult = await this.runGlobalHooks('setup', reporter, token);
590-
if (globalSetupResult !== 'passed')
591-
return;
592-
}
574+
// Underlying debugTest implementation will run the global setup.
575+
await this.runGlobalHooks('teardown', reporter, token);
593576
if (token?.isCancellationRequested)
594577
return;
595578

@@ -614,7 +597,7 @@ export class TestModel extends DisposableBase {
614597
try {
615598
if (token?.isCancellationRequested)
616599
return;
617-
await this._playwrightTest.debugTests(request, options, reporter, token, debugShouldRunGlobalSetup);
600+
await this._playwrightTest.debugTests(request, options, reporter, token);
618601
} finally {
619602
await this._embedder.runHooks.onDidRunTests();
620603
}
@@ -930,11 +913,3 @@ function isAncestorOf(root: vscodeTypes.TestItem, descendent: vscodeTypes.TestIt
930913
function noOverrideToUndefined<T>(value: T | 'no-override'): T | undefined {
931914
return value === 'no-override' ? undefined : value;
932915
}
933-
934-
function isBogStandardBrowserProject(name: string) {
935-
name = name.toLowerCase();
936-
937-
return ['chromium', 'firefox', 'webkit', 'google chrome', 'chrome', 'microsoft edge', 'edge', ].some(prefix => {
938-
return name.startsWith(prefix) || name.startsWith(`mobile ${prefix}`) || name.startsWith(`desktop ${prefix}`);
939-
});
940-
}

src/upstream/testServerInterface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export interface TestServerInterface {
4747

4848
runGlobalSetup(params: {}): Promise<{
4949
report: ReportEntry[],
50-
env: [string, string | null][],
5150
status: reporterTypes.FullResult['status']
5251
}>;
5352

tests/codegen.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { connectToSharedBrowser, enableProjects, expect, test, waitForPage } from './utils';
17+
import { connectToSharedBrowser, expect, test, waitForPage } from './utils';
1818
import fs from 'node:fs';
1919

2020
test('should generate code', async ({ activate }) => {
@@ -113,8 +113,6 @@ test('Record at Cursor should respect custom testId', async ({ activate, showBro
113113
`,
114114
});
115115

116-
await enableProjects(vscode, ['main']);
117-
118116
await testController.expandTestItems(/test.spec/);
119117
await expect(await testController.run()).toHaveOutput('1 passed');
120118

tests/debug-tests.spec.ts

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ test('should debug all tests', async ({ activate }) => {
5252
testIds: undefined
5353
})
5454
},
55+
{ method: 'runGlobalTeardown', params: {} },
5556
]);
5657
});
5758

@@ -94,6 +95,7 @@ test('should debug one test', async ({ activate }) => {
9495
testIds: [expect.any(String)]
9596
})
9697
},
98+
{ method: 'runGlobalTeardown', params: {} },
9799
]);
98100
});
99101

@@ -245,75 +247,32 @@ test('should run global setup before debugging', async ({ activate }, testInfo)
245247
}`,
246248
'globalSetup.ts': `
247249
async function globalSetup(config) {
248-
console.log('RUN GLOBAL SETUP UNDER DEBUG: ' + !!process.env.VSCODE_MOCK_DEBUGGING);
250+
console.log('RUN GLOBAL SETUP');
249251
process.env.MAGIC_NUMBER = '42';
250252
}
251253
export default globalSetup;
252254
`,
253255
'tests/test.spec.ts': `
254256
import { test, expect } from '@playwright/test';
255257
test('should pass', async () => {
256-
console.log('TEST UNDER DEBUG: ' + !!process.env.VSCODE_MOCK_DEBUGGING);
257258
console.log('MAGIC NUMBER: ' + process.env.MAGIC_NUMBER);
258259
expect(process.env.MAGIC_NUMBER).toBe('42');
259260
});
260261
`
261262
});
262263

263-
const testRunPromise1 = new Promise<TestRun>(f => testController.onDidCreateTestRun(f));
264264
await testController.expandTestItems(/test.spec/);
265-
const runFinishedPromise1 = testController.debugProfile().run(testController.findTestItems(/pass/));
266-
const testRun1 = await testRunPromise1;
267-
await expect(testRun1).toHaveOutput(`RUN GLOBAL SETUP UNDER DEBUG: false`);
268-
await expect.poll(() => stripAnsi(vscode.debug.output)).toContain(`TEST UNDER DEBUG: true`);
269-
await expect.poll(() => stripAnsi(vscode.debug.output)).toContain(`MAGIC NUMBER: 42`);
270-
expect(testRun1.renderLog()).toBe(`
265+
const testItems = testController.findTestItems(/pass/);
266+
const testRun = await testController.debug(testItems);
267+
268+
expect(stripAnsi(vscode.debug.output)).toContain(`RUN GLOBAL SETUP`);
269+
expect(stripAnsi(vscode.debug.output)).toContain(`MAGIC NUMBER: 42`);
270+
271+
expect(testRun.renderLog({ messages: true })).toBe(`
271272
tests > test.spec.ts > should pass [2:0]
272273
enqueued
273274
enqueued
274275
started
275276
passed
276277
`);
277-
await runFinishedPromise1;
278-
279-
// Second time it should reuse the global setup and not run it again.
280-
const testRunPromise2 = new Promise<TestRun>(f => testController.onDidCreateTestRun(f));
281-
await testController.expandTestItems(/test.spec/);
282-
const runFinishedPromise2 = testController.debugProfile().run(testController.findTestItems(/pass/));
283-
const testRun2 = await testRunPromise2;
284-
await expect.poll(() => stripAnsi(vscode.debug.output)).toContain(`TEST UNDER DEBUG: true`);
285-
await expect.poll(() => stripAnsi(vscode.debug.output)).toContain(`MAGIC NUMBER: 42`);
286-
expect(testRun2.renderOutput()).not.toContain(`RUN GLOBAL SETUP`);
287-
await runFinishedPromise2;
288-
});
289-
290-
test('should debug global setup when toggle is enabled', async ({ activate }, testInfo) => {
291-
const { vscode, testController } = await activate({
292-
'playwright.config.js': `module.exports = {
293-
testDir: 'tests',
294-
globalSetup: 'globalSetup.ts',
295-
}`,
296-
'globalSetup.ts': `
297-
async function globalSetup(config) {
298-
console.log('RUN GLOBAL SETUP UNDER DEBUG: ' + !!process.env.VSCODE_MOCK_DEBUGGING);
299-
process.env.MAGIC_NUMBER = '42';
300-
}
301-
export default globalSetup;
302-
`,
303-
'tests/test.spec.ts': `
304-
import { test, expect } from '@playwright/test';
305-
test('should pass', async () => {
306-
console.log('TEST UNDER DEBUG: ' + !!process.env.VSCODE_MOCK_DEBUGGING);
307-
console.log('MAGIC NUMBER: ' + process.env.MAGIC_NUMBER);
308-
expect(process.env.MAGIC_NUMBER).toBe('42');
309-
});
310-
`
311-
}, { runGlobalSetupOnEachRun: true });
312-
313-
await testController.expandTestItems(/test.spec/);
314-
const runFinishedPromise = testController.debugProfile().run(testController.findTestItems(/pass/));
315-
await expect.poll(() => stripAnsi(vscode.debug.output)).toContain(`RUN GLOBAL SETUP UNDER DEBUG: true`);
316-
await expect.poll(() => stripAnsi(vscode.debug.output)).toContain(`TEST UNDER DEBUG: true`);
317-
await expect.poll(() => stripAnsi(vscode.debug.output)).toContain(`MAGIC NUMBER: 42`);
318-
await runFinishedPromise;
319278
});

tests/list-files.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ test('should support multiple projects', async ({ activate }) => {
252252
- tests
253253
- test1.spec.ts
254254
- test2.spec.ts
255+
- [playwright.config.js [project 2] — disabled]
255256
`);
256257

257258
await expect(vscode).toHaveConnectionLog([
@@ -281,7 +282,6 @@ test('should switch between multiple projects with filter', async ({ activate })
281282
test('three', async () => {});
282283
`,
283284
});
284-
await enableProjects(vscode, ['project 1']);
285285
await expect(testController).toHaveTestTree(`
286286
- tests
287287
- test1.spec.ts

tests/mock/vscode.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ export class TestItem {
248248
}
249249

250250
private _innerDelete(id: string) {
251-
const item = this.map.get(id);
252251
this.map.delete(id);
253-
item?.forEach(child => this.testController.allTestItems.delete(child.id));
254252
this.testController.allTestItems.delete(id);
255253
}
256254

@@ -782,7 +780,7 @@ class Debug {
782780
this._debuggerProcess = spawn(node, [configuration.program, ...configuration.args], {
783781
cwd: configuration.cwd,
784782
stdio: 'pipe',
785-
env: { ...configuration.env, VSCODE_MOCK_DEBUGGING: '1' },
783+
env: configuration.env,
786784
});
787785

788786
this._debuggerProcess.stdout.on('data', data => {

0 commit comments

Comments
 (0)