1
1
import * as path from 'path' ;
2
2
import test from 'ava' ;
3
- import { verify } from './fixtures/utils' ;
3
+ import { verify , verifyWithFileName } from './fixtures/utils' ;
4
4
import tsd from '..' ;
5
5
import { Diagnostic } from '../lib/interfaces' ;
6
6
@@ -21,18 +21,20 @@ test('return diagnostics', async t => {
21
21
} ) ;
22
22
23
23
test ( 'return diagnostics from imported files as well' , async t => {
24
- const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/failure-nested' ) } ) ;
24
+ const cwd = path . join ( __dirname , 'fixtures/failure-nested' ) ;
25
+ const diagnostics = await tsd ( { cwd} ) ;
25
26
26
- verify ( t , diagnostics , [
27
- [ 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 $ / ] ,
28
- [ 6 , 19 , 'error' , 'Argument of type \'number\' is not assignable to parameter of type \'string\'.' , / i n d e x .t e s t - d .t s $ / ]
27
+ verifyWithFileName ( t , cwd , diagnostics , [
28
+ [ 5 , 19 , 'error' , 'Argument of type \'number\' is not assignable to parameter of type \'string\'.' , ' child.test-d.ts' ] ,
29
+ [ 6 , 19 , 'error' , 'Argument of type \'number\' is not assignable to parameter of type \'string\'.' , ' index.test-d.ts' ] ,
29
30
] ) ;
30
31
} ) ;
31
32
32
33
test ( 'fail if typings file is not part of `files` list' , async t => {
33
- const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/no-files' ) } ) ;
34
+ const cwd = path . join ( __dirname , 'fixtures/no-files' ) ;
35
+ const diagnostics = await tsd ( { cwd} ) ;
34
36
35
- verify ( t , diagnostics , [
37
+ verifyWithFileName ( t , cwd , diagnostics , [
36
38
[ 3 , 1 , 'error' , 'TypeScript type definition `index.d.ts` is not part of the `files` list.' , 'package.json' ] ,
37
39
] ) ;
38
40
} ) ;
@@ -50,39 +52,51 @@ test('allow specifying glob patterns containing typings file in `files` list', a
50
52
} ) ;
51
53
52
54
test ( 'fail if `typings` property is used instead of `types`' , async t => {
53
- const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/types-property/typings' ) } ) ;
55
+ const cwd = path . join ( __dirname , 'fixtures/types-property/typings' ) ;
56
+ const diagnostics = await tsd ( { cwd} ) ;
54
57
55
- verify ( t , diagnostics , [
58
+ verifyWithFileName ( t , cwd , diagnostics , [
56
59
[ 3 , 1 , 'error' , 'Use property `types` instead of `typings`.' , 'package.json' ] ,
57
60
] ) ;
58
61
} ) ;
59
62
60
63
test ( 'fail if tests don\'t pass in strict mode' , async t => {
61
- const diagnostics = await tsd ( {
62
- cwd : path . join ( __dirname , 'fixtures/failure-strict-null-checks' )
63
- } ) ;
64
-
65
- verify ( t , diagnostics , [
66
- [ 4 , 19 , 'error' , 'Argument of type \'number | null\' is not assignable to parameter of type \'number\'.\n Type \'null\' is not assignable to type \'number\'.' , / f a i l u r e - s t r i c t - n u l l - c h e c k s \/ i n d e x .t e s t - d .t s $ / ] ,
64
+ const cwd = path . join ( __dirname , 'fixtures/failure-strict-null-checks' ) ;
65
+ const diagnostics = await tsd ( { cwd} ) ;
66
+
67
+ verifyWithFileName ( t , cwd , diagnostics , [
68
+ [
69
+ 4 ,
70
+ 19 ,
71
+ 'error' ,
72
+ 'Argument of type \'number | null\' is not assignable to parameter of type \'number\'.\n Type \'null\' is not assignable to type \'number\'.' ,
73
+ 'index.test-d.ts' ,
74
+ ] ,
67
75
] ) ;
68
76
} ) ;
69
77
70
78
test ( 'overridden config defaults to `strict` if `strict` is not explicitly overridden' , async t => {
71
- const diagnostics = await tsd ( {
72
- cwd : path . join ( __dirname , 'fixtures/strict-null-checks-as-default-config-value' )
73
- } ) ;
74
-
75
- verify ( t , diagnostics , [
76
- [ 4 , 19 , 'error' , 'Argument of type \'number | null\' is not assignable to parameter of type \'number\'.\n Type \'null\' is not assignable to type \'number\'.' , / s t r i c t - n u l l - c h e c k s - a s - d e f a u l t - c o n f i g - v a l u e \/ i n d e x .t e s t - d .t s $ / ] ,
79
+ const cwd = path . join ( __dirname , 'fixtures/strict-null-checks-as-default-config-value' ) ;
80
+ const diagnostics = await tsd ( { cwd} ) ;
81
+
82
+ verifyWithFileName ( t , cwd , diagnostics , [
83
+ [
84
+ 4 ,
85
+ 19 ,
86
+ 'error' ,
87
+ 'Argument of type \'number | null\' is not assignable to parameter of type \'number\'.\n Type \'null\' is not assignable to type \'number\'.' ,
88
+ 'index.test-d.ts' ,
89
+ ] ,
77
90
] ) ;
78
91
} ) ;
79
92
80
93
test ( 'fail if types are used from a lib that was not explicitly specified' , async t => {
81
- const diagnostics = await tsd ( { cwd : path . join ( __dirname , 'fixtures/lib-config/failure-missing-lib' ) } ) ;
94
+ const cwd = path . join ( __dirname , 'fixtures/lib-config/failure-missing-lib' ) ;
95
+ const diagnostics = await tsd ( { cwd} ) ;
82
96
83
- verify ( t , diagnostics , [
84
- [ 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 $ / ] ,
85
- [ 4 , 11 , '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 .t e s t - d .t s $ / ]
97
+ verifyWithFileName ( t , cwd , diagnostics , [
98
+ [ 1 , 22 , 'error' , 'Cannot find name \'Window\'.' , ' index.d.ts' ] ,
99
+ [ 4 , 11 , 'error' , 'Cannot find name \'Window\'.' , ' index.test-d.ts' ] ,
86
100
] ) ;
87
101
} ) ;
88
102
0 commit comments