Path: blob/main/tests/smoke/inspect/inspect-code-cells.test.ts
12921 views
/*1* inspect-code-cells.test.ts2*3* Copyright (C) 2020-2024 Posit Software, PBC4*5*/67import { assertObjectMatch } from "https://deno.land/[email protected]/assert/assert_object_match.ts";8import { existsSync } from "../../../src/deno_ral/fs.ts";9import { } from "../../../src/project/types.ts";10import {11ExecuteOutput,12testQuartoCmd,13} from "../../test.ts";14import { assert } from "testing/asserts";1516(() => {17const input = "docs/project/book/_include.qmd";18const output = "docs/project/book/_include.json";19testQuartoCmd(20"inspect",21[input, output],22[23{24name: "inspect-code-cells",25verify: async (outputs: ExecuteOutput[]) => {26assert(existsSync(output));27const json = JSON.parse(Deno.readTextFileSync(output));28const info = json.fileInformation["docs/project/book/_include.qmd"];29const codeCells = info.codeCells;30assertObjectMatch(info.codeCells[0], {31start: 0,32end: 3,33source: "print(\"Hello, world\")\n",34language: "python",35metadata: {36"echo": true37}38});39}40}41],42{43teardown: async () => {44if (existsSync(output)) {45Deno.removeSync(output);46}47}48},49);50515253})();5455(() => {56const input = "docs/inspect/10039.qmd";57const output = "docs/inspect/_10039.json";58testQuartoCmd(59"inspect",60[input, output],61[62{63name: "inspect-tagged-metadata",64verify: async (outputs: ExecuteOutput[]) => {65assert(existsSync(output));66const json = JSON.parse(Deno.readTextFileSync(output));67const info = json.fileInformation["docs/inspect/10039.qmd"];68const codeCells = info.codeCells;69assertObjectMatch(info.codeCells[1], {70"start": 14,71"end": 18,72"file": "docs/inspect/10039.qmd",73"source": "p[[1]]\n",74"language": "r",75"metadata": {76"label": "plot",77"fig-cap": {78"value": "names(p)[[1]]",79"tag": "!expr"80}81}82});83}84}85],86{87teardown: async () => {88if (existsSync(output)) {89Deno.removeSync(output);90}91}92},93);94})();9596