|
1 | 1 | async function test(description: string, testFunction: () => any | Promise<any>) {
|
2 | 2 | try {
|
3 |
| - const result = await testFunction(); |
4 |
| - if (!result) { throw result; } |
5 |
| - console.log(`✔ ${description}`); |
6 |
| - } catch (error) { |
7 |
| - console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); |
8 |
| - } |
| 3 | + const result = await testFunction(); |
| 4 | + if (!result) { throw result; } |
| 5 | + console.log(`✔ ${description}`); |
| 6 | + } catch (error) { |
| 7 | + console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); |
| 8 | + } |
9 | 9 | }
|
10 | 10 |
|
11 | 11 | console.log('loaded ts-ext-ts/index.ts');
|
12 | 12 |
|
13 | 13 | test(
|
14 |
| - 'has CJS context', |
15 |
| - () => typeof require !== 'undefined' || typeof module !== 'undefined', |
| 14 | + 'has CJS context', |
| 15 | + () => typeof require !== 'undefined' || typeof module !== 'undefined', |
16 | 16 | );
|
17 | 17 |
|
18 | 18 | test(
|
19 |
| - 'import.meta.url', |
20 |
| - () => Boolean(import.meta.url), |
| 19 | + 'import.meta.url', |
| 20 | + () => Boolean(import.meta.url), |
21 | 21 | );
|
22 | 22 |
|
23 | 23 | test(
|
24 |
| - 'name in error', |
25 |
| - () => { |
26 |
| - let nameInError; |
27 |
| - try { |
28 |
| - nameInError(); |
29 |
| - } catch (error) { |
30 |
| - return error.message.includes('nameInError'); |
31 |
| - } |
32 |
| - }, |
| 24 | + 'name in error', |
| 25 | + () => { |
| 26 | + let nameInError; |
| 27 | + try { |
| 28 | + nameInError(); |
| 29 | + } catch (error) { |
| 30 | + return error.message.includes('nameInError'); |
| 31 | + } |
| 32 | + }, |
33 | 33 | );
|
34 | 34 |
|
35 | 35 | test(
|
36 |
| - 'sourcemaps', |
37 |
| - () => new Error().stack!.includes(':37:'), |
| 36 | + 'sourcemaps', |
| 37 | + () => { |
| 38 | + const { stack } = new Error(); |
| 39 | + return ( |
| 40 | + stack!.includes(`${__filename}:38:`) |
| 41 | + || stack!.includes(`${__filename.toLowerCase()}:38:`) |
| 42 | + ); |
| 43 | + }, |
38 | 44 | );
|
39 | 45 |
|
40 | 46 | test(
|
41 |
| - 'has dynamic import', |
42 |
| - () => import('fs').then(Boolean), |
| 47 | + 'has dynamic import', |
| 48 | + () => import('fs').then(Boolean), |
43 | 49 | );
|
44 | 50 |
|
45 | 51 | test(
|
46 |
| - 'resolves optional node prefix', |
47 |
| - () => import('node:fs').then(Boolean), |
| 52 | + 'resolves optional node prefix', |
| 53 | + () => import('node:fs').then(Boolean), |
48 | 54 | );
|
49 | 55 |
|
50 | 56 | test(
|
51 |
| - 'resolves required node prefix', |
52 |
| - () => import('node:test').then(Boolean), |
| 57 | + 'resolves required node prefix', |
| 58 | + () => import('node:test').then(Boolean), |
53 | 59 | );
|
54 | 60 |
|
55 | 61 | test(
|
|
0 commit comments