Skip to content

Commit

Permalink
chore: use clear cache via test server
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Apr 5, 2024
1 parent d717d24 commit 3f3c6f8
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/../playwright/packages/web"
"${workspaceFolder}/../playwright/packages/html-reporter"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
Expand Down
1 change: 1 addition & 0 deletions l10n/bundle.l10n.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions l10n/bundle.l10n.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "拾取选择器",
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions package.nls.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "在当前光标处开始录制",
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/playwrightTestCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
const { locations, parametrizedTestTitle } = this._narrowDownLocations(items);
if (!locations)
Expand Down
5 changes: 5 additions & 0 deletions src/playwrightTestServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ export class PlaywrightTestServer {
return result.status;
}

async clearCache(): Promise<void> {
const testServer = await this._testServer();
await testServer?.clearCache({});
}

async runTests(items: vscodeTypes.TestItem[], runOptions: PlaywrightTestRunOptions, reporter: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken): Promise<void> {
const testServer = await this._testServer();
if (token?.isCancellationRequested)
Expand Down
10 changes: 9 additions & 1 deletion src/settingsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<svg xmlns="http://www.w3.org/2000/svg" height="48" width="48"></svg>`,
text: this._vscode.l10n.t('Clear cache'),
location: 'projectList',
disabled: !this._models.selectedModel(),
},
{
command: 'pw.extension.command.toggleModels',
svg: `<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 -960 960 960" width="48"><path d="m388-80-20-126q-19-7-40-19t-37-25l-118 54-93-164 108-79q-2-9-2.5-20.5T185-480q0-9 .5-20.5T188-521L80-600l93-164 118 54q16-13 37-25t40-18l20-127h184l20 126q19 7 40.5 18.5T669-710l118-54 93 164-108 77q2 10 2.5 21.5t.5 21.5q0 10-.5 21t-2.5 21l108 78-93 164-118-54q-16 13-36.5 25.5T592-206L572-80H388Zm48-60h88l14-112q33-8 62.5-25t53.5-41l106 46 40-72-94-69q4-17 6.5-33.5T715-480q0-17-2-33.5t-7-33.5l94-69-40-72-106 46q-23-26-52-43.5T538-708l-14-112h-88l-14 112q-34 7-63.5 24T306-642l-106-46-40 72 94 69q-4 17-6.5 33.5T245-480q0 17 2.5 33.5T254-413l-94 69 40 72 106-46q24 24 53.5 41t62.5 25l14 112Zm44-210q54 0 92-38t38-92q0-54-38-92t-92-38q-54 0-92 38t-38 92q0 54 38 92t92 38Zm0-130Z"/></svg>`,
Expand Down Expand Up @@ -267,9 +274,10 @@ function htmlForWebview(vscode: vscodeTypes.VSCode, extensionUri: vscodeTypes.Ur
</label>
</div>
</div>
<div id="projectListActions" class="list"></div>
<div class="separator"></div>
<div id="actions" class="list"></div>
<div class="separator"></div>
<div id="projectListActions" class="list"></div>
</body>
<script nonce="${nonce}">
let selectConfig;
Expand Down
4 changes: 4 additions & 0 deletions src/testModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ export class TestModel {
this._startedDevServer = false;
}

async clearCache() {
await this._playwrightTest.clearCache();
}

async runTests(items: vscodeTypes.TestItem[], reporter: reporterTypes.ReporterV2, token: vscodeTypes.CancellationToken) {
if (token?.isCancellationRequested)
return;
Expand Down
4 changes: 4 additions & 0 deletions src/upstream/testServerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export class TestServerConnection implements TestServerInterface, TestServerInte
return await this._sendMessage('stopDevServer', params);
}

async clearCache(params: Parameters<TestServerInterface['clearCache']>[0]): ReturnType<TestServerInterface['clearCache']> {
return await this._sendMessage('clearCache', params);
}

async listFiles(params: Parameters<TestServerInterface['listFiles']>[0]): ReturnType<TestServerInterface['listFiles']> {
return await this._sendMessage('listFiles', params);
}
Expand Down
2 changes: 2 additions & 0 deletions src/upstream/testServerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export interface TestServerInterface {
status: reporterTypes.FullResult['status']
}>;

clearCache(params: {}): Promise<void>;

listFiles(params: {
projects?: string[];
}): Promise<{
Expand Down

0 comments on commit 3f3c6f8

Please sign in to comment.