Skip to content

Commit 7863c51

Browse files
committed
also support passing env variables from the config
1 parent c397f92 commit 7863c51

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,16 @@
128128
},
129129
"nodejs-testing.envFile": {
130130
"type": "string",
131-
"description": "Absolute path to a file containing environment variable definitions.\n\nNote: template parameters like ${workspaceFolder} will be resolved.",
131+
"markdownDescription": "Absolute path to a file containing environment variable definitions.\n\nNote: template parameters like ${workspaceFolder} will be resolved.",
132132
"default": ""
133+
},
134+
"nodejs-testing.env": {
135+
"type": "object",
136+
"markdownDescription": "Environment variables passed to the program. The value null removes the variable from the environment.\n\nNote: This takes precedence over envFile.",
137+
"additionalProperties": {
138+
"type": "string"
139+
},
140+
"default": {}
133141
}
134142
}
135143
}

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export async function activate(context: vscode.ExtensionContext) {
2525
context.extensionUri.fsPath,
2626
new ConfigValue("nodejsParameters", []),
2727
new ConfigValue("envFile", ""),
28+
new ConfigValue("env", {}),
2829
extensions,
2930
);
3031

src/runner.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class TestRunner {
3838
extensionDir: string,
3939
private readonly nodejsParameters: ConfigValue<string[]>,
4040
private readonly envFile: ConfigValue<string>,
41+
private readonly env: ConfigValue<Record<string, string>>,
4142
private readonly extensions: ConfigValue<ExtensionConfig[]>,
4243
) {
4344
this.workerPath = join(extensionDir, "out", "runner-worker.js");
@@ -88,9 +89,14 @@ export class TestRunner {
8889
const outputQueue = new OutputQueue();
8990

9091
const extensions = this.extensions.value;
91-
const extraEnv = this.envFile.value
92-
? parseEnv(await fs.readFile(replaceVariables(this.envFile.value), "utf-8"))
93-
: {};
92+
const envFile = this.envFile.value
93+
? await fs.readFile(replaceVariables(this.envFile.value))
94+
: null;
95+
const envFileValues = envFile ? parseEnv(envFile) : {};
96+
const extraEnv = {
97+
...envFileValues,
98+
...this.env.value,
99+
};
94100

95101
await new Promise<void>((resolve, reject) => {
96102
const socket = getRandomPipe();

0 commit comments

Comments
 (0)