Skip to content

Commit b1a606a

Browse files
committed
test - auto detect project output directory now
this better handle project accross all our tests
1 parent 494a5f0 commit b1a606a

File tree

9 files changed

+39
-49
lines changed

9 files changed

+39
-49
lines changed

tests/smoke/extensions/extension-render-project.test.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,20 @@
44
* Copyright (C) 2020-2022 Posit Software, PBC
55
*/
66

7-
import { docs } from "../../utils.ts";
7+
import { docs, projectOutputForInput } from "../../utils.ts";
88

99
import { basename, dirname, extname, join, relative } from "../../../src/deno_ral/path.ts";
1010
import { ensureHtmlElements } from "../../verify.ts";
1111
import { testQuartoCmd } from "../../test.ts";
1212
import { noErrors } from "../../verify.ts";
1313
import { existsSync } from "fs/mod.ts";
1414

15-
const siteOutputForInput = (rootDir: string, input: string) => {
16-
const dir = join(rootDir, "_site");
17-
const stem = basename(input, extname(input));
18-
19-
const outputPath = join(
20-
dir,
21-
dirname(relative(rootDir, input)),
22-
`${stem}.html`,
23-
);
24-
const supportPath = join(dir, `site_libs`);
25-
26-
return {
27-
outputPath,
28-
supportPath,
29-
};
30-
};
31-
3215
const testRender = (
33-
rootDir: string,
3416
input: string,
3517
includeSelectors: string[],
3618
excludeSelectors: string[],
3719
) => {
38-
const output = siteOutputForInput(rootDir, input);
20+
const output = projectOutputForInput(input);
3921
const verifySel = ensureHtmlElements(
4022
output.outputPath,
4123
includeSelectors,
@@ -63,8 +45,7 @@ const rootDir = docs("extensions/project/");
6345

6446
// Render the home page and verify the output
6547
// contains the extension shortcodes and filter elements
66-
const rootInput = join(rootDir, "posts/welcome/index.qmd");
67-
testRender(rootDir, rootInput, [
48+
testRender(join(rootDir, "posts/welcome/index.qmd"), [
6849
"a.lightbox",
6950
"i.fa-solid.fa-anchor",
7051
"i.fa-solid.fa-bacteria",
@@ -74,7 +55,7 @@ testRender(rootDir, rootInput, [
7455
// Render the welcome page (subdirectory) and verify the output
7556
// contains the extension shortcodes and filter elements
7657
const subdirInput = join(rootDir, "posts/welcome/index.qmd");
77-
testRender(rootDir, subdirInput, [
58+
testRender(join(rootDir, "posts/welcome/index.qmd"), [
7859
"a.lightbox",
7960
"i.fa-solid.fa-anchor",
8061
"i.fa-solid.fa-bacteria",

tests/smoke/jats/render-manuscript.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import { ensureMECAValidates, ensureXmlValidatesWithXsd } from "../../verify.ts"
1111
import { testRender } from "../render/render.ts";
1212

1313
const xsdPath = docs(join("jats", "xsd", "JATS-Archiving-1-2-MathML2-DTD"));
14-
const projectOutDir = "_manuscript";
1514

1615
const testContext = undefined;
1716
const args = undefined;
1817

1918
// Test a basic manuscript render (this will include a sub-notebook which should
2019
// nonetheless validate)
2120
const input = docs(join("jats", "manuscript", "index.ipynb"));
22-
const output = outputForInput(input, "jats", projectOutDir);
21+
const output = outputForInput(input, "jats");
2322
const mecaOutput = join(dirname(output.outputPath), "index-meca.zip");
2423

2524
// Test the article and ensure that it validates
@@ -29,6 +28,5 @@ testRender(
2928
false,
3029
[ensureXmlValidatesWithXsd(output.outputPath, xsdPath), ensureMECAValidates(mecaOutput)],
3130
testContext,
32-
args,
33-
projectOutDir,
31+
args
3432
);

tests/smoke/project/common.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ export async function cleanWorking() {
2121

2222
export type OutputVerify = (outputDir: string) => Verify[];
2323

24+
// This is similar to testSite.
25+
// It tests a project render, and allow to verify output directory assertions
2426
export const testProjectRender = (
2527
input: string,
2628
to: string,
27-
outputDir: string,
28-
outputVerify: OutputVerify
29+
outputVerify: OutputVerify = (_outDir: string): Verify[] => [],
2930
) => {
3031

31-
const output = outputForInput(input, to, outputDir);
32+
const output = outputForInput(input, to);
3233
const outDir = dirname(output.outputPath);
3334
const outVerify = outputVerify(outDir);
3435

tests/smoke/render/render-email.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ testRender(docs("email/email-attach.qmd"), "email", false, [fileExists(previewFi
3838
// Test an email render that has no subject line, this verifies that `rsc_email_subject` key is present and the value is an empty string
3939
testRender(docs("email/email-no-subject.qmd"), "email", false, [fileExists(previewFile), validJsonWithFields(jsonFile, {"rsc_email_subject": ""})], cleanupCtx);
4040

41-
// Render in a project with an output directory and confirm that everything ends up in the output directory
42-
testProjectRender(docs("email/project/email-attach.qmd"), "email", "_out", (outputDir: string) => {
41+
// Render in a project with an output directory set in _quarto.yml and confirm that everything ends up in the output directory
42+
testProjectRender(docs("email/project/email-attach.qmd"), "email", (outputDir: string) => {
4343
const verify: Verify[]= [];
4444
const json = join(outputDir, ".output_metadata.json");
4545
const preview = join(outputDir, "email-preview", "index.html");

tests/smoke/render/render.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ export function cleanoutput(
8080
input: string,
8181
to: string,
8282
projectOutDir?: string,
83+
projectRoot?: string,
8384
// deno-lint-ignore no-explicit-any
8485
metadata?: Record<string, any>,
8586
) {
86-
const out = outputForInput(input, to, projectOutDir, metadata);
87+
const out = outputForInput(input, to, projectOutDir, projectRoot, metadata);
8788
if (safeExistsSync(out.outputPath)) {
8889
safeRemoveSync(out.outputPath);
8990
}

tests/smoke/site/render-shortcode-navbar.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (C) 2020-2022 Posit Software, PBC
55
*
66
*/
7-
import { docs, siteOutputForInput } from "../../utils.ts";
7+
import { docs, projectOutputForInput } from "../../utils.ts";
88
import { ensureFileRegexMatches } from "../../verify.ts";
99
import { testSite } from "./site.ts";
1010

@@ -14,7 +14,7 @@ testSite(
1414
[],
1515
[],
1616
ensureFileRegexMatches(
17-
siteOutputForInput(docs("websites/issue-3686/index.qmd"))
17+
projectOutputForInput(docs("websites/issue-3686/index.qmd"))
1818
.outputPath,
1919
[],
2020
[/\{\{\&lt\;/, /\&gt\;\}\}/],

tests/smoke/site/site.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { existsSync } from "fs/mod.ts";
77
import { dirname } from "../../../src/deno_ral/path.ts";
88
import { testQuartoCmd, Verify } from "../../test.ts";
9-
import { siteOutputForInput } from "../../utils.ts";
9+
import { projectOutputForInput } from "../../utils.ts";
1010
import { ensureHtmlElements, noErrorsOrWarnings } from "../../verify.ts";
1111

1212
export const testSite = (
@@ -16,7 +16,7 @@ export const testSite = (
1616
excludeSelectors: string[],
1717
...verify: Verify[]
1818
) => {
19-
const output = siteOutputForInput(input);
19+
const output = projectOutputForInput(input);
2020

2121
const verifySel = ensureHtmlElements(
2222
output.outputPath,

tests/smoke/smoke-all.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ function resolveTestSpecs(
125125
verifyFns.push(noErrors);
126126
} else {
127127
// See if there is a project and grab it's type
128-
const projectOutDir = findProjectOutputDir(findSmokeAllProjectDir(input));
129-
const outputFile = outputForInput(input, format, projectOutDir, metadata);
128+
const projectPath = findSmokeAllProjectDir(input)
129+
const projectOutDir = findProjectOutputDir(projectPath);
130+
const outputFile = outputForInput(input, format, projectOutDir, projectPath, metadata);
130131
if (key === "fileExists") {
131132
for (
132133
const [path, file] of Object.entries(
@@ -284,7 +285,7 @@ for (const { path: fileName } of files) {
284285
return Promise.resolve(true);
285286
},
286287
teardown: () => {
287-
cleanoutput(input, format, undefined, metadata);
288+
cleanoutput(input, format, undefined, undefined, metadata);
288289
testSpecResolve(); // Resolve the promise for the testSpec
289290
return Promise.resolve();
290291
},

tests/utils.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*/
77

8-
import { basename, dirname, extname, join } from "../src/deno_ral/path.ts";
8+
import { basename, dirname, extname, join, relative } 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";
@@ -73,11 +73,14 @@ export function outputForInput(
7373
input: string,
7474
to: string,
7575
projectOutDir?: string,
76+
projectRoot?: string,
7677
// deno-lint-ignore no-explicit-any
7778
metadata?: Record<string, any>,
7879
) {
7980
// TODO: Consider improving this (e.g. for cases like Beamer, or typst)
80-
const dir = dirname(input);
81+
projectRoot = projectRoot ?? findProjectDir(input);
82+
projectOutDir = projectOutDir ?? findProjectOutputDir(projectRoot);
83+
const dir = projectRoot ? relative(projectRoot, dirname(input)) : dirname(input);
8184
let stem = basename(input, extname(input));
8285
let ext = metadata?.[kMetadataFormat]?.[to]?.[kOutputExt];
8386

@@ -139,11 +142,11 @@ export function outputForInput(
139142
}
140143
}
141144

142-
const outputPath = projectOutDir
143-
? join(dir, projectOutDir, `${stem}.${outputExt}`)
144-
: join(dir, `${stem}.${outputExt}`);
145-
const supportPath = projectOutDir
146-
? join(dir, projectOutDir, `${stem}_files`)
145+
const outputPath: string = projectRoot && projectOutDir
146+
? join(projectRoot, projectOutDir, dir, `${stem}.${outputExt}`)
147+
: join(dir, `${stem}.${outputExt}`);
148+
const supportPath: string = projectRoot && projectOutDir
149+
? join(projectRoot, projectOutDir, dir, `${stem}_files`)
147150
: join(dir, `${stem}_files`);
148151

149152
return {
@@ -152,8 +155,13 @@ export function outputForInput(
152155
};
153156
}
154157

155-
export function siteOutputForInput(input: string) {
156-
const dir = join(dirname(input), "_site");
158+
export function projectOutputForInput(input: string) {
159+
const projectDir = findProjectDir(input);
160+
const projectOutDir = findProjectOutputDir(projectDir);
161+
if (!projectDir) {
162+
throw new Error("No project directory found");
163+
}
164+
const dir = join(projectDir, projectOutDir, relative(projectDir, dirname(input)));
157165
const stem = basename(input, extname(input));
158166

159167
const outputPath = join(dir, `${stem}.html`);

0 commit comments

Comments
 (0)