From 3f3c6f8084afdaa2c99b5d310ed9b54e9cbf1636 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Fri, 5 Apr 2024 09:10:04 -0700 Subject: [PATCH] chore: use clear cache via test server --- .vscode/launch.json | 2 +- l10n/bundle.l10n.fr.json | 1 + l10n/bundle.l10n.json | 1 + l10n/bundle.l10n.zh-CN.json | 1 + package.json | 7 ++++++- package.nls.fr.json | 1 + package.nls.json | 3 ++- package.nls.zh-CN.json | 1 + src/extension.ts | 3 +++ src/playwrightTestCLI.ts | 3 +++ src/playwrightTestServer.ts | 5 +++++ src/settingsView.ts | 10 +++++++++- src/testModel.ts | 4 ++++ src/upstream/testServerConnection.ts | 4 ++++ src/upstream/testServerInterface.ts | 2 ++ 15 files changed, 44 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index efe25cc1c..529b15021 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "runtimeExecutable": "${execPath}", "args": [ "--extensionDevelopmentPath=${workspaceFolder}", - "${workspaceFolder}/../playwright/packages/web" + "${workspaceFolder}/../playwright/packages/html-reporter" ], "outFiles": [ "${workspaceFolder}/out/**/*.js" diff --git a/l10n/bundle.l10n.fr.json b/l10n/bundle.l10n.fr.json index e15715b5c..1ea6cca30 100644 --- a/l10n/bundle.l10n.fr.json +++ b/l10n/bundle.l10n.fr.json @@ -2,6 +2,7 @@ "Accept to copy locator into clipboard": "Accepter pour copier le locator dans le presse-papiers", "Can't close browsers while running tests": "Impossible de fermer les navigateurs pendant l'exécution des tests", "Can't record while running tests": "Impossible d'enregistrer pendant l'exécution des tests", + "Clear cache": "Vider le cache", "Close all browsers": "Fermer tous les navigateurs", "No Playwright tests found.": "Aucun test Playwright trouvé.", "Pick locator": "Trouver locator", diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 4e39b1a5a..1e3bf9151 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -2,6 +2,7 @@ "Accept to copy locator into clipboard": "Accept to copy locator into clipboard", "Can't close browsers while running tests": "Can't close browsers while running tests", "Can't record while running tests": "Can't record while running tests", + "Clear cache": "Clear cache", "Close all browsers": "Close all browsers", "No Playwright tests found.": "No Playwright tests found.", "Pick locator": "Pick locator", diff --git a/l10n/bundle.l10n.zh-CN.json b/l10n/bundle.l10n.zh-CN.json index f655994e9..2c7b67ca0 100644 --- a/l10n/bundle.l10n.zh-CN.json +++ b/l10n/bundle.l10n.zh-CN.json @@ -2,6 +2,7 @@ "Accept to copy locator into clipboard": "确认保存到剪贴板", "Can't close browsers while running tests": "运行测试时不能关闭浏览器", "Can't record while running tests": "运行测试时不能录制", + "Clear cache": "清除缓存", "Close all browsers": "关闭全部 Playwright 浏览器", "No Playwright tests found.": "没有找到 Playwright Test", "Pick locator": "拾取选择器", diff --git a/package.json b/package.json index d22c16e68..65e964fdf 100644 --- a/package.json +++ b/package.json @@ -88,8 +88,13 @@ }, { "category": "Test", - "command": "pw.extension.command.startDevServer", + "command": "pw.extension.command.stopDevServer", "title": "%contributes.command.pw.extension.command.stopDevServer%" + }, + { + "category": "Test", + "command": "pw.extension.command.clearCache", + "title": "%contributes.command.pw.extension.command.clearCache%" } ], "configuration": { diff --git a/package.nls.fr.json b/package.nls.fr.json index c75b2666c..6ac98449d 100644 --- a/package.nls.fr.json +++ b/package.nls.fr.json @@ -3,6 +3,7 @@ "contributes.command.pw.extension.install": "Installer Playwright", "contributes.command.pw.extension.installBrowsers": "Installer les navigateurs Playwright", "contributes.command.pw.extension.command.inspect": "Trouver locator", + "contributes.command.pw.extension.command.clearCache": "Effacer le cache", "contributes.command.pw.extension.command.closeBrowsers": "Fermer tous les navigateurs", "contributes.command.pw.extension.command.recordNew": "Enregistrer nouveau", "contributes.command.pw.extension.command.recordAtCursor": "Enregistrer au niveau du curseur", diff --git a/package.nls.json b/package.nls.json index e302ebfd4..5ff121b5e 100644 --- a/package.nls.json +++ b/package.nls.json @@ -3,10 +3,11 @@ "contributes.command.pw.extension.install": "Install Playwright", "contributes.command.pw.extension.installBrowsers": "Install Playwright Browsers", "contributes.command.pw.extension.command.inspect": "Pick locator", + "contributes.command.pw.extension.command.clearCache": "Clear cache", "contributes.command.pw.extension.command.closeBrowsers": "Close all Playwright browsers", "contributes.command.pw.extension.command.recordNew": "Record new", "contributes.command.pw.extension.command.recordAtCursor": "Record at cursor", - "contributes.command.pw.extension.command.runGlobalSetup": "Run global tetup", + "contributes.command.pw.extension.command.runGlobalSetup": "Run global setup", "contributes.command.pw.extension.command.runGlobalTeardown": "Run global teardown", "contributes.command.pw.extension.command.startDevServer": "Start dev server", "contributes.command.pw.extension.command.stopDevServer": "Stop dev server", diff --git a/package.nls.zh-CN.json b/package.nls.zh-CN.json index eed4d4fe9..5cf473bc9 100644 --- a/package.nls.zh-CN.json +++ b/package.nls.zh-CN.json @@ -3,6 +3,7 @@ "contributes.command.pw.extension.install": "安装 Playwright", "contributes.command.pw.extension.installBrowsers": "安装 Playwright 浏览器", "contributes.command.pw.extension.command.inspect": "拾取选择器", + "contributes.command.pw.extension.command.clearCache": "清除缓存", "contributes.command.pw.extension.command.closeBrowsers": "关闭全部 Playwright 浏览器", "contributes.command.pw.extension.command.recordNew": "录制新用例", "contributes.command.pw.extension.command.recordAtCursor": "在当前光标处开始录制", diff --git a/src/extension.ts b/src/extension.ts index 777eed60c..bb4cc1600 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -202,6 +202,9 @@ export class Extension implements RunHooks { await this._models.selectedModel()?.stopDevServer(); this._settingsView.updateActions(); }), + vscode.commands.registerCommand('pw.extension.command.clearCache', async () => { + await this._models.selectedModel()?.clearCache(); + }), vscode.workspace.onDidChangeTextDocument(() => { if (this._completedSteps.size) { this._completedSteps.clear(); diff --git a/src/playwrightTestCLI.ts b/src/playwrightTestCLI.ts index 324c72758..4a5f31e05 100644 --- a/src/playwrightTestCLI.ts +++ b/src/playwrightTestCLI.ts @@ -72,6 +72,9 @@ export class PlaywrightTestCLI { async stopDevServer() { } + async clearCache() { + } + async runTests(items: vscodeTypes.TestItem[], options: PlaywrightTestRunOptions, reporter: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken): Promise { const { locations, parametrizedTestTitle } = this._narrowDownLocations(items); if (!locations) diff --git a/src/playwrightTestServer.ts b/src/playwrightTestServer.ts index 368f74595..a4ccd37f2 100644 --- a/src/playwrightTestServer.ts +++ b/src/playwrightTestServer.ts @@ -149,6 +149,11 @@ export class PlaywrightTestServer { return result.status; } + async clearCache(): Promise { + const testServer = await this._testServer(); + await testServer?.clearCache({}); + } + async runTests(items: vscodeTypes.TestItem[], runOptions: PlaywrightTestRunOptions, reporter: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken): Promise { const testServer = await this._testServer(); if (token?.isCancellationRequested) diff --git a/src/settingsView.ts b/src/settingsView.ts index a0c80b8dd..9a9f454e6 100644 --- a/src/settingsView.ts +++ b/src/settingsView.ts @@ -165,6 +165,13 @@ export class SettingsView extends DisposableBase implements vscodeTypes.WebviewV location: 'projectList', disabled: !this._models.selectedModel() || !this._models.selectedModel()!.canStopDevServer(), }, + { + command: 'pw.extension.command.clearCache', + svg: ``, + text: this._vscode.l10n.t('Clear cache'), + location: 'projectList', + disabled: !this._models.selectedModel(), + }, { command: 'pw.extension.command.toggleModels', svg: ``, @@ -267,9 +274,10 @@ function htmlForWebview(vscode: vscodeTypes.VSCode, extensionUri: vscodeTypes.Ur -
+
+