Skip to content

Commit 7718ad7

Browse files
committed
Add test: quarto inspect standalone file should omit project in RStudio
Also adds _setIsRStudioForTest() override to platform.ts to avoid Deno.env.set() race conditions in parallel tests (#14218, PR #12621).
1 parent 5f5993c commit 7718ad7

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

src/core/platform.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ export function isWSL() {
1414
return !!Deno.env.get("WSL_DISTRO_NAME");
1515
}
1616

17+
// Test override for isRStudio — avoids Deno.env.set() race conditions
18+
// in parallel tests. See quarto-dev/quarto-cli#14218 and PR #12621.
19+
let _isRStudioOverride: boolean | undefined;
20+
export function _setIsRStudioForTest(value: boolean | undefined) {
21+
_isRStudioOverride = value;
22+
}
23+
1724
export function isRStudio() {
25+
if (_isRStudioOverride !== undefined) return _isRStudioOverride;
1826
return !!Deno.env.get("RSTUDIO");
1927
}
2028

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Hello
3+
format: html
4+
---
5+
6+
Hello world.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* inspect-standalone-rstudio.test.ts
3+
*
4+
* Copyright (C) 2020-2026 Posit Software, PBC
5+
*
6+
*/
7+
8+
import { existsSync } from "../../../src/deno_ral/fs.ts";
9+
import { _setIsRStudioForTest } from "../../../src/core/platform.ts";
10+
import {
11+
ExecuteOutput,
12+
testQuartoCmd,
13+
} from "../../test.ts";
14+
import { assert, assertEquals } from "testing/asserts";
15+
16+
// Test: standalone file inspect with RStudio override should NOT emit project.
17+
// Uses _setIsRStudioForTest to avoid Deno.env.set() race conditions in
18+
// parallel tests (see #14218, PR #12621).
19+
(() => {
20+
const input = "docs/inspect/standalone-hello.qmd";
21+
const output = "docs/inspect/standalone-hello.json";
22+
testQuartoCmd(
23+
"inspect",
24+
[input, output],
25+
[
26+
{
27+
name: "inspect-standalone-no-project-in-rstudio",
28+
verify: async (_outputs: ExecuteOutput[]) => {
29+
assert(existsSync(output));
30+
const json = JSON.parse(Deno.readTextFileSync(output));
31+
assertEquals(json.project, undefined,
32+
"Standalone file inspect should not emit 'project' when in RStudio");
33+
}
34+
}
35+
],
36+
{
37+
setup: async () => {
38+
_setIsRStudioForTest(true);
39+
},
40+
teardown: async () => {
41+
_setIsRStudioForTest(undefined);
42+
if (existsSync(output)) {
43+
Deno.removeSync(output);
44+
}
45+
}
46+
},
47+
);
48+
})();
49+
50+
// Test: standalone file inspect WITHOUT RStudio should still emit project
51+
(() => {
52+
const input = "docs/inspect/standalone-hello.qmd";
53+
const output = "docs/inspect/standalone-hello-nors.json";
54+
testQuartoCmd(
55+
"inspect",
56+
[input, output],
57+
[
58+
{
59+
name: "inspect-standalone-has-project-outside-rstudio",
60+
verify: async (_outputs: ExecuteOutput[]) => {
61+
assert(existsSync(output));
62+
const json = JSON.parse(Deno.readTextFileSync(output));
63+
assert(json.project !== undefined,
64+
"Standalone file inspect should emit 'project' when not in RStudio");
65+
assert(json.project.dir !== undefined,
66+
"project.dir should be set");
67+
}
68+
}
69+
],
70+
{
71+
teardown: async () => {
72+
if (existsSync(output)) {
73+
Deno.removeSync(output);
74+
}
75+
}
76+
},
77+
);
78+
})();

0 commit comments

Comments
 (0)