Path: blob/main/tests/smoke/project/project-book.test.ts
12925 views
/*1* project-render.test.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*/5import { existsSync } from "../../../src/deno_ral/fs.ts";6import { join } from "../../../src/deno_ral/path.ts";7import { Metadata } from "../../../src/config/types.ts";89import { testQuartoCmd, Verify } from "../../test.ts";10import { docs } from "../../utils.ts";11import {12directoryEmptyButFor,13fileExists,14verifyYamlFile,15} from "../../verify.ts";1617import {18cleanWorking,19kProjectWorkingDir,20kQuartoProjectFile,21} from "./common.ts";2223// A book project24testQuartoCmd(25"create-project",26[kProjectWorkingDir, "--type", "book"],27[28fileExists(kQuartoProjectFile),29fileExists(join(kProjectWorkingDir, "index.qmd")),30fileExists(join(kProjectWorkingDir, "references.bib")),31verifyYamlFile(32kQuartoProjectFile,33(yaml: unknown) => {34// Make sure there is a project yaml section35const metadata = yaml as Metadata;36if (37metadata["project"] !== undefined && metadata["book"] !== undefined38) {39const type = (metadata["project"] as Metadata)["type"];40return type === "book";41} else {42return false;43}44},45),46],47{48setup: cleanWorking,49teardown: cleanWorking,50},51);5253// Book render54const outDir = "_book";55const bookProjDir = docs("project/book");56const bookOutDir = join(bookProjDir, outDir);5758const bookPdfDir = bookOutDir;59const verifyPdfBook: Verify[] = [60fileExists(join(bookPdfDir, "book.pdf")),61directoryEmptyButFor(bookPdfDir, ["book.pdf"]),62];63testQuartoCmd(64"render",65[bookProjDir, "--to", "pdf"],66verifyPdfBook,67{68teardown: async () => {69if (existsSync(bookOutDir)) {70await Deno.remove(bookOutDir, { recursive: true });71}72},73},74);7576const bookDocxDir = bookOutDir;77const verifyDocxBook: Verify[] = [78fileExists(join(bookDocxDir, "book.docx")),79directoryEmptyButFor(bookDocxDir, ["book.docx"]),80];81testQuartoCmd(82"render",83[bookProjDir, "--to", "docx"],84verifyDocxBook,85{86teardown: async () => {87if (existsSync(bookOutDir)) {88await Deno.remove(bookOutDir, { recursive: true });89}90},91},92);9394const bookEpubDir = bookOutDir;95const verifyEpubBook: Verify[] = [96fileExists(join(bookEpubDir, "book.epub")),97directoryEmptyButFor(bookEpubDir, ["book.epub"]),98];99testQuartoCmd(100"render",101[bookProjDir, "--to", "epub"],102verifyEpubBook,103{104teardown: async () => {105if (existsSync(bookOutDir)) {106await Deno.remove(bookOutDir, { recursive: true });107}108},109},110);111112const verifyHtmlBook: Verify[] = [113"index.html",114"intro.html",115"references.html",116"search.json",117"site_libs",118"summary.html",119].map((path) => {120return fileExists(join(bookOutDir, path));121});122testQuartoCmd(123"render",124[bookProjDir, "--to", "html"],125verifyHtmlBook,126{127teardown: async () => {128if (existsSync(bookOutDir)) {129await Deno.remove(bookOutDir, { recursive: true });130}131},132},133);134135136