@@ -14,34 +14,68 @@ describe("TypeScriptLoader", () => {
1414 } ) ;
1515
1616 describe ( "cosmiconfig" , ( ) => {
17- it ( "should load a valid TS file" , async ( ) => {
18- const cfg = cosmiconfig ( "test" , {
19- loaders : {
20- ".ts" : TypeScriptLoader ( ) ,
21- } ,
17+ describe ( "synchronous" , ( ) => {
18+ it ( "should load a valid TS file" , ( ) => {
19+ const cfg = cosmiconfigSync ( "test" , {
20+ loaders : {
21+ ".ts" : TypeScriptLoader ( ) ,
22+ } ,
23+ } ) ;
24+ const loadedCfg = cfg . load (
25+ path . resolve ( fixturesPath , "valid.fixture.ts" )
26+ ) ;
27+
28+ expect ( typeof loadedCfg ! . config ) . toStrictEqual ( "object" ) ;
29+ expect ( typeof loadedCfg ! . config . test ) . toStrictEqual ( "object" ) ;
30+ expect ( loadedCfg ! . config . test . cake ) . toStrictEqual ( "a lie" ) ;
2231 } ) ;
23- const loadedCfg = await cfg . load (
24- path . resolve ( fixturesPath , "valid.fixture.ts" )
25- ) ;
2632
27- expect ( typeof loadedCfg ! . config ) . toStrictEqual ( "object" ) ;
28- expect ( typeof loadedCfg ! . config . test ) . toStrictEqual ( "object" ) ;
29- expect ( loadedCfg ! . config . test . cake ) . toStrictEqual ( "a lie" ) ;
33+ it ( "should throw an error on loading an invalid TS file" , ( ) => {
34+ const cfg = cosmiconfigSync ( "test" , {
35+ loaders : {
36+ ".ts" : TypeScriptLoader ( ) ,
37+ } ,
38+ } ) ;
39+
40+ try {
41+ cfg . load ( path . resolve ( fixturesPath , "invalid.fixture.ts" ) ) ;
42+ fail ( "Should fail to load invalid TS" ) ;
43+ } catch ( error : any ) {
44+ expect ( error ?. name ) . toStrictEqual ( "TypeScriptCompileError" ) ;
45+ }
46+ } ) ;
3047 } ) ;
3148
32- it ( "should throw an error on loading an invalid TS file" , async ( ) => {
33- const cfg = cosmiconfig ( "test" , {
34- loaders : {
35- ".ts" : TypeScriptLoader ( ) ,
36- } ,
49+ describe ( "asynchronous" , ( ) => {
50+ it ( "should load a valid TS file" , async ( ) => {
51+ const cfg = cosmiconfig ( "test" , {
52+ loaders : {
53+ ".ts" : TypeScriptLoader ( ) ,
54+ } ,
55+ } ) ;
56+ const loadedCfg = await cfg . load (
57+ path . resolve ( fixturesPath , "valid.fixture.ts" )
58+ ) ;
59+
60+ expect ( typeof loadedCfg ! . config ) . toStrictEqual ( "object" ) ;
61+ expect ( typeof loadedCfg ! . config . test ) . toStrictEqual ( "object" ) ;
62+ expect ( loadedCfg ! . config . test . cake ) . toStrictEqual ( "a lie" ) ;
3763 } ) ;
3864
39- try {
40- await cfg . load ( path . resolve ( fixturesPath , "invalid.fixture.ts" ) ) ;
41- fail ( "Should fail to load invalid TS" ) ;
42- } catch ( error : any ) {
43- expect ( error ?. name ) . toStrictEqual ( "TypeScriptCompileError" ) ;
44- }
65+ it ( "should throw an error on loading an invalid TS file" , async ( ) => {
66+ const cfg = cosmiconfig ( "test" , {
67+ loaders : {
68+ ".ts" : TypeScriptLoader ( ) ,
69+ } ,
70+ } ) ;
71+
72+ try {
73+ await cfg . load ( path . resolve ( fixturesPath , "invalid.fixture.ts" ) ) ;
74+ fail ( "Should fail to load invalid TS" ) ;
75+ } catch ( error : any ) {
76+ expect ( error ?. name ) . toStrictEqual ( "TypeScriptCompileError" ) ;
77+ }
78+ } ) ;
4579 } ) ;
4680 } ) ;
4781
0 commit comments