@@ -30,38 +30,34 @@ suite("Quarto basics", function () {
3030 assert . equal ( before , after ) ;
3131 } ) ;
3232
33- test ( "Roundtrip changes roundtrip-changes.qmd" , async function ( ) {
34- // We want this test to fail locally so that we can reference the
35- // before/affter diff that Mocha logs, but we dont wan't CI to fail.
36- if ( process . env [ 'CI' ] ) this . skip ( ) ;
33+ roundtripSnapshotTest ( 'valid-basics.qmd' ) ;
3734
38- const { doc } = await openAndShowTextDocument ( "roundtrip-changes .qmd" ) ;
35+ roundtripSnapshotTest ( 'valid-basics-2 .qmd' ) ;
3936
40- const { before, after } = await roundtrip ( doc ) ;
41-
42- assert . equal ( before , after ) ;
43- } ) ;
37+ roundtripSnapshotTest ( 'valid-nesting.qmd' ) ;
4438
45- test ( "Roundtripped valid-basics.qmd matches snapshot" , async function ( ) {
46- const { doc } = await openAndShowTextDocument ( "valid-basics.qmd" ) ;
39+ roundtripSnapshotTest ( 'invalid.qmd' ) ;
4740
48- const { after } = await roundtrip ( doc ) ;
49-
50- assert . equal ( after , await readOrCreateSnapshot ( "roundtripped-valid-basics.qmd" , after ) ) ;
51- } ) ;
52-
53- test ( "Roundtripped invalid.qmd matches snapshot" , async function ( ) {
54- const { doc } = await openAndShowTextDocument ( "invalid.qmd" ) ;
55-
56- const { after } = await roundtrip ( doc ) ;
41+ roundtripSnapshotTest ( 'capsule-leak.qmd' ) ;
42+ } ) ;
5743
58- assert . equal ( after , await readOrCreateSnapshot ( "roundtripped-invalid.qmd" , after ) ) ;
59- } ) ;
60- test ( "Roundtripped capsule-leak.qmd matches snapshot" , async function ( ) {
61- const { doc } = await openAndShowTextDocument ( "capsule-leak.qmd" ) ;
44+ /**
45+ *
46+ * When the test is run on the dev's machine for the first time, saves the roundtripped file as a snapshot.
47+ * All subsequent runs of the test compare the roundtripped file to that snapshot.
48+ *
49+ * Useful for capturing the behaviour of roundtripping at a point in time and testing against that.
50+ *
51+ * @param filename A .qmd file in the examples folder to snapshot test
52+ */
53+ function roundtripSnapshotTest ( filename : string ) {
54+ const snapshotFileName = `roundtripped-${ filename } ` ;
55+
56+ test ( `Roundtripped ${ filename } matches snapshot` , async function ( ) {
57+ const { doc } = await openAndShowTextDocument ( filename ) ;
6258
6359 const { after } = await roundtrip ( doc ) ;
6460
65- assert . equal ( after , await readOrCreateSnapshot ( "roundtripped-capsule-leak.qmd" , after ) ) ;
61+ assert . equal ( after , await readOrCreateSnapshot ( snapshotFileName , after ) ) ;
6662 } ) ;
67- } ) ;
63+ }
0 commit comments