Skip to content

Commit f92e675

Browse files
committed
test - move findProjectOutputDir to tests/utils
1 parent 3a6eb4f commit f92e675

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

tests/smoke/smoke-all.test.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import {
3434
ensurePptxMaxSlides,
3535
ensureLatexFileRegexMatches,
3636
} from "../verify.ts";
37-
import { readYaml, readYamlFromMarkdown } from "../../src/core/yaml.ts";
38-
import { findProjectDir, outputForInput } from "../utils.ts";
37+
import { readYamlFromMarkdown } from "../../src/core/yaml.ts";
38+
import { findProjectDir, findProjectOutputDir, 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";
4141
import { WalkEntry } from "fs/mod.ts";
@@ -125,7 +125,7 @@ function resolveTestSpecs(
125125
verifyFns.push(noErrors);
126126
} else {
127127
// See if there is a project and grab it's type
128-
const projectOutDir = findProjectOutputDir(input);
128+
const projectOutDir = findProjectOutputDir(findSmokeAllProjectDir(input));
129129
const outputFile = outputForInput(input, format, projectOutDir, metadata);
130130
if (key === "fileExists") {
131131
for (
@@ -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, /smoke-all$/);
243+
const projectPath = findSmokeAllProjectDir(input);
244244
if (projectPath) testedProjects.add(projectPath);
245245

246246
// Render project before testing individual document if required
@@ -315,7 +315,7 @@ Promise.all(testFilesPromises).then(() => {
315315
// Clean up any projects that were tested
316316
for (const project of testedProjects) {
317317
// Clean project output directory
318-
const projectOutDir = join(project, findProjectOutputDir(undefined, project));
318+
const projectOutDir = join(project, findProjectOutputDir(project));
319319
if (safeExistsSync(projectOutDir)) {
320320
safeRemoveSync(projectOutDir, { recursive: true });
321321
}
@@ -327,28 +327,6 @@ Promise.all(testFilesPromises).then(() => {
327327
}
328328
}).catch((_error) => {});
329329

330-
331-
function findProjectOutputDir(input?: string, dir?: string) {
332-
if (dir === undefined && input === undefined) {
333-
throw new Error("Either input or dir must be provided");
334-
}
335-
dir = dir ?? findProjectDir(input!, /smoke-all$/);
336-
if (!dir) {
337-
return;
338-
}
339-
const yaml = readYaml(join(dir, "_quarto.yml"));
340-
let type = undefined;
341-
try {
342-
// deno-lint-ignore no-explicit-any
343-
type = ((yaml as any).project as any).type;
344-
} catch (error) {
345-
throw new Error("Failed to read quarto project YAML", error);
346-
}
347-
348-
if (type === "book") {
349-
return "_book";
350-
}
351-
if (type === "website") {
352-
return (yaml as any)?.project?.["output-dir"] || "_site";
353-
}
330+
function findSmokeAllProjectDir(input: string) {
331+
return findProjectDir(input, /smoke-all$/);
354332
}

tests/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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";
1111
import { safeExistsSync } from "../src/core/path.ts";
12+
import { readYaml } from "../src/core/yaml.ts";
1213

1314
// caller is responsible for cleanup!
1415
export function inTempDirectory(fn: (dir: string) => unknown): unknown {
@@ -40,6 +41,27 @@ export function findProjectDir(input: string, until?: RegExp | undefined): strin
4041
}
4142
}
4243

44+
export function findProjectOutputDir(projectdir: string | undefined) {
45+
if (!projectdir) {
46+
return;
47+
}
48+
const yaml = readYaml(join(projectdir, "_quarto.yml"));
49+
let type = undefined;
50+
try {
51+
// deno-lint-ignore no-explicit-any
52+
type = ((yaml as any).project as any).type;
53+
} catch (error) {
54+
throw new Error("Failed to read quarto project YAML", error);
55+
}
56+
57+
if (type === "book") {
58+
return "_book";
59+
}
60+
if (type === "website") {
61+
return (yaml as any)?.project?.["output-dir"] || "_site";
62+
}
63+
}
64+
4365
// Gets output that should be created for this input file and target format
4466
export function outputForInput(
4567
input: string,

0 commit comments

Comments
 (0)