File tree 3 files changed +26
-0
lines changed
3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -268,6 +268,14 @@ console.log(diagnostics.length);
268
268
// => 2
269
269
```
270
270
271
+ You can also make use of the CLI's formatter to generate the same formatting output when running ` tsd ` programmatically.
272
+
273
+ ``` ts
274
+ import tsd , {formatter } from ' tsd' ;
275
+
276
+ const formattedDiagnostics = formatter (await tsd ());
277
+ ```
278
+
271
279
### tsd(options?)
272
280
273
281
Retrieve the type definition diagnostics of the project.
Original file line number Diff line number Diff line change 1
1
import tsd from './lib' ;
2
+ import formatter from './lib/formatter' ;
2
3
3
4
export * from './lib/assertions/assert' ;
5
+ export { formatter } ;
4
6
export default tsd ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import path from 'path';
2
2
import test from 'ava' ;
3
3
import execa from 'execa' ;
4
4
import readPkgUp from 'read-pkg-up' ;
5
+ import tsd , { formatter } from '..' ;
5
6
6
7
interface ExecaError extends Error {
7
8
readonly exitCode : number ;
@@ -105,3 +106,18 @@ test('tsd logs stacktrace on failure', async t => {
105
106
t . true ( stderr . includes ( 'Error running tsd: JSONError: Unexpected end of JSON input while parsing empty string' ) ) ;
106
107
t . truthy ( stack ) ;
107
108
} ) ;
109
+
110
+ test ( 'exported formatter matches cli results' , async t => {
111
+ const options = {
112
+ cwd : path . join ( __dirname , 'fixtures/failure' ) ,
113
+ } ;
114
+
115
+ const { stderr : cliResults } = await t . throwsAsync < ExecaError > ( execa ( '../../../cli.js' , options ) ) ;
116
+
117
+ t . true ( cliResults . includes ( '✖ 5:19 Argument of type number is not assignable to parameter of type string.' ) ) ;
118
+
119
+ const tsdResults = await tsd ( options ) ;
120
+ const formattedResults = formatter ( tsdResults ) ;
121
+
122
+ t . true ( formattedResults . includes ( '✖ 5:19 Argument of type number is not assignable to parameter of type string.' ) ) ;
123
+ } ) ;
You can’t perform that action at this time.
0 commit comments