Skip to content

Latest commit

 

History

History
111 lines (84 loc) · 2.81 KB

File metadata and controls

111 lines (84 loc) · 2.81 KB
paths
tests/smoke/**/*.test.ts
tests/unit/**/*.test.ts

TypeScript Tests

TypeScript-based tests using Deno. Smoke tests render documents; unit tests verify isolated functionality.

Running Tests

# Linux/macOS
./run-tests.sh smoke/render/render.test.ts    # Specific smoke test
./run-tests.sh unit/path.test.ts              # Specific unit test
./run-tests.sh smoke/extensions/              # Directory

# Windows
.\run-tests.ps1 smoke/render/render.test.ts

Core Infrastructure

File Purpose
tests/test.ts testQuartoCmd(), testRender(), unitTest()
tests/verify.ts Verification functions (noErrors, fileExists, etc.)
tests/utils.ts docs(), outputForInput(), path utilities

Smoke Tests (tests/smoke/)

Render documents and verify output:

import { testRender } from "./render.ts";
import { noErrorsOrWarnings } from "../../verify.ts";
import { docs } from "../../utils.ts";

testRender(
  "test.qmd",
  "html",
  false,                // Keep output?
  [noErrorsOrWarnings],
  { cwd: () => docs("my-feature/") }
);

With setup/teardown:

testRender("test.qmd", "html", false, [noErrorsOrWarnings], {
  cwd: () => inputDir,
  setup: async () => { /* Create temp files */ },
  teardown: async () => { /* Cleanup */ },
});

Unit Tests (tests/unit/)

Test isolated functionality:

import { unitTest } from "../test.ts";
import { assert, assertEquals } from "testing/asserts";

// deno-lint-ignore require-await
unitTest("feature - description", async () => {
  const result = myFunction(input);
  assertEquals(result, expected);
});

Assertions from testing/asserts: assert, assertEquals, assertThrows, assertRejects

Common Patterns

Temp files:

const workingDir = Deno.makeTempDirSync({ prefix: "quarto-test" });
// Use workingDir, clean up in teardown

Fixtures:

const fixtureDir = docs("my-fixture");  // → tests/docs/my-fixture/

Test Organization

  • tests/smoke/<feature>/ - Smoke tests by feature
  • tests/unit/<feature>/ - Unit tests by feature
  • tests/docs/<feature>/ - Test fixtures

Details: llm-docs/testing-patterns.md for comprehensive patterns and examples.

Common Test Utilities

Constructing MappedString values:

import { asMappedString } from "../../../src/core/lib/mapped-text.ts";

// Use asMappedString("") instead of casting or constructing MappedString manually
const markdown = asMappedString("");
const markdownWithContent = asMappedString("# Title\nSome content");

Mock ProjectContext:

import { createMockProjectContext } from "./utils.ts";  // tests/unit/project/utils.ts
const project = createMockProjectContext();  // Creates temp dir + FileInformationCacheMap