11import  *  as  vscode  from  "vscode" ; 
22import  *  as  assert  from  "assert" ; 
3- import  {  WORKSPACE_PATH ,  examplesOutUri ,  wait  }  from  "./test-utils" ; 
3+ import  {  WORKSPACE_PATH ,  readOrCreateSnapshot ,   examplesOutUri ,  wait ,   roundtrip ,   openAndShowTextDocument  }  from  "./test-utils" ; 
44import  {  isQuartoDoc  }  from  "../core/doc" ; 
5- import  {  extension  }  from  "./extension" ; 
65
7- const  APPROX_TIME_TO_OPEN_VISUAL_EDITOR  =  1700 ; 
86
97suite ( "Quarto basics" ,  function  ( )  { 
108  // Before running tests, copy `./examples` to a new folder `./examples-out`. 
@@ -15,8 +13,7 @@ suite("Quarto basics", function () {
1513  } ) ; 
1614
1715  test ( "Can open a Quarto document" ,  async  function  ( )  { 
18-     const  doc  =  await  vscode . workspace . openTextDocument ( examplesOutUri ( "hello.qmd" ) ) ; 
19-     const  editor  =  await  vscode . window . showTextDocument ( doc ) ; 
16+     const  {  editor }  =  await  openAndShowTextDocument ( "hello.qmd" ) ; 
2017
2118    assert . strictEqual ( editor ?. document . languageId ,  "quarto" ) ; 
2219    assert . strictEqual ( isQuartoDoc ( editor ?. document ) ,  true ) ; 
@@ -26,40 +23,38 @@ suite("Quarto basics", function () {
2623  //       test. That's okay for this test, but could cause issues if you expect a qmd to look how it 
2724  //       does in `/examples`. 
2825  test ( "Roundtrip doesn't change hello.qmd" ,  async  function  ( )  { 
29-     const  doc  =  await  vscode . workspace . openTextDocument ( examplesOutUri ( "hello.qmd" ) ) ; 
30-     const  editor  =  await  vscode . window . showTextDocument ( doc ) ; 
26+     const  {  doc }  =  await  openAndShowTextDocument ( "hello.qmd" ) ; 
3127
3228    const  {  before,  after }  =  await  roundtrip ( doc ) ; 
3329
3430    assert . equal ( before ,  after ) ; 
3531  } ) ; 
3632
37-   test ( "Roundtrip does change  roundtrip-failures .qmd" ,  async  function  ( )  { 
33+   test ( "Roundtrip changes  roundtrip-changes .qmd" ,  async  function  ( )  { 
3834    // We want this test to fail locally so that we can reference the 
3935    // before/affter diff that Mocha logs, but we dont wan't CI to fail. 
4036    if  ( process . env [ 'CI' ] )  this . skip ( ) ; 
4137
42-     const  doc  =  await  vscode . workspace . openTextDocument ( examplesOutUri ( "roundtrip-failures.qmd" ) ) ; 
43-     const  editor  =  await  vscode . window . showTextDocument ( doc ) ; 
38+     const  {  doc }  =  await  openAndShowTextDocument ( "roundtrip-changes.qmd" ) ; 
4439
4540    const  {  before,  after }  =  await  roundtrip ( doc ) ; 
4641
4742    assert . equal ( before ,  after ) ; 
4843  } ) ; 
49- } ) ; 
5044
51- async  function  roundtrip ( doc : vscode . TextDocument )  { 
52-   const  before  =  doc . getText ( ) ; 
45+   test ( "Roundtripped valid-basics.qmd matches snapshot" ,  async  function  ( )  { 
46+     const  {  doc }  =  await  openAndShowTextDocument ( "valid-basics.qmd" ) ; 
47+ 
48+     const  {  after }  =  await  roundtrip ( doc ) ; 
49+ 
50+     assert . equal ( after ,  await  readOrCreateSnapshot ( "roundtripped-valid-basics.qmd" ,  after ) ) ; 
51+   } ) ; 
5352
54-   // switch to visual editor and back 
55-   await  vscode . commands . executeCommand ( "quarto.test_setkVisualModeConfirmedTrue" ) ; 
56-   await  wait ( 300 ) ; 
57-   await  vscode . commands . executeCommand ( "quarto.editInVisualMode" ) ; 
58-   await  wait ( APPROX_TIME_TO_OPEN_VISUAL_EDITOR ) ; 
59-   await  vscode . commands . executeCommand ( "quarto.editInSourceMode" ) ; 
60-   await  wait ( 300 ) ; 
53+   test ( "Roundtripped invalid.qmd matches snapshot" ,  async  function  ( )  { 
54+     const  {  doc }  =  await  openAndShowTextDocument ( "invalid.qmd" ) ; 
6155
62-   const  after  =   doc . getText ( ) ; 
56+      const  {   after }   =   await   roundtrip ( doc ) ; 
6357
64-   return  {  before,  after } ; 
65- } 
58+     assert . equal ( after ,  await  readOrCreateSnapshot ( "roundtripped-invalid.qmd" ,  after ) ) ; 
59+   } ) ; 
60+ } ) ; 
0 commit comments