diff --git a/apps/vscode/src/test/examples/generated_snapshots/roundtripped-valid-basics-2.qmd b/apps/vscode/src/test/examples/generated_snapshots/roundtripped-valid-basics-2.qmd
new file mode 100644
index 00000000..f61d8314
--- /dev/null
+++ b/apps/vscode/src/test/examples/generated_snapshots/roundtripped-valid-basics-2.qmd
@@ -0,0 +1,68 @@
+---
+bibliography: references.bib
+---
+
+Welcome to valid basics 2.
+
+```{=html}
+
hi
+```
+
+`hi`{=html}
+
+```{{r}}
+1 + 1
+```
+
+> This is a block quote this is the same block quote
+
+| this is a line block
+| this is another line block
+
+This is *emphasized* text
+
+This is also *emphasized* text
+
+hello [underline]{.underline} ~~strikethrough~~ ^super^ ~sub~ [smallcaps]{.smallcaps}
+
+
+
+definition term
+
+: definition content
+
+definition term 2
+
+: definition content 2
+
+------------------------------------------------------------------------
+
+::: {#thm-pythagoras}
+#### Pythagoras's Theorem
+
+In a right triangle, the lengths of the two shorter sides $a$, $b$ and the longer side $c$ stand in the relation $$
+a^2 + b^2 = c^2.
+$$
+:::
+
+See @thm-pythagoras for details.
+
+{{< meta title >}}
+
+| Col1 | Col2 | Col3 |
+|------|------|-----:|
+| 11 | 21 | 31 |
+| 12 | 22 | 32 |
+| 13 | 23 | 33 |
+
+: table caption
+
+@riehl2023
+
+[@riehl2023]
+
+hey footnote[^1]
+
+[^1]: hello I'm a foot node
+
+be careful of newline at end of file, roundtripping removes it:
\ No newline at end of file
diff --git a/apps/vscode/src/test/examples/generated_snapshots/roundtripped-valid-nesting.qmd b/apps/vscode/src/test/examples/generated_snapshots/roundtripped-valid-nesting.qmd
new file mode 100644
index 00000000..4d55280a
--- /dev/null
+++ b/apps/vscode/src/test/examples/generated_snapshots/roundtripped-valid-nesting.qmd
@@ -0,0 +1,33 @@
+````{=markdown}
+```{=markdown}
+hi
+```
+````
+
+```{{python}}
+a = 3
+```
+
+> ```
+> 1+1
+> ```
+>
+> $$
+> 3 = 1 + 1 + 1 = 2 + 1 = 1 + 2
+> $$
+>
+> > block quote in block quote
+>
+> +-----+-------+
+> | $$ | ``` r |
+> | 1+0 | 1+1 |
+> | $$ | ``` |
+> +-----+-------+
+> | 3 | 4 |
+> +-----+-------+
+>
+> : my table caption
+>
+> ::: hello
+> fenced div in block quote
+> :::
\ No newline at end of file
diff --git a/apps/vscode/src/test/examples/references.bib b/apps/vscode/src/test/examples/references.bib
new file mode 100644
index 00000000..987851be
--- /dev/null
+++ b/apps/vscode/src/test/examples/references.bib
@@ -0,0 +1,14 @@
+@article{riehl2023,
+ title = {Could ∞-Category Theory Be Taught to Undergraduates?},
+ author = {Riehl, Emily},
+ year = {2023},
+ month = {05},
+ date = {2023-05-01},
+ journal = {Notices of the American Mathematical Society},
+ pages = {1},
+ volume = {70},
+ number = {05},
+ doi = {10.1090/noti2692},
+ url = {http://dx.doi.org/10.1090/noti2692},
+ langid = {en}
+}
diff --git a/apps/vscode/src/test/examples/roundtrip-changes.qmd b/apps/vscode/src/test/examples/roundtrip-changes.qmd
deleted file mode 100644
index ea5236fb..00000000
--- a/apps/vscode/src/test/examples/roundtrip-changes.qmd
+++ /dev/null
@@ -1,15 +0,0 @@
-``````{=markdown}
-```{=markdown}
-hi
-```
-``````
-
-`````
-```{python}
-a = 3
-````
-`````
-
-_YO!_
-
-be careful of newline at end of file, roundtripping removes it:
diff --git a/apps/vscode/src/test/examples/valid-basics-2.qmd b/apps/vscode/src/test/examples/valid-basics-2.qmd
new file mode 100644
index 00000000..0f430289
--- /dev/null
+++ b/apps/vscode/src/test/examples/valid-basics-2.qmd
@@ -0,0 +1,69 @@
+---
+bibliography: references.bib
+---
+
+Welcome to valid basics 2.
+
+```{=html}
+hi
+```
+
+`hi`{=html}
+
+```{{r}}
+1 + 1
+```
+
+> This is a block quote
+> this is the same block quote
+
+| this is a line block
+| this is another line block
+
+This is *emphasized* text
+
+This is also _emphasized_ text
+
+hello [underline]{.underline} ~~strikethrough~~ ^super^ ~sub~ [smallcaps]{.smallcaps}
+
+
+
+definition term
+
+: definition content
+
+definition term 2
+
+: definition content 2
+
+------------------------------------------------------------------------
+
+::: {#thm-pythagoras}
+#### Pythagoras's Theorem
+In a right triangle, the lengths of the two shorter sides $a$, $b$ and the longer side $c$ stand in the relation
+$$
+a^2 + b^2 = c^2.
+$$
+:::
+
+See @thm-pythagoras for details.
+
+{{< meta title >}}
+
+| Col1 | Col2 | Col3 |
+|------|------|-----:|
+| 11 | 21 | 31 |
+| 12 | 22 | 32 |
+| 13 | 23 | 33 |
+
+: table caption
+
+@riehl2023
+
+[@riehl2023]
+
+hey footnote[^1]
+
+[^1]: hello I'm a foot node
+
+be careful of newline at end of file, roundtripping removes it:
diff --git a/apps/vscode/src/test/examples/valid-nesting.qmd b/apps/vscode/src/test/examples/valid-nesting.qmd
new file mode 100644
index 00000000..8bd3ed3d
--- /dev/null
+++ b/apps/vscode/src/test/examples/valid-nesting.qmd
@@ -0,0 +1,35 @@
+``````{=markdown}
+```{=markdown}
+hi
+```
+``````
+
+````
+```{python}
+a = 3
+```
+````
+
+> ```
+> 1+1
+> ```
+>
+> $$
+> 3 = 1 + 1 + 1 = 2 + 1 = 1 + 2
+> $$
+>
+> > block quote in block quote
+>
+> +-----+-------+
+> | $$ | ``` r |
+> | 1+0 | 1+1 |
+> | $$ | ``` |
+> +-----+-------+
+> | 3 | 4 |
+> +-----+-------+
+>
+> : my table caption
+>
+> ::: hello
+> fenced div in block quote
+> :::
diff --git a/apps/vscode/src/test/quartoDoc.test.ts b/apps/vscode/src/test/quartoDoc.test.ts
index 4b27cbce..aeb88526 100644
--- a/apps/vscode/src/test/quartoDoc.test.ts
+++ b/apps/vscode/src/test/quartoDoc.test.ts
@@ -30,38 +30,34 @@ suite("Quarto basics", function () {
assert.equal(before, after);
});
- test("Roundtrip changes roundtrip-changes.qmd", async function () {
- // We want this test to fail locally so that we can reference the
- // before/affter diff that Mocha logs, but we dont wan't CI to fail.
- if (process.env['CI']) this.skip();
+ roundtripSnapshotTest('valid-basics.qmd');
- const { doc } = await openAndShowTextDocument("roundtrip-changes.qmd");
+ roundtripSnapshotTest('valid-basics-2.qmd');
- const { before, after } = await roundtrip(doc);
-
- assert.equal(before, after);
- });
+ roundtripSnapshotTest('valid-nesting.qmd');
- test("Roundtripped valid-basics.qmd matches snapshot", async function () {
- const { doc } = await openAndShowTextDocument("valid-basics.qmd");
+ roundtripSnapshotTest('invalid.qmd');
- const { after } = await roundtrip(doc);
-
- assert.equal(after, await readOrCreateSnapshot("roundtripped-valid-basics.qmd", after));
- });
-
- test("Roundtripped invalid.qmd matches snapshot", async function () {
- const { doc } = await openAndShowTextDocument("invalid.qmd");
-
- const { after } = await roundtrip(doc);
+ roundtripSnapshotTest('capsule-leak.qmd');
+});
- assert.equal(after, await readOrCreateSnapshot("roundtripped-invalid.qmd", after));
- });
- test("Roundtripped capsule-leak.qmd matches snapshot", async function () {
- const { doc } = await openAndShowTextDocument("capsule-leak.qmd");
+/**
+ *
+ * When the test is run on the dev's machine for the first time, saves the roundtripped file as a snapshot.
+ * All subsequent runs of the test compare the roundtripped file to that snapshot.
+ *
+ * Useful for capturing the behaviour of roundtripping at a point in time and testing against that.
+ *
+ * @param filename A .qmd file in the examples folder to snapshot test
+ */
+function roundtripSnapshotTest(filename: string) {
+ const snapshotFileName = `roundtripped-${filename}`;
+
+ test(`Roundtripped ${filename} matches snapshot`, async function () {
+ const { doc } = await openAndShowTextDocument(filename);
const { after } = await roundtrip(doc);
- assert.equal(after, await readOrCreateSnapshot("roundtripped-capsule-leak.qmd", after));
+ assert.equal(after, await readOrCreateSnapshot(snapshotFileName, after));
});
-});
+}
diff --git a/apps/vscode/src/test/test-utils.ts b/apps/vscode/src/test/test-utils.ts
index 75c38efa..c6ce53c5 100644
--- a/apps/vscode/src/test/test-utils.ts
+++ b/apps/vscode/src/test/test-utils.ts
@@ -49,15 +49,28 @@ export async function roundtrip(doc: vscode.TextDocument) {
return { before, after };
}
+const YELLOW_COLOR_ESCAPE_CODE = '\x1b[33m';
+const RESET_COLOR_ESCAPE_CODE = '\x1b[0m';
+
export async function readOrCreateSnapshot(fileName: string, content: string) {
const snapshotUri = examplesUri(path.join('generated_snapshots', fileName));
try {
const doc = await vscode.workspace.openTextDocument(snapshotUri);
return doc.getText();
} catch {
+ if (process.env['CI']) throw 'Attempted to create snapshot in CI!';
+
+ console.warn(`${YELLOW_COLOR_ESCAPE_CODE}
+⚠︎ Created snapshot in file:
+${snapshotUri}
+ Please take a look at the snapshot file and ensure it is what you expect
+ If it looks good to you, please commit the generated snapshot along with your test code
+ If you did not intend to create a snapshot, please carefully check your test code and delete the snapshot file
+${RESET_COLOR_ESCAPE_CODE}`);
+
await vscode.workspace.fs.writeFile(
snapshotUri,
- Buffer.from(content, 'utf8')
+ Buffer.from(content, 'utf8') as Uint8Array
);
return content;
}