|
1 |
| -import { assert } from 'vitest'; |
2 |
| -import * as acorn from 'acorn'; |
3 |
| -import { tsPlugin } from '../src'; |
4 | 1 | import * as fs from 'fs';
|
5 | 2 | import * as path from 'path';
|
6 | 3 | import { describe } from 'vitest';
|
7 | 4 | import { it } from 'vitest';
|
8 |
| - |
9 |
| -export const Parser = acorn.Parser.extend(tsPlugin() as any); |
10 |
| - |
11 |
| -export const DtsParser = acorn.Parser.extend( |
12 |
| - tsPlugin({ |
13 |
| - dts: true |
14 |
| - }) as any |
15 |
| -); |
16 |
| - |
17 |
| -export const JsxParser = acorn.Parser.extend( |
18 |
| - tsPlugin({ |
19 |
| - jsx: true |
20 |
| - }) as any |
21 |
| -); |
22 |
| - |
23 |
| -export function equalNode(node, snapshot) { |
24 |
| - assert.deepEqual(JSON.parse(JSON.stringify(node)), snapshot, 'should be' + JSON.stringify(node)); |
25 |
| -} |
26 |
| - |
27 |
| -export function parseDtsSource(input: string) { |
28 |
| - return DtsParser.parse(input, { |
29 |
| - sourceType: 'module', |
30 |
| - ecmaVersion: 'latest', |
31 |
| - locations: true |
32 |
| - }); |
33 |
| -} |
34 |
| - |
35 |
| -export function parseJsxSource(input: string) { |
36 |
| - return JsxParser.parse(input, { |
37 |
| - sourceType: 'module', |
38 |
| - ecmaVersion: 'latest', |
39 |
| - locations: true |
40 |
| - }); |
41 |
| -} |
42 |
| - |
43 |
| -export function parseSource(input: string) { |
44 |
| - return Parser.parse(input, { |
45 |
| - sourceType: 'module', |
46 |
| - ecmaVersion: 'latest', |
47 |
| - locations: true |
48 |
| - }); |
49 |
| -} |
50 |
| - |
51 |
| -export function parseSourceShouldThrowError(input: string, message?: string) { |
52 |
| - try { |
53 |
| - Parser.parse(input, { |
54 |
| - sourceType: 'module', |
55 |
| - ecmaVersion: 'latest', |
56 |
| - locations: true |
57 |
| - }); |
58 |
| - |
59 |
| - assert.fail('should throw an error'); |
60 |
| - } catch (e) { |
61 |
| - if (message) { |
62 |
| - assert.equal(e.message, message); |
63 |
| - } |
64 |
| - } |
65 |
| -} |
66 |
| - |
67 |
| -export function generateSource(input: string[]): string { |
68 |
| - return input.join('\n'); |
69 |
| -} |
| 5 | +import { |
| 6 | + equalNode, |
| 7 | + parseDtsSource, |
| 8 | + parseJsxSource, |
| 9 | + parseSource, |
| 10 | + parseSourceShouldThrowError |
| 11 | +} from './utils'; |
70 | 12 |
|
71 | 13 | describe('tests', () => {
|
72 | 14 | fs.readdirSync(__dirname, { withFileTypes: true })
|
|
0 commit comments