@@ -6,45 +6,48 @@ import * as tsconfig from './tsconfig'
6
6
const TEST_DIR = join ( __dirname , '../tests' )
7
7
8
8
interface Test {
9
- path : [ string ] | [ string , string ]
10
- result ?: tsconfig . TSConfig
9
+ args : [ string ] | [ string , string ]
10
+ config ?: any
11
+ path ?: string
11
12
error ?: string
12
- filename ?: string
13
13
}
14
14
15
15
describe ( 'tsconfig' , function ( ) {
16
16
const tests : Test [ ] = [
17
17
{
18
- path : [ TEST_DIR , 'invalidfile' ] ,
18
+ args : [ TEST_DIR , 'invalidfile' ] ,
19
19
error : `Unexpected token 's' at 1:1 in ${ join ( TEST_DIR , 'invalidfile/tsconfig.json' ) } \nsome random string\n^`
20
20
} ,
21
21
{
22
- path : [ TEST_DIR , 'missing' ] ,
22
+ args : [ TEST_DIR , 'missing' ] ,
23
23
error : 'Cannot find a tsconfig.json file at the specified directory: missing'
24
24
} ,
25
25
{
26
- path : [ TEST_DIR , 'missing/foobar' ] ,
26
+ args : [ TEST_DIR , 'missing/foobar' ] ,
27
27
error : 'The specified path does not exist: missing/foobar'
28
28
} ,
29
29
{
30
- path : [ '/' ] ,
31
- result : { }
30
+ args : [ '/' ] ,
31
+ config : { }
32
32
} ,
33
33
{
34
- path : [ TEST_DIR , 'empty' ] ,
35
- result : { }
34
+ args : [ TEST_DIR , 'empty' ] ,
35
+ config : { } ,
36
+ path : join ( TEST_DIR , 'empty/tsconfig.json' )
36
37
} ,
37
38
{
38
- path : [ TEST_DIR , 'empty/tsconfig.json' ] ,
39
- result : { }
39
+ args : [ TEST_DIR , 'empty/tsconfig.json' ] ,
40
+ config : { } ,
41
+ path : join ( TEST_DIR , 'empty/tsconfig.json' )
40
42
} ,
41
43
{
42
- path : [ join ( TEST_DIR , 'find/up/config' ) ] ,
43
- result : { }
44
+ args : [ join ( TEST_DIR , 'find/up/config' ) ] ,
45
+ config : { } ,
46
+ path : join ( TEST_DIR , 'find/tsconfig.json' )
44
47
} ,
45
48
{
46
- path : [ TEST_DIR , 'valid' ] ,
47
- result : {
49
+ args : [ TEST_DIR , 'valid' ] ,
50
+ config : {
48
51
compilerOptions : {
49
52
module : 'commonjs' ,
50
53
noImplicitAny : true ,
@@ -57,11 +60,11 @@ describe('tsconfig', function () {
57
60
'./src/foo.ts'
58
61
]
59
62
} ,
60
- filename : join ( __dirname , '../tests/ valid/tsconfig.json' )
63
+ path : join ( TEST_DIR , 'valid/tsconfig.json' )
61
64
} ,
62
65
{
63
- path : [ TEST_DIR , 'bom' ] ,
64
- result : {
66
+ args : [ TEST_DIR , 'bom' ] ,
67
+ config : {
65
68
compilerOptions : {
66
69
module : 'commonjs' ,
67
70
noImplicitAny : true ,
@@ -74,11 +77,11 @@ describe('tsconfig', function () {
74
77
'./src/bom.ts'
75
78
]
76
79
} ,
77
- filename : join ( __dirname , '../tests/ bom/tsconfig.json' )
80
+ path : join ( TEST_DIR , 'bom/tsconfig.json' )
78
81
} ,
79
82
{
80
- path : [ join ( TEST_DIR , 'cwd' ) ] ,
81
- result : {
83
+ args : [ join ( TEST_DIR , 'cwd' ) ] ,
84
+ config : {
82
85
compilerOptions : {
83
86
module : 'commonjs' ,
84
87
noImplicitAny : true ,
@@ -88,30 +91,31 @@ describe('tsconfig', function () {
88
91
preserveConstEnums : true
89
92
}
90
93
} ,
91
- filename : join ( __dirname , '../tests/ cwd/tsconfig.json' )
94
+ path : join ( TEST_DIR , 'cwd/tsconfig.json' )
92
95
}
93
96
]
94
97
95
98
describe ( 'sync' , function ( ) {
96
99
tests . forEach ( function ( test ) {
97
- describe ( inspect ( test . path ) , function ( ) {
100
+ describe ( inspect ( test . args ) , function ( ) {
98
101
it ( 'should try to find config' , function ( ) {
99
102
let result : any
100
103
101
104
try {
102
- result = tsconfig . loadSync ( test . path [ 0 ] , test . path [ 1 ] )
105
+ result = tsconfig . loadSync ( test . args [ 0 ] , test . args [ 1 ] )
103
106
} catch ( err ) {
104
107
expect ( err . message ) . to . equal ( test . error )
105
108
106
109
return
107
110
}
108
111
109
- expect ( result ) . to . deep . equal ( test . result )
112
+ expect ( result . path ) . to . equal ( test . path )
113
+ expect ( result . config ) . to . deep . equal ( test . config )
110
114
} )
111
115
112
- if ( test . filename ) {
116
+ if ( test . path ) {
113
117
it ( 'should resolve filename' , function ( ) {
114
- expect ( tsconfig . resolveSync ( test . path [ 0 ] , test . path [ 1 ] ) ) . to . equal ( test . filename )
118
+ expect ( tsconfig . resolveSync ( test . args [ 0 ] , test . args [ 1 ] ) ) . to . equal ( test . path )
115
119
} )
116
120
}
117
121
} )
@@ -120,19 +124,26 @@ describe('tsconfig', function () {
120
124
121
125
describe ( 'async' , function ( ) {
122
126
tests . forEach ( function ( test ) {
123
- describe ( inspect ( test . path ) , function ( ) {
127
+ describe ( inspect ( test . args ) , function ( ) {
124
128
it ( 'should try to find config' , function ( ) {
125
- return tsconfig . load ( test . path [ 0 ] , test . path [ 1 ] )
129
+ return tsconfig . load ( test . args [ 0 ] , test . args [ 1 ] )
126
130
. then (
127
- config => expect ( config ) . to . deep . equal ( test . result ) ,
128
- error => expect ( error . message ) . to . equal ( test . error )
131
+ result => {
132
+ expect ( result . path ) . to . equal ( test . path )
133
+ expect ( result . config ) . to . deep . equal ( test . config )
134
+ } ,
135
+ error => {
136
+ expect ( error . message ) . to . equal ( test . error )
137
+ }
129
138
)
130
139
} )
131
140
132
- if ( test . filename ) {
141
+ if ( test . path ) {
133
142
it ( 'should resolve filename' , function ( ) {
134
- return tsconfig . resolve ( test . path [ 0 ] , test . path [ 1 ] )
135
- . then ( filename => expect ( filename ) . to . equal ( test . filename ) )
143
+ return tsconfig . resolve ( test . args [ 0 ] , test . args [ 1 ] )
144
+ . then ( filename => {
145
+ expect ( filename ) . to . equal ( test . path )
146
+ } )
136
147
} )
137
148
}
138
149
} )
0 commit comments