11import {
2+ AbstractFileSystem ,
23 allChecks ,
34 LiquidCheckDefinition ,
45 path ,
@@ -44,6 +45,9 @@ describe('Module: runChecks', () => {
4445 let documentManager : DocumentManager ;
4546 let connection : { sendDiagnostics : ReturnType < typeof vi . fn > } ;
4647 let runChecks : ReturnType < typeof makeRunChecks > ;
48+ let fs : MockFileSystem ;
49+ const rootUri = path . normalize ( 'browser:///theme' ) ;
50+ const fileUri = path . join ( rootUri , 'snippets' , 'input.liquid' ) ;
4751
4852 beforeEach ( ( ) => {
4953 connection = {
@@ -52,13 +56,20 @@ describe('Module: runChecks', () => {
5256
5357 documentManager = new DocumentManager ( ) ;
5458 diagnosticsManager = new DiagnosticsManager ( connection as any as Connection ) ;
59+ fs = new MockFileSystem (
60+ {
61+ '.theme-check.yml' : '' ,
62+ 'snippets/input.liquid' : `{{ 'any' | filter }}` ,
63+ } ,
64+ rootUri ,
65+ ) ;
5566 runChecks = makeRunChecks ( documentManager , diagnosticsManager , {
56- fs : new MockFileSystem ( { } , 'browser:/' ) ,
67+ fs,
5768 loadConfig : async ( ) => ( {
58- context : 'theme' ,
69+ context : 'theme' as const ,
5970 settings : { } ,
6071 checks : [ LiquidFilter ] ,
61- rootUri : 'browser:/' ,
72+ rootUri,
6273 } ) ,
6374 themeDocset : {
6475 filters : async ( ) => [ ] ,
@@ -74,15 +85,14 @@ describe('Module: runChecks', () => {
7485 } ) ;
7586
7687 it ( 'should send diagnostics when there are errors' , async ( ) => {
77- const fileURI = 'browser:/input.liquid' ;
78- const fileContents = `{{ 'any' | filter }}` ;
88+ const fileContents = await fs . readFile ( fileUri ) ;
7989 const fileVersion = 0 ;
80- documentManager . open ( fileURI , fileContents , fileVersion ) ;
90+ documentManager . open ( fileUri , fileContents , fileVersion ) ;
8191
82- await runChecks ( [ 'browser:/input.liquid' ] ) ;
92+ await runChecks ( [ fileUri ] ) ;
8393 expect ( connection . sendDiagnostics ) . toBeCalled ( ) ;
8494 expect ( connection . sendDiagnostics ) . toBeCalledWith ( {
85- uri : fileURI ,
95+ uri : fileUri ,
8696 version : fileVersion ,
8797 diagnostics : [
8898 {
@@ -106,23 +116,22 @@ describe('Module: runChecks', () => {
106116 } ) ;
107117
108118 it ( 'should send an empty array when the errors were cleared' , async ( ) => {
109- const fileURI = 'browser:/input.liquid' ;
110119 const fileContentsWithError = `{{ 'any' | filter }}` ;
111120 const fileContentsWithoutError = `{{ 'any' }}` ;
112121 let fileVersion = 1 ;
113122
114123 // Open and have errors
115- documentManager . open ( fileURI , fileContentsWithError , fileVersion ) ;
116- await runChecks ( [ 'browser:/input.liquid' ] ) ;
124+ documentManager . open ( fileUri , fileContentsWithError , fileVersion ) ;
125+ await runChecks ( [ fileUri ] ) ;
117126
118127 // Change doc to fix errors
119128 fileVersion = 2 ;
120- documentManager . change ( fileURI , fileContentsWithoutError , fileVersion ) ;
121- await runChecks ( [ 'browser:/input.liquid' ] ) ;
129+ documentManager . change ( fileUri , fileContentsWithoutError , fileVersion ) ;
130+ await runChecks ( [ fileUri ] ) ;
122131
123132 expect ( connection . sendDiagnostics ) . toBeCalledTimes ( 2 ) ;
124133 expect ( connection . sendDiagnostics ) . toHaveBeenLastCalledWith ( {
125- uri : fileURI ,
134+ uri : fileUri ,
126135 version : fileVersion ,
127136 diagnostics : [ ] ,
128137 } ) ;
@@ -131,7 +140,7 @@ describe('Module: runChecks', () => {
131140 it ( 'should send diagnostics per URI when there are errors' , async ( ) => {
132141 const files = [
133142 {
134- fileURI : 'browser:/ input1.liquid',
143+ fileURI : path . join ( rootUri , 'snippets' , ' input1.liquid') ,
135144 fileContents : `{{ 'any' | filter }}` ,
136145 fileVersion : 0 ,
137146 diagnostics : [
@@ -154,7 +163,7 @@ describe('Module: runChecks', () => {
154163 ] ,
155164 } ,
156165 {
157- fileURI : 'browser:/ input2.liquid',
166+ fileURI : path . join ( rootUri , 'snippets' , ' input2.liquid') ,
158167 // same but on a new line
159168 fileContents : `\n{{ 'any' | filter }}` ,
160169 fileVersion : 0 ,
@@ -183,7 +192,7 @@ describe('Module: runChecks', () => {
183192 documentManager . open ( fileURI , fileContents , fileVersion ) ;
184193 } ) ;
185194
186- await runChecks ( [ 'browser:/ input1.liquid'] ) ;
195+ await runChecks ( [ path . join ( rootUri , 'snippets' , ' input1.liquid') ] ) ;
187196
188197 files . forEach ( ( { fileURI, fileVersion, diagnostics } ) => {
189198 expect ( connection . sendDiagnostics ) . toBeCalledWith ( {
@@ -196,23 +205,24 @@ describe('Module: runChecks', () => {
196205
197206 it ( 'should use the contents of the default translations file buffer (if any) instead of the result of the factory' , async ( ) => {
198207 const defaultPath = 'locales/en.default.json' ;
199- const defaultURI = `browser:/ ${ defaultPath } ` ;
208+ const defaultURI = path . join ( rootUri , ... defaultPath . split ( '/' ) ) ;
200209 const frPath = 'locales/fr.json' ;
201- const frURI = `browser:/ ${ frPath } ` ;
210+ const frURI = path . join ( rootUri , ... frPath . split ( '/' ) ) ;
202211 const files = {
212+ '.theme-check.yml' : '' ,
203213 [ defaultPath ] : JSON . stringify ( { hello : 'hello' } ) ,
204214 [ frPath ] : JSON . stringify ( { hello : 'bonjour' , hi : 'salut' } ) ,
205215 } ;
206216
207217 const matchingTranslation = allChecks . filter ( ( c ) => c . meta . code === 'MatchingTranslations' ) ;
208218 expect ( matchingTranslation ) . to . have . lengthOf ( 1 ) ;
209219 runChecks = makeRunChecks ( documentManager , diagnosticsManager , {
210- fs : new MockFileSystem ( files , path . normalize ( 'browser:/' ) ) ,
220+ fs : new MockFileSystem ( files , rootUri ) ,
211221 loadConfig : async ( ) => ( {
212222 context : 'theme' ,
213223 settings : { } ,
214224 checks : matchingTranslation ,
215- rootUri : path . normalize ( 'browser:/' ) ,
225+ rootUri : rootUri ,
216226 } ) ,
217227 themeDocset : {
218228 filters : async ( ) => [ ] ,
@@ -229,29 +239,31 @@ describe('Module: runChecks', () => {
229239 // Open and have errors
230240 documentManager . open ( frURI , files [ frPath ] , 0 ) ;
231241 await runChecks ( [ frURI ] ) ;
232- expect ( connection . sendDiagnostics ) . toHaveBeenCalledWith ( {
233- uri : frURI ,
234- version : 0 ,
235- diagnostics : [
236- {
237- source : 'theme-check' ,
238- code : 'MatchingTranslations' ,
239- codeDescription : { href : expect . any ( String ) } ,
240- message : `A default translation for 'hi' does not exist` ,
241- severity : 1 ,
242- range : {
243- end : {
244- character : 31 ,
245- line : 0 ,
246- } ,
247- start : {
248- character : 19 ,
249- line : 0 ,
242+ expect ( connection . sendDiagnostics ) . toHaveBeenCalledWith (
243+ expect . objectContaining ( {
244+ uri : frURI ,
245+ version : 0 ,
246+ diagnostics : expect . arrayContaining ( [
247+ {
248+ source : 'theme-check' ,
249+ code : 'MatchingTranslations' ,
250+ codeDescription : { href : expect . any ( String ) } ,
251+ message : `A default translation for 'hi' does not exist` ,
252+ severity : 1 ,
253+ range : {
254+ end : {
255+ character : 31 ,
256+ line : 0 ,
257+ } ,
258+ start : {
259+ character : 19 ,
260+ line : 0 ,
261+ } ,
250262 } ,
251263 } ,
252- } ,
253- ] ,
254- } ) ;
264+ ] ) ,
265+ } ) ,
266+ ) ;
255267
256268 // Change the contents of the defaultURI buffer, expect frURI to be fixed
257269 documentManager . open ( defaultURI , files [ defaultPath ] , 0 ) ;
0 commit comments