2022-05-17 12:15:06 -05:00
|
|
|
import * as assert from "assert";
|
2023-07-17 08:49:15 -05:00
|
|
|
import type { Context } from ".";
|
2022-05-17 12:15:06 -05:00
|
|
|
import { substituteVariablesInEnv } from "../../src/config";
|
2022-05-11 07:22:58 -05:00
|
|
|
|
|
|
|
export async function getTests(ctx: Context) {
|
2022-05-17 12:15:06 -05:00
|
|
|
await ctx.suite("Server Env Settings", (suite) => {
|
|
|
|
suite.addTest("Replacing Env Variables", async () => {
|
2022-05-11 07:22:58 -05:00
|
|
|
const envJson = {
|
|
|
|
USING_MY_VAR: "${env:MY_VAR} test ${env:MY_VAR}",
|
2022-05-17 12:15:06 -05:00
|
|
|
MY_VAR: "test",
|
2022-05-11 07:22:58 -05:00
|
|
|
};
|
|
|
|
const expectedEnv = {
|
|
|
|
USING_MY_VAR: "test test test",
|
2022-05-17 12:15:06 -05:00
|
|
|
MY_VAR: "test",
|
2022-05-11 07:22:58 -05:00
|
|
|
};
|
|
|
|
const actualEnv = await substituteVariablesInEnv(envJson);
|
|
|
|
assert.deepStrictEqual(actualEnv, expectedEnv);
|
|
|
|
});
|
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("Circular dependencies remain as is", async () => {
|
2022-05-11 07:22:58 -05:00
|
|
|
const envJson = {
|
|
|
|
A_USES_B: "${env:B_USES_A}",
|
|
|
|
B_USES_A: "${env:A_USES_B}",
|
|
|
|
C_USES_ITSELF: "${env:C_USES_ITSELF}",
|
|
|
|
D_USES_C: "${env:C_USES_ITSELF}",
|
|
|
|
E_IS_ISOLATED: "test",
|
2022-05-17 12:15:06 -05:00
|
|
|
F_USES_E: "${env:E_IS_ISOLATED}",
|
2022-05-11 07:22:58 -05:00
|
|
|
};
|
|
|
|
const expectedEnv = {
|
|
|
|
A_USES_B: "${env:B_USES_A}",
|
|
|
|
B_USES_A: "${env:A_USES_B}",
|
|
|
|
C_USES_ITSELF: "${env:C_USES_ITSELF}",
|
|
|
|
D_USES_C: "${env:C_USES_ITSELF}",
|
|
|
|
E_IS_ISOLATED: "test",
|
2022-05-17 12:15:06 -05:00
|
|
|
F_USES_E: "test",
|
2022-05-11 07:22:58 -05:00
|
|
|
};
|
|
|
|
const actualEnv = await substituteVariablesInEnv(envJson);
|
|
|
|
assert.deepStrictEqual(actualEnv, expectedEnv);
|
|
|
|
});
|
2022-05-11 07:28:08 -05:00
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("Should support external variables", async () => {
|
2023-07-17 08:49:15 -05:00
|
|
|
process.env["TEST_VARIABLE"] = "test";
|
2022-05-11 07:28:08 -05:00
|
|
|
const envJson = {
|
2022-05-17 12:15:06 -05:00
|
|
|
USING_EXTERNAL_VAR: "${env:TEST_VARIABLE} test ${env:TEST_VARIABLE}",
|
2022-05-11 07:28:08 -05:00
|
|
|
};
|
|
|
|
const expectedEnv = {
|
2022-05-17 12:15:06 -05:00
|
|
|
USING_EXTERNAL_VAR: "test test test",
|
2022-05-11 07:28:08 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const actualEnv = await substituteVariablesInEnv(envJson);
|
|
|
|
assert.deepStrictEqual(actualEnv, expectedEnv);
|
2023-07-17 08:49:15 -05:00
|
|
|
delete process.env["TEST_VARIABLE"];
|
2022-05-11 07:28:08 -05:00
|
|
|
});
|
2022-05-11 07:34:43 -05:00
|
|
|
|
2022-05-17 12:15:06 -05:00
|
|
|
suite.addTest("should support VSCode variables", async () => {
|
2022-05-11 07:34:43 -05:00
|
|
|
const envJson = {
|
2022-05-17 12:15:06 -05:00
|
|
|
USING_VSCODE_VAR: "${workspaceFolderBasename}",
|
2022-05-11 07:34:43 -05:00
|
|
|
};
|
|
|
|
const actualEnv = await substituteVariablesInEnv(envJson);
|
2023-07-17 08:49:15 -05:00
|
|
|
assert.deepStrictEqual(actualEnv["USING_VSCODE_VAR"], "code");
|
2022-05-11 07:34:43 -05:00
|
|
|
});
|
2022-05-11 07:22:58 -05:00
|
|
|
});
|
|
|
|
}
|