11import * as path from 'path' ;
22import test , { ExecutionContext } from 'ava' ;
3- import m from '../lib ' ;
3+ import tsd from '..' ;
44import { Diagnostic } from '../lib/interfaces' ;
55
66type Expectation = [ number , number , 'error' | 'warning' , string , ( string | RegExp ) ?] ;
@@ -32,23 +32,23 @@ const verify = (t: ExecutionContext, diagnostics: Diagnostic[], expectations: Ex
3232} ;
3333
3434test ( '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.' ) ;
3636} ) ;
3737
3838test ( '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.' ) ;
4040} ) ;
4141
4242test ( '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' ) } ) ;
4444
4545 verify ( t , diagnostics , [
4646 [ 5 , 19 , 'error' , 'Argument of type \'number\' is not assignable to parameter of type \'string\'.' ]
4747 ] ) ;
4848} ) ;
4949
5050test ( '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' ) } ) ;
5252
5353 verify ( t , diagnostics , [
5454 [ 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 => {
5757} ) ;
5858
5959test ( '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' ) } ) ;
6161
6262 verify ( t , diagnostics , [
6363 [ 3 , 1 , 'error' , 'TypeScript type definition `index.d.ts` is not part of the `files` list.' , 'package.json' ] ,
6464 ] ) ;
6565} ) ;
6666
6767test ( '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' ) } ) ;
6969
7070 verify ( t , diagnostics , [
7171 [ 3 , 1 , 'error' , 'Use property `types` instead of `typings`.' , 'package.json' ] ,
7272 ] ) ;
7373} ) ;
7474
7575test ( 'fail if tests don\'t pass in strict mode' , async t => {
76- const diagnostics = await m ( {
76+ const diagnostics = await tsd ( {
7777 cwd : path . join ( __dirname , 'fixtures/failure-strict-null-checks' )
7878 } ) ;
7979
@@ -83,7 +83,7 @@ test('fail if tests don\'t pass in strict mode', async t => {
8383} ) ;
8484
8585test ( 'overridden config defaults to `strict` if `strict` is not explicitly overridden' , async t => {
86- const diagnostics = await m ( {
86+ const diagnostics = await tsd ( {
8787 cwd : path . join ( __dirname , 'fixtures/strict-null-checks-as-default-config-value' )
8888 } ) ;
8989
@@ -93,7 +93,7 @@ test('overridden config defaults to `strict` if `strict` is not explicitly overr
9393} ) ;
9494
9595test ( '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' ) } ) ;
9797
9898 verify ( t , diagnostics , [
9999 [ 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
102102} ) ;
103103
104104test ( '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' ) } ) ;
106106
107107 verify ( t , diagnostics , [ ] ) ;
108108} ) ;
109109
110110test ( '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' ) } ) ;
112112
113113 verify ( t , diagnostics , [ ] ) ;
114114} ) ;
115115
116116test ( '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' ) } ) ;
118118
119119 verify ( t , diagnostics , [ ] ) ;
120120} ) ;
121121
122122test ( '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' ) } ) ;
124124
125125 verify ( t , diagnostics , [ ] ) ;
126126} ) ;
127127
128128test ( 'pass in loose mode when strict mode is disabled in settings' , async t => {
129- const diagnostics = await m ( {
129+ const diagnostics = await tsd ( {
130130 cwd : path . join ( __dirname , 'fixtures/non-strict-check-with-config' )
131131 } ) ;
132132
133133 verify ( t , diagnostics , [ ] ) ;
134134} ) ;
135135
136136test ( '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' ) } ) ;
138138
139139 verify ( t , diagnostics , [ ] ) ;
140140} ) ;
141141
142142test ( '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' ) } ) ;
144144
145145 verify ( t , diagnostics , [ ] ) ;
146146} ) ;
147147
148148test ( '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' ) } ) ;
150150
151151 verify ( t , diagnostics , [ ] ) ;
152152} ) ;
153153
154154test ( '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' ) } ) ;
156156
157157 verify ( t , diagnostics , [ ] ) ;
158158} ) ;
159159
160160test ( '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' ) } ) ;
162162
163163 verify ( t , diagnostics , [ ] ) ;
164164} ) ;
165165
166166test ( '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' ) } ) ;
168168
169169 verify ( t , diagnostics , [ ] ) ;
170170} ) ;
171171
172172test ( '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' ) } ) ;
174174
175175 verify ( t , diagnostics , [ ] ) ;
176176} ) ;
177177
178178test ( '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' ) } ) ;
180180
181181 verify ( t , diagnostics , [
182182 [ 4 , 0 , 'error' , 'Expected an error, but found none.' ]
183183 ] ) ;
184184} ) ;
185185
186186test ( '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' ) } ) ;
188188
189189 verify ( t , diagnostics , [
190190 [ 5 , 0 , 'error' , 'Expected an error, but found none.' ]
191191 ] ) ;
192192} ) ;
193193
194194test ( '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' ) } ) ;
196196
197197 verify ( t , diagnostics , [
198198 [ 4 , 29 , 'error' , '\')\' expected.' ] ,
@@ -203,29 +203,29 @@ test('expectError should not ignore syntactical errors', async t => {
203203} ) ;
204204
205205test ( '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' ) } ) ;
207207
208208 verify ( t , diagnostics , [
209209 [ 5 , 0 , 'error' , 'Expected an error, but found none.' ]
210210 ] ) ;
211211} ) ;
212212
213213test ( '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' ) } ) ;
215215
216216 verify ( t , diagnostics , [
217217 [ 3 , 18 , 'error' , 'Cannot find name \'Primitive\'.' ]
218218 ] ) ;
219219} ) ;
220220
221221test ( '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' ) } ) ;
223223
224224 verify ( t , diagnostics , [ ] ) ;
225225} ) ;
226226
227227test ( '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' ) } ) ;
229229
230230 verify ( t , diagnostics , [
231231 [ 5 , 0 , 'error' , 'Parameter type `string` is declared too wide for argument type `"cat"`.' ] ,
@@ -242,7 +242,7 @@ test('loose types', async t => {
242242} ) ;
243243
244244test ( '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' ) } ) ;
246246
247247 verify ( t , diagnostics , [ ] ) ;
248248} ) ;
0 commit comments