1
1
import path from "node:path" ;
2
2
3
- import { cosmiconfig } from "cosmiconfig" ;
3
+ import { cosmiconfig , cosmiconfigSync } from "cosmiconfig" ;
4
4
5
5
import { TypeScriptLoader } from "." ;
6
6
@@ -14,45 +14,79 @@ describe("TypeScriptLoader", () => {
14
14
} ) ;
15
15
16
16
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" ) ;
22
31
} ) ;
23
- const loadedCfg = await cfg . load (
24
- path . resolve ( fixturesPath , "valid.fixture.ts" )
25
- ) ;
26
32
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
+ } ) ;
30
47
} ) ;
31
48
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" ) ;
37
63
} ) ;
38
64
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
+ } ) ;
45
79
} ) ;
46
80
} ) ;
47
81
48
82
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" , {
51
85
loaders : {
52
86
".ts" : TypeScriptLoader ( ) ,
53
87
} ,
54
88
} ) ;
55
- const loadedCfg = await cfg . load (
89
+ const loadedCfg = cfg . load (
56
90
path . resolve ( fixturesPath , "valid.fixture.ts" )
57
91
) ;
58
92
@@ -61,16 +95,16 @@ describe("TypeScriptLoader", () => {
61
95
expect ( loadedCfg ! . config . test . cake ) . toStrictEqual ( "a lie" ) ;
62
96
} ) ;
63
97
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" , {
66
100
loaders : {
67
101
".ts" : TypeScriptLoader ( ) ,
68
102
} ,
69
103
} ) ;
70
104
71
- await expect ( ( ) =>
105
+ expect ( ( ) =>
72
106
cfg . load ( path . resolve ( fixturesPath , "invalid.fixture.ts" ) )
73
- ) . rejects . toThrowError ( ) ;
107
+ ) . toThrowError ( ) ;
74
108
} ) ;
75
109
} ) ;
76
110
} ) ;
0 commit comments