From 90172773011c155799217022ffcc1ecd0343e362 Mon Sep 17 00:00:00 2001 From: DudaGod Date: Wed, 20 Nov 2024 01:18:56 +0300 Subject: [PATCH] feat: ability to specify "env" via vscode settings --- README.md | 3 ++- package.json | 9 +++++++ samples/vscode-settings/.vscode/settings.json | 5 +++- src/api/index.ts | 10 +++++++- src/config/index.ts | 5 +++- src/config/settings.ts | 3 +++ ...-vscode-settings.ts => use-config-path.ts} | 0 tests/e2e/vscode-settings/specs/use-env.ts | 25 +++++++++++++++++++ 8 files changed, 56 insertions(+), 4 deletions(-) rename tests/e2e/vscode-settings/specs/{use-vscode-settings.ts => use-config-path.ts} (100%) create mode 100644 tests/e2e/vscode-settings/specs/use-env.ts diff --git a/README.md b/README.md index 78e0d23..9764bd0 100644 --- a/README.md +++ b/README.md @@ -77,4 +77,5 @@ Adds a keybinding (`cmd+shift+8` for mac and `ctrl+shift+8` for others) to run a You can configure Testplane using [user and workspace settings](https://code.visualstudio.com/docs/getstarted/settings#_workspace-settings). Available settings: -- `testplane.configPath`: The path to the Testplane [configuration file](https://testplane.io/docs/v8/config/main/). +- `testplane.configPath`: The path to the Testplane [configuration file](https://testplane.io/docs/v8/config/main/); +- `testplane.env`: Environment variables passed to the Testplane process in addition to `process.env`. diff --git a/package.json b/package.json index 61b1685..35b60be 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,15 @@ "markdownDescription": "The path to the Testplane [configuration file](https://testplane.io/docs/v8/config/main/)", "type": "string", "scope": "window" + }, + "testplane.env": { + "markdownDescription": "Environment variables passed to the Testplane process in addition to `process.env`", + "type": [ + "object", + "null" + ], + "default": null, + "scope": "window" } } } diff --git a/samples/vscode-settings/.vscode/settings.json b/samples/vscode-settings/.vscode/settings.json index a88e9ff..f32a82c 100644 --- a/samples/vscode-settings/.vscode/settings.json +++ b/samples/vscode-settings/.vscode/settings.json @@ -1,3 +1,6 @@ { - "testplane.configPath": "./another-config/testplane.config.ts" + "testplane.configPath": "./another-config/testplane.config.ts", + "testplane.env": { + "TESTPLANE_SKIP_BROWSERS": "another-bro" + } } diff --git a/src/api/index.ts b/src/api/index.ts index e692faf..4ac8ca3 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -13,7 +13,15 @@ export async function createChildProcess(wf: vscode.WorkspaceFolder, config: VSC const workerPath = resolve(__dirname, "worker.js"); const execPath = await findNodePath(); - const proc = fork(workerPath, { cwd: normalize(wf.uri.fsPath), stdio: "overlapped", execPath }); + const proc = fork(workerPath, { + cwd: normalize(wf.uri.fsPath), + stdio: "overlapped", + execPath, + env: { + ...process.env, + ...config.env, + }, + }); proc.stdout?.on("data", d => logger.worker("info", d.toString())); proc.stderr?.on("data", d => logger.worker("error", d.toString())); diff --git a/src/config/index.ts b/src/config/index.ts index 7d86fdf..4be8fee 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -8,5 +8,8 @@ export const getVSCodeConfig = async (wf?: vscode.WorkspaceFolder): Promise | null; }; export const getVSCodeSettings = (wf?: vscode.WorkspaceFolder): VSCodeSettings => { @@ -19,9 +20,11 @@ export const getVSCodeSettings = (wf?: vscode.WorkspaceFolder): VSCodeSettings = }); const configPath = get("configPath"); + const env = get | null>("env", null)!; return { configPath: resolveConfigPath(configPath, wf), + env, }; }; diff --git a/tests/e2e/vscode-settings/specs/use-vscode-settings.ts b/tests/e2e/vscode-settings/specs/use-config-path.ts similarity index 100% rename from tests/e2e/vscode-settings/specs/use-vscode-settings.ts rename to tests/e2e/vscode-settings/specs/use-config-path.ts diff --git a/tests/e2e/vscode-settings/specs/use-env.ts b/tests/e2e/vscode-settings/specs/use-env.ts new file mode 100644 index 0000000..e5ba05c --- /dev/null +++ b/tests/e2e/vscode-settings/specs/use-env.ts @@ -0,0 +1,25 @@ +import { expect } from "@wdio/globals"; +import { VSCodePO } from "../../page-objects"; + +describe(".vscode/settings.json", () => { + it("should be skipped by 'TESTPLANE_SKIP_BROWSERS' env variable from user settings", async () => { + const vscodePO = await VSCodePO.create(); + const testingViewControl = vscodePO.getTestingViewControl(); + await testingViewControl.open(); + + const sidebar = vscodePO.getTestingSideBar(); + await sidebar.waitTestsRead(); + await sidebar.runAllTests(); + await sidebar.waitTestsRunComplete(); + + await expect(await sidebar.getTestsRunStats()).toBe("0/0"); + + const [firstSection] = await sidebar.getSections(); + const [mainTreeItem] = await firstSection.getVisibleItems(); + await mainTreeItem.expandAll(); + + const items = await firstSection.getVisibleItems(); + + await expect(await items[0].getAriaLabelAttr()).toContain("tests (Skipped)"); + }); +});