Skip to content

Commit

Permalink
Merge pull request #15 from gemini-testing/TESTPLANE-326.ability_to_s…
Browse files Browse the repository at this point in the history
…et_env_variables

feat: ability to specify "env" via vscode settings
  • Loading branch information
DudaGod authored Nov 26, 2024
2 parents 650f854 + 9017277 commit 4fc30a4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion samples/vscode-settings/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
10 changes: 9 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
5 changes: 4 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ export const getVSCodeConfig = async (wf?: vscode.WorkspaceFolder): Promise<VSCo
const settings = getVSCodeSettings(wf);
const configPath = settings.configPath ? settings.configPath : await findTestplaneConfigFile();

return { configPath };
return {
configPath,
env: settings.env,
};
};
3 changes: 3 additions & 0 deletions src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as vscode from "vscode";

export type VSCodeSettings = {
configPath: string | undefined;
env: Record<string, string> | null;
};

export const getVSCodeSettings = (wf?: vscode.WorkspaceFolder): VSCodeSettings => {
Expand All @@ -19,9 +20,11 @@ export const getVSCodeSettings = (wf?: vscode.WorkspaceFolder): VSCodeSettings =
});

const configPath = get<string>("configPath");
const env = get<Record<string, string> | null>("env", null)!;

return {
configPath: resolveConfigPath(configPath, wf),
env,
};
};

Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/vscode-settings/specs/use-env.ts
Original file line number Diff line number Diff line change
@@ -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)");
});
});

0 comments on commit 4fc30a4

Please sign in to comment.