11import path from "node:path" ;
22
3- import { cosmiconfig } from "cosmiconfig" ;
3+ import { cosmiconfig , cosmiconfigSync } from "cosmiconfig" ;
44
55import { TypeScriptLoader } from "." ;
66
@@ -14,45 +14,79 @@ 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
4882 describe ( "cosmiconfigSync" , ( ) => {
49- it ( "should load a valid TS file" , async ( ) => {
50- const cfg = cosmiconfig ( "test" , {
83+ it ( "should load a valid TS file" , ( ) => {
84+ const cfg = cosmiconfigSync ( "test" , {
5185 loaders : {
5286 ".ts" : TypeScriptLoader ( ) ,
5387 } ,
5488 } ) ;
55- const loadedCfg = await cfg . load (
89+ const loadedCfg = cfg . load (
5690 path . resolve ( fixturesPath , "valid.fixture.ts" )
5791 ) ;
5892
@@ -61,16 +95,16 @@ describe("TypeScriptLoader", () => {
6195 expect ( loadedCfg ! . config . test . cake ) . toStrictEqual ( "a lie" ) ;
6296 } ) ;
6397
64- it ( "should throw an error on loading an invalid TS file" , async ( ) => {
65- const cfg = cosmiconfig ( "test" , {
98+ it ( "should throw an error on loading an invalid TS file" , ( ) => {
99+ const cfg = cosmiconfigSync ( "test" , {
66100 loaders : {
67101 ".ts" : TypeScriptLoader ( ) ,
68102 } ,
69103 } ) ;
70104
71- await expect ( ( ) =>
105+ expect ( ( ) =>
72106 cfg . load ( path . resolve ( fixturesPath , "invalid.fixture.ts" ) )
73- ) . rejects . toThrowError ( ) ;
107+ ) . toThrowError ( ) ;
74108 } ) ;
75109 } ) ;
76110} ) ;
0 commit comments