@@ -10,6 +10,8 @@ import { loaderJavaScript } from './loaderJavaScript.js';
1010const oc = ( ...params : Parameters < typeof expect . objectContaining > ) => expect . objectContaining ( ...params ) ;
1111const ac = ( ...params : Parameters < typeof expect . arrayContaining > ) => expect . arrayContaining ( ...params ) ;
1212
13+ const supportsTypeScriptConfig = process . version >= 'v22' ;
14+
1315describe ( 'loaderJavaScript' , ( ) => {
1416 afterEach ( ( ) => { } ) ;
1517
@@ -47,6 +49,37 @@ describe('loaderJavaScript', () => {
4749 expect ( result4 . settings ) . not . toBe ( result . settings ) ;
4850 } ) ;
4951
52+ test . skipIf ( ! supportsTypeScriptConfig ) . each `
53+ file | expected
54+ ${ 'ts/cspell.config.ts' } | ${ { settings : oc ( { id : 'module/ts' } ) } }
55+ ${ 'ts/cspell.config.mts' } | ${ { settings : oc ( { id : 'module/mts' } ) } }
56+ ` ( 'loaderJavaScript $file' , async ( { file, expected } ) => {
57+ const url = pathToFileURL ( fixtures ( file ) ) ;
58+ expected . url ??= url ;
59+ const next = vi . fn ( ) ;
60+
61+ const result = await loaderJavaScript . load ( { url, context : { deserialize, io : defaultIO } } , next ) ;
62+ expect ( result ) . toEqual ( expected ) ;
63+
64+ // Try double loading.
65+ const result2 = await loaderJavaScript . load ( { url, context : { deserialize, io : defaultIO } } , next ) ;
66+ expect ( result2 . settings ) . toBe ( result . settings ) ;
67+
68+ // Ensure that we can force a load by changing search params.
69+ const url3 = new URL ( url . href ) ;
70+ url3 . searchParams . append ( 'q' , '29' ) ;
71+
72+ const result3 = await loaderJavaScript . load ( { url : url3 , context : { deserialize, io : defaultIO } } , next ) ;
73+ expect ( result3 . settings ) . not . toBe ( result . settings ) ;
74+ expect ( result3 . settings ) . toEqual ( result . settings ) ;
75+
76+ // Ensure that we can force a load by changing the hash.
77+ const url4 = new URL ( url . href ) ;
78+ url4 . hash = 'hash' ;
79+ const result4 = await loaderJavaScript . load ( { url : url4 , context : { deserialize, io : defaultIO } } , next ) ;
80+ expect ( result4 . settings ) . not . toBe ( result . settings ) ;
81+ } ) ;
82+
5083 /* cspell:ignore lazr */
5184
5285 test . each `
0 commit comments