Skip to content

Commit 3a6eb4f

Browse files
committed
tests - move findProjectDir in tests/utils
1 parent 240f91c commit 3a6eb4f

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

tests/smoke/smoke-all.test.ts

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import {
3535
ensureLatexFileRegexMatches,
3636
} from "../verify.ts";
3737
import { readYaml, readYamlFromMarkdown } from "../../src/core/yaml.ts";
38-
import { outputForInput } from "../utils.ts";
38+
import { findProjectDir, outputForInput } from "../utils.ts";
3939
import { jupyterNotebookToMarkdown } from "../../src/command/convert/jupyter.ts";
4040
import { basename, dirname, join, relative } from "../../src/deno_ral/path.ts";
41-
import { existsSync, WalkEntry } from "fs/mod.ts";
41+
import { WalkEntry } from "fs/mod.ts";
4242
import { quarto } from "../../src/quarto.ts";
4343
import { safeExistsSync, safeRemoveSync } from "../../src/core/path.ts";
4444

@@ -240,7 +240,7 @@ for (const { path: fileName } of files) {
240240
}
241241

242242
// Get project path for this input and store it if this is a project (used for cleaning)
243-
const projectPath = findProjectDir(input);
243+
const projectPath = findProjectDir(input, /smoke-all$/);
244244
if (projectPath) testedProjects.add(projectPath);
245245

246246
// Render project before testing individual document if required
@@ -328,34 +328,11 @@ Promise.all(testFilesPromises).then(() => {
328328
}).catch((_error) => {});
329329

330330

331-
function findProjectDir(input: string): string | undefined {
332-
let dir = dirname(input);
333-
// This is used for smoke-all tests and should stop there
334-
// to avoid side effect of _quarto.yml outside of Quarto tests folders
335-
while (dir !== "" && dir !== "." && !/smoke-all$/.test(dir)) {
336-
const filename = ["_quarto.yml", "_quarto.yaml"].find((file) => {
337-
const yamlPath = join(dir, file);
338-
if (existsSync(yamlPath)) {
339-
return true;
340-
}
341-
});
342-
if (filename) {
343-
return dir;
344-
}
345-
346-
const newDir = dirname(dir); // stops at the root for both Windows and Posix
347-
if (newDir === dir) {
348-
return;
349-
}
350-
dir = newDir;
351-
}
352-
}
353-
354331
function findProjectOutputDir(input?: string, dir?: string) {
355332
if (dir === undefined && input === undefined) {
356333
throw new Error("Either input or dir must be provided");
357334
}
358-
dir = dir ?? findProjectDir(input!);
335+
dir = dir ?? findProjectDir(input!, /smoke-all$/);
359336
if (!dir) {
360337
return;
361338
}

tests/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,38 @@
88
import { basename, dirname, extname, join } from "../src/deno_ral/path.ts";
99
import { parseFormatString } from "../src/core/pandoc/pandoc-formats.ts";
1010
import { kMetadataFormat, kOutputExt } from "../src/config/constants.ts";
11+
import { safeExistsSync } from "../src/core/path.ts";
1112

1213
// caller is responsible for cleanup!
1314
export function inTempDirectory(fn: (dir: string) => unknown): unknown {
1415
const dir = Deno.makeTempDirSync();
1516
return fn(dir);
1617
}
1718

19+
// Find a _quarto.yaml file in the directory hierarchy of the input file
20+
export function findProjectDir(input: string, until?: RegExp | undefined): string | undefined {
21+
let dir = dirname(input);
22+
// This is used for smoke-all tests and should stop there
23+
// to avoid side effect of _quarto.yml outside of Quarto tests folders
24+
while (dir !== "" && dir !== "." && (until ? !until.test(dir) : true)) {
25+
const filename = ["_quarto.yml", "_quarto.yaml"].find((file) => {
26+
const yamlPath = join(dir, file);
27+
if (safeExistsSync(yamlPath)) {
28+
return true;
29+
}
30+
});
31+
if (filename) {
32+
return dir;
33+
}
34+
35+
const newDir = dirname(dir); // stops at the root for both Windows and Posix
36+
if (newDir === dir) {
37+
return;
38+
}
39+
dir = newDir;
40+
}
41+
}
42+
1843
// Gets output that should be created for this input file and target format
1944
export function outputForInput(
2045
input: string,

0 commit comments

Comments
 (0)