1
1
import * as path from 'path' ;
2
2
import test , { ExecutionContext } from 'ava' ;
3
- import m from '../lib ' ;
3
+ import tsd from '..' ;
4
4
import { Diagnostic } from '../lib/interfaces' ;
5
5
6
6
type Expectation = [ number , number , 'error' | 'warning' , string , ( string | RegExp ) ?] ;
@@ -32,23 +32,23 @@ const verify = (t: ExecutionContext, diagnostics: Diagnostic[], expectations: Ex
32
32
} ;
33
33
34
34
test ( 'throw if no type definition was found' , async t => {
35
- await t . throwsAsync ( m ( { cwd : path . join ( __dirname , 'fixtures/no-tsd' ) } ) , 'The type definition `index.d.ts` does not exist. Create one and try again.' ) ;
35
+ await t . throwsAsync ( tsd ( { cwd : path . join ( __dirname , 'fixtures/no-tsd' ) } ) , 'The type definition `index.d.ts` does not exist. Create one and try again.' ) ;
36
36
} ) ;
37
37
38
38
test ( 'throw if no test is found' , async t => {
39
- await t . throwsAsync ( m ( { cwd : path . join ( __dirname , 'fixtures/no-test' ) } ) , 'The test file `index.test-d.ts` or `index.test-d.tsx` does not exist. Create one and try again.' ) ;
39
+ await t . throwsAsync ( tsd ( { cwd : path . join ( __dirname , 'fixtures/no-test' ) } ) , 'The test file `index.test-d.ts` or `index.test-d.tsx` does not exist. Create one and try again.' ) ;
40
40
} ) ;
41
41
42
42
test ( 'return diagnostics' , async t => {
43
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/failure' ) } ) ;
43
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/failure' ) } ) ;
44
44
45
45
verify ( t , diagnostics , [
46
46
[ 5 , 19 , 'error' , 'Argument of type \'number\' is not assignable to parameter of type \'string\'.' ]
47
47
] ) ;
48
48
} ) ;
49
49
50
50
test ( 'return diagnostics from imported files as well' , async t => {
51
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/failure-nested' ) } ) ;
51
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/failure-nested' ) } ) ;
52
52
53
53
verify ( t , diagnostics , [
54
54
[ 5 , 19 , 'error' , 'Argument of type \'number\' is not assignable to parameter of type \'string\'.' , / c h i l d .t e s t - d .t s $ / ] ,
@@ -57,23 +57,23 @@ test('return diagnostics from imported files as well', async t => {
57
57
} ) ;
58
58
59
59
test ( 'fail if typings file is not part of `files` list' , async t => {
60
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/no-files' ) } ) ;
60
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/no-files' ) } ) ;
61
61
62
62
verify ( t , diagnostics , [
63
63
[ 3 , 1 , 'error' , 'TypeScript type definition `index.d.ts` is not part of the `files` list.' , 'package.json' ] ,
64
64
] ) ;
65
65
} ) ;
66
66
67
67
test ( 'fail if `typings` property is used instead of `types`' , async t => {
68
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/types-property/typings' ) } ) ;
68
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/types-property/typings' ) } ) ;
69
69
70
70
verify ( t , diagnostics , [
71
71
[ 3 , 1 , 'error' , 'Use property `types` instead of `typings`.' , 'package.json' ] ,
72
72
] ) ;
73
73
} ) ;
74
74
75
75
test ( 'fail if tests don\'t pass in strict mode' , async t => {
76
- const diagnostics = await m ( {
76
+ const diagnostics = await tsd ( {
77
77
cwd : path . join ( __dirname , 'fixtures/failure-strict-null-checks' )
78
78
} ) ;
79
79
@@ -83,7 +83,7 @@ test('fail if tests don\'t pass in strict mode', async t => {
83
83
} ) ;
84
84
85
85
test ( 'overridden config defaults to `strict` if `strict` is not explicitly overridden' , async t => {
86
- const diagnostics = await m ( {
86
+ const diagnostics = await tsd ( {
87
87
cwd : path . join ( __dirname , 'fixtures/strict-null-checks-as-default-config-value' )
88
88
} ) ;
89
89
@@ -93,7 +93,7 @@ test('overridden config defaults to `strict` if `strict` is not explicitly overr
93
93
} ) ;
94
94
95
95
test ( 'fail if types are used from a lib that was not explicitly specified' , async t => {
96
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/lib-config/failure-missing-lib' ) } ) ;
96
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/lib-config/failure-missing-lib' ) } ) ;
97
97
98
98
verify ( t , diagnostics , [
99
99
[ 1 , 22 , 'error' , 'Cannot find name \'Window\'.' , / f a i l u r e - m i s s i n g - l i b \/ i n d e x .d .t s $ / ] ,
@@ -102,97 +102,97 @@ test('fail if types are used from a lib that was not explicitly specified', asyn
102
102
} ) ;
103
103
104
104
test ( 'allow specifying a lib as a triple-slash-reference' , async t => {
105
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-as-triple-slash-reference' ) } ) ;
105
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-as-triple-slash-reference' ) } ) ;
106
106
107
107
verify ( t , diagnostics , [ ] ) ;
108
108
} ) ;
109
109
110
110
test ( 'allow specifying a lib in package.json\'s `tsd` field' , async t => {
111
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-from-package-json' ) } ) ;
111
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-from-package-json' ) } ) ;
112
112
113
113
verify ( t , diagnostics , [ ] ) ;
114
114
} ) ;
115
115
116
116
test ( 'allow specifying a lib in tsconfig.json' , async t => {
117
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-from-tsconfig-json' ) } ) ;
117
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-from-tsconfig-json' ) } ) ;
118
118
119
119
verify ( t , diagnostics , [ ] ) ;
120
120
} ) ;
121
121
122
122
test ( 'a lib option in package.json overrdides a lib option in tsconfig.json' , async t => {
123
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-from-package-json-overrides-tsconfig-json' ) } ) ;
123
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/lib-config/lib-from-package-json-overrides-tsconfig-json' ) } ) ;
124
124
125
125
verify ( t , diagnostics , [ ] ) ;
126
126
} ) ;
127
127
128
128
test ( 'pass in loose mode when strict mode is disabled in settings' , async t => {
129
- const diagnostics = await m ( {
129
+ const diagnostics = await tsd ( {
130
130
cwd : path . join ( __dirname , 'fixtures/non-strict-check-with-config' )
131
131
} ) ;
132
132
133
133
verify ( t , diagnostics , [ ] ) ;
134
134
} ) ;
135
135
136
136
test ( 'return no diagnostics' , async t => {
137
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/success' ) } ) ;
137
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/success' ) } ) ;
138
138
139
139
verify ( t , diagnostics , [ ] ) ;
140
140
} ) ;
141
141
142
142
test ( 'support non-barrel main' , async t => {
143
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/test-non-barrel-main' ) } ) ;
143
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/test-non-barrel-main' ) } ) ;
144
144
145
145
verify ( t , diagnostics , [ ] ) ;
146
146
} ) ;
147
147
148
148
test ( 'support non-barrel main using `types` property' , async t => {
149
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/test-non-barrel-main-via-types' ) } ) ;
149
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/test-non-barrel-main-via-types' ) } ) ;
150
150
151
151
verify ( t , diagnostics , [ ] ) ;
152
152
} ) ;
153
153
154
154
test ( 'support testing in sub-directories' , async t => {
155
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/test-in-subdir' ) } ) ;
155
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/test-in-subdir' ) } ) ;
156
156
157
157
verify ( t , diagnostics , [ ] ) ;
158
158
} ) ;
159
159
160
160
test ( 'support top-level await' , async t => {
161
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/top-level-await' ) } ) ;
161
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/top-level-await' ) } ) ;
162
162
163
163
verify ( t , diagnostics , [ ] ) ;
164
164
} ) ;
165
165
166
166
test ( 'support default test directory' , async t => {
167
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/test-directory/default' ) } ) ;
167
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/test-directory/default' ) } ) ;
168
168
169
169
verify ( t , diagnostics , [ ] ) ;
170
170
} ) ;
171
171
172
172
test ( 'support tsx in subdirectory' , async t => {
173
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/test-directory/tsx' ) } ) ;
173
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/test-directory/tsx' ) } ) ;
174
174
175
175
verify ( t , diagnostics , [ ] ) ;
176
176
} ) ;
177
177
178
178
test ( 'support setting a custom test directory' , async t => {
179
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/test-directory/custom' ) } ) ;
179
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/test-directory/custom' ) } ) ;
180
180
181
181
verify ( t , diagnostics , [
182
182
[ 4 , 0 , 'error' , 'Expected an error, but found none.' ]
183
183
] ) ;
184
184
} ) ;
185
185
186
186
test ( 'expectError for functions' , async t => {
187
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/expect-error/functions' ) } ) ;
187
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/expect-error/functions' ) } ) ;
188
188
189
189
verify ( t , diagnostics , [
190
190
[ 5 , 0 , 'error' , 'Expected an error, but found none.' ]
191
191
] ) ;
192
192
} ) ;
193
193
194
194
test ( 'expectError should not ignore syntactical errors' , async t => {
195
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/expect-error/syntax' ) } ) ;
195
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/expect-error/syntax' ) } ) ;
196
196
197
197
verify ( t , diagnostics , [
198
198
[ 4 , 29 , 'error' , '\')\' expected.' ] ,
@@ -203,29 +203,29 @@ test('expectError should not ignore syntactical errors', async t => {
203
203
} ) ;
204
204
205
205
test ( 'expectError for values' , async t => {
206
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/expect-error/values' ) } ) ;
206
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/expect-error/values' ) } ) ;
207
207
208
208
verify ( t , diagnostics , [
209
209
[ 5 , 0 , 'error' , 'Expected an error, but found none.' ]
210
210
] ) ;
211
211
} ) ;
212
212
213
213
test ( 'missing import' , async t => {
214
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/missing-import' ) } ) ;
214
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/missing-import' ) } ) ;
215
215
216
216
verify ( t , diagnostics , [
217
217
[ 3 , 18 , 'error' , 'Cannot find name \'Primitive\'.' ]
218
218
] ) ;
219
219
} ) ;
220
220
221
221
test ( 'tsx' , async t => {
222
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/tsx' ) } ) ;
222
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/tsx' ) } ) ;
223
223
224
224
verify ( t , diagnostics , [ ] ) ;
225
225
} ) ;
226
226
227
227
test ( 'loose types' , async t => {
228
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/strict-types/loose' ) } ) ;
228
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/strict-types/loose' ) } ) ;
229
229
230
230
verify ( t , diagnostics , [
231
231
[ 5 , 0 , 'error' , 'Parameter type `string` is declared too wide for argument type `"cat"`.' ] ,
@@ -242,7 +242,7 @@ test('loose types', async t => {
242
242
} ) ;
243
243
244
244
test ( 'strict types' , async t => {
245
- const diagnostics = await m ( { cwd : path . join ( __dirname , 'fixtures/strict-types/strict' ) } ) ;
245
+ const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/strict-types/strict' ) } ) ;
246
246
247
247
verify ( t , diagnostics , [ ] ) ;
248
248
} ) ;
0 commit comments