Skip to content

Commit

Permalink
expand unit test to cover more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Oct 24, 2024
1 parent e61ed62 commit f8eef34
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions test/build-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,25 @@ describe("build", () => {
join(inputDir, "weather.md"),
"# It's going to be ${weather}!" +
"\n\n" +
"```js\nconst weather = await FileAttachment('weather.txt').text(); display(weather);\n```"
"```js\nconst weather = await FileAttachment('weather.txt').text(); display(weather);\n```" +
"\n\n" +
"```js\nconst generated = await FileAttachment('generated.txt').text(); display(generated);\n```" +
"\n\n" +
"```js\nconst thing = await FileAttachment('parameterized-thing.txt').text(); display(thing);\n```"
);
await mkdir(join(inputDir, "cities"));
await writeFile(join(inputDir, "cities", "index.md"), "# Cities");
await writeFile(join(inputDir, "cities", "portland.md"), "# Portland");
// A non-page file that should not be included
await writeFile(join(inputDir, "weather.txt"), "sunny");
await writeFile(join(inputDir, "generated.txt.ts"), "process.stdout.write('hello');");
await writeFile(join(inputDir, "weather.txt"), "sunny");
await writeFile(join(inputDir, "parameterized-[page].txt.ts"), "process.stdout.write('hello');");
await writeFile(join(inputDir, "module-[page].js"), "console.log(observable.params.page);");

const outputDir = await mkdtemp(tmpPrefix + "output-");
const cacheDir = await mkdtemp(tmpPrefix + "output-");

const config = normalizeConfig({root: inputDir, output: outputDir}, inputDir);
const config = normalizeConfig({root: inputDir, output: outputDir, dynamicPaths: ["/module-thing.js"]}, inputDir);
const effects = new LoggingBuildEffects(outputDir, cacheDir);
await build({config}, effects);
effects.buildManifest!.pages.sort((a, b) => ascending(a.path, b.path));
Expand All @@ -144,8 +151,12 @@ describe("build", () => {
{path: "/cities/portland", title: "Portland", source: "/cities/portland.md"},
{path: "/weather", title: "It's going to be !", source: "/weather.md"}
],
files: [{path: "/weather.txt"}],
modules: []
files: [
{path: "/weather.txt"},
{path: "/generated.txt", source: "/generated.txt.ts"},
{path: "/parameterized-thing.txt", source: "/parameterized-[page].txt.ts", params: {page: "thing"}}
],
modules: [{path: "/module-thing.js", source: "/module-[page].js", params: {page: "thing"}}]
});

await Promise.all([inputDir, cacheDir, outputDir].map((dir) => rm(dir, {recursive: true}))).catch(() => {});
Expand Down

0 comments on commit f8eef34

Please sign in to comment.