|
1 | 1 | import * as path from 'path';
|
2 |
| -import test, {ExecutionContext} from 'ava'; |
| 2 | +import test from 'ava'; |
| 3 | +import {verify} from './fixtures/utils'; |
3 | 4 | import tsd from '..';
|
4 |
| -import {Diagnostic} from '../lib/interfaces'; |
5 |
| - |
6 |
| -type Expectation = [number, number, 'error' | 'warning', string, (string | RegExp)?]; |
7 |
| - |
8 |
| -/** |
9 |
| - * Verify a list of diagnostics. |
10 |
| - * |
11 |
| - * @param t - The AVA execution context. |
12 |
| - * @param diagnostics - List of diagnostics to verify. |
13 |
| - * @param expectations - Expected diagnostics. |
14 |
| - */ |
15 |
| -const verify = (t: ExecutionContext, diagnostics: Diagnostic[], expectations: Expectation[]) => { |
16 |
| - t.true(diagnostics.length === expectations.length); |
17 |
| - |
18 |
| - for (const [index, diagnostic] of diagnostics.entries()) { |
19 |
| - t.is(diagnostic.line, expectations[index][0]); |
20 |
| - t.is(diagnostic.column, expectations[index][1]); |
21 |
| - t.is(diagnostic.severity, expectations[index][2]); |
22 |
| - t.is(diagnostic.message, expectations[index][3]); |
23 |
| - |
24 |
| - const filename = expectations[index][4]; |
25 |
| - |
26 |
| - if (typeof filename === 'string') { |
27 |
| - t.is(diagnostic.fileName, filename); |
28 |
| - } else if (typeof filename === 'object') { |
29 |
| - t.regex(diagnostic.fileName, filename); |
30 |
| - } |
31 |
| - } |
32 |
| -}; |
33 | 5 |
|
34 | 6 | test('throw if no type definition was found', async t => {
|
35 | 7 | 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.');
|
|
0 commit comments