Skip to content

Commit c6bc126

Browse files
committed
Add a unit test to quartoConfig loading
1 parent c774111 commit c6bc126

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/core/quarto.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export const quartoConfig = {
4343
return kLocalDevelopment;
4444
}
4545
},
46-
dotenv: async (): Promise<Record<string, string>> => {
47-
if (!dotenvConfig) {
46+
dotenv: async (forceReload?: boolean): Promise<Record<string, string>> => {
47+
if (forceReload || !dotenvConfig) {
4848
const options: ConfigOptions = {
4949
defaultsPath: join(quartoConfig.sharePath(), "env", "env.defaults"),
5050
// On dev mode only (QUARTO_DEBUG='true'), we load the .env file in root quarto-cli project

tests/unit/dotenv-config.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* environment.test.ts
3+
*
4+
* Copyright (C) 2020-2022 Posit Software, PBC
5+
*
6+
*/
7+
import { assert, assertEquals } from "testing/asserts.ts";
8+
import { unitTest } from "../test.ts";
9+
import { quartoConfig } from "../../src/core/quarto.ts";
10+
11+
const workingDir = Deno.makeTempDirSync();
12+
13+
unitTest(
14+
"dotenv config",
15+
async () => {
16+
// force reload for the test as otherwise the cached value
17+
// loaded from tests/ working dir will be used
18+
const dotenvConfig = await quartoConfig.dotenv(true);
19+
assert(
20+
Object.keys(dotenvConfig).length > 0,
21+
"Quarto dotenv config is not loading correctly",
22+
);
23+
},
24+
{
25+
setup: () => {
26+
// testing working dir config wrongly loaded
27+
// https://github.com/quarto-dev/quarto-cli/issues/9262
28+
Deno.writeTextFileSync(".env.example", "TEST_VAR=")
29+
return Promise.resolve();
30+
},
31+
cwd: () => {
32+
return workingDir;
33+
},
34+
teardown: () => {
35+
try {
36+
Deno.removeSync(workingDir, { recursive: true });
37+
} catch {
38+
}
39+
return Promise.resolve();
40+
},
41+
}
42+
);

0 commit comments

Comments
 (0)