Path: blob/main/tests/smoke/typst-gather/typst-gather.test.ts
6466 views
import { testQuartoCmd, Verify } from "../../test.ts";1import { assert } from "testing/asserts";2import { existsSync } from "../../../src/deno_ral/fs.ts";34// Test 1: Auto-detection from _extension.yml5const verifyPackagesCreated: Verify = {6name: "Verify typst/packages directory was created",7verify: async () => {8const packagesDir = "_extensions/test-format/typst/packages";9assert(10existsSync(packagesDir),11`Expected typst/packages directory not found: ${packagesDir}`,12);13},14};1516const verifyExamplePackageCached: Verify = {17name: "Verify @preview/example package was cached",18verify: async () => {19const packageDir =20"_extensions/test-format/typst/packages/preview/example/0.1.0";21assert(22existsSync(packageDir),23`Expected cached package not found: ${packageDir}`,24);2526// Verify typst.toml exists in the package27const manifestPath = `${packageDir}/typst.toml`;28assert(29existsSync(manifestPath),30`Expected package manifest not found: ${manifestPath}`,31);32},33};3435testQuartoCmd(36"call",37["typst-gather"],38[verifyPackagesCreated, verifyExamplePackageCached],39{40cwd: () => "smoke/typst-gather",41},42"typst-gather caches preview packages from extension templates",43);4445// Test 2: Config file with rootdir46const verifyConfigPackagesCreated: Verify = {47name: "Verify typst/packages directory was created via config",48verify: async () => {49const packagesDir = "_extensions/config-format/typst/packages";50assert(51existsSync(packagesDir),52`Expected typst/packages directory not found: ${packagesDir}`,53);54},55};5657const verifyConfigExamplePackageCached: Verify = {58name: "Verify @preview/example package was cached via config",59verify: async () => {60const packageDir =61"_extensions/config-format/typst/packages/preview/example/0.1.0";62assert(63existsSync(packageDir),64`Expected cached package not found: ${packageDir}`,65);6667const manifestPath = `${packageDir}/typst.toml`;68assert(69existsSync(manifestPath),70`Expected package manifest not found: ${manifestPath}`,71);72},73};7475testQuartoCmd(76"call",77["typst-gather"],78[verifyConfigPackagesCreated, verifyConfigExamplePackageCached],79{80cwd: () => "smoke/typst-gather/with-config",81},82"typst-gather uses rootdir from config file",83);8485// Test 3: --init-config generates config file86const verifyInitConfigCreated: Verify = {87name: "Verify typst-gather.toml was created",88verify: async () => {89assert(90existsSync("typst-gather.toml"),91"Expected typst-gather.toml to be created",92);9394// Read and verify content has rootdir95const content = Deno.readTextFileSync("typst-gather.toml");96assert(97content.includes("rootdir"),98"Expected typst-gather.toml to contain rootdir",99);100assert(101content.includes("_extensions/test-format"),102"Expected rootdir to point to extension directory",103);104},105};106107testQuartoCmd(108"call",109["typst-gather", "--init-config"],110[verifyInitConfigCreated],111{112cwd: () => "smoke/typst-gather",113teardown: async () => {114// Clean up generated config file115try {116Deno.removeSync("typst-gather.toml");117} catch {118// Ignore if already removed119}120},121},122"typst-gather --init-config generates config with rootdir",123);124125// Test 4: @local package is copied when [local] section is configured126const verifyLocalPackageCopied: Verify = {127name: "Verify @local/my-local-pkg was copied",128verify: async () => {129const packageDir =130"_extensions/local-format/typst/packages/local/my-local-pkg/0.1.0";131assert(132existsSync(packageDir),133`Expected local package not found: ${packageDir}`,134);135136const manifestPath = `${packageDir}/typst.toml`;137assert(138existsSync(manifestPath),139`Expected package manifest not found: ${manifestPath}`,140);141142const libPath = `${packageDir}/lib.typ`;143assert(existsSync(libPath), `Expected lib.typ not found: ${libPath}`);144},145};146147testQuartoCmd(148"call",149["typst-gather"],150[verifyLocalPackageCopied],151{152cwd: () => "smoke/typst-gather/with-local",153teardown: async () => {154// Clean up copied packages155try {156Deno.removeSync("_extensions/local-format/typst", { recursive: true });157} catch {158// Ignore if already removed159}160},161},162"typst-gather copies @local packages when configured",163);164165// Test 5: --init-config detects @local imports and generates [local] section166const verifyInitConfigWithLocal: Verify = {167name: "Verify --init-config detects @local imports",168verify: async () => {169assert(170existsSync("typst-gather.toml"),171"Expected typst-gather.toml to be created",172);173174const content = Deno.readTextFileSync("typst-gather.toml");175assert(176content.includes("[local]"),177"Expected typst-gather.toml to contain [local] section",178);179assert(180content.includes("my-local-pkg"),181"Expected typst-gather.toml to reference my-local-pkg",182);183assert(184content.includes("@local/my-local-pkg"),185"Expected typst-gather.toml to show found @local import",186);187},188};189190testQuartoCmd(191"call",192["typst-gather", "--init-config"],193[verifyInitConfigWithLocal],194{195cwd: () => "smoke/typst-gather/with-local",196setup: async () => {197// Remove existing config so --init-config can run198try {199Deno.renameSync("typst-gather.toml", "typst-gather.toml.bak");200} catch {201// Ignore if doesn't exist202}203},204teardown: async () => {205// Restore original config and clean up generated one206try {207Deno.removeSync("typst-gather.toml");208} catch {209// Ignore210}211try {212Deno.renameSync("typst-gather.toml.bak", "typst-gather.toml");213} catch {214// Ignore215}216},217},218"typst-gather --init-config detects @local imports",219);220221222