shikiHighlighter.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. createRawCodeTokens,
  4. highlightCode,
  5. shouldUseSyntaxHighlighting,
  6. } from "@/lib/shikiHighlighter.js";
  7. describe("shikiHighlighter", () => {
  8. it("keeps plain text code fences out of the async highlighter", () => {
  9. expect(shouldUseSyntaxHighlighting("text")).toBe(false);
  10. expect(shouldUseSyntaxHighlighting("plaintext")).toBe(false);
  11. expect(shouldUseSyntaxHighlighting("log")).toBe(false);
  12. expect(shouldUseSyntaxHighlighting("not-a-real-language")).toBe(false);
  13. });
  14. it("allows known languages and aliases to use syntax highlighting", () => {
  15. expect(shouldUseSyntaxHighlighting("json")).toBe(true);
  16. expect(shouldUseSyntaxHighlighting("typescript")).toBe(true);
  17. expect(shouldUseSyntaxHighlighting("tsx")).toBe(true);
  18. });
  19. it("returns raw tokens for plain text without registering async callbacks", () => {
  20. let callbackCount = 0;
  21. const code = [
  22. '"next start" does not work with "output: standalone" configuration.',
  23. 'Use "node .next/standalone/server.js" instead.',
  24. ].join("\n");
  25. const tokenized = highlightCode(code, "text", "github-light", () => {
  26. callbackCount += 1;
  27. });
  28. expect(tokenized).toEqual(createRawCodeTokens(code));
  29. expect(callbackCount).toBe(0);
  30. });
  31. });