|
| 1 | +import { skip, spawnPromisified } from '../common/index.mjs'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | +import { match, strictEqual } from 'node:assert'; |
| 4 | +import { test } from 'node:test'; |
| 5 | + |
| 6 | +if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); |
| 7 | + |
| 8 | +test('execute a TypeScript file with transformation enabled', async () => { |
| 9 | + const result = await spawnPromisified(process.execPath, [ |
| 10 | + '--experimental-enable-transformation', |
| 11 | + '--no-warnings', |
| 12 | + fixtures.path('typescript/ts/transformation/test-enum.ts'), |
| 13 | + ]); |
| 14 | + |
| 15 | + strictEqual(result.stderr, ''); |
| 16 | + match(result.stdout, /Hello, TypeScript!/); |
| 17 | + strictEqual(result.code, 0); |
| 18 | +}); |
| 19 | + |
| 20 | +test('execute a TypeScript file with transformation enabled and sourcemaps', async () => { |
| 21 | + const result = await spawnPromisified(process.execPath, [ |
| 22 | + '--experimental-enable-transformation', |
| 23 | + '--enable-source-maps', |
| 24 | + '--no-warnings', |
| 25 | + fixtures.path('typescript/ts/transformation/test-enum.ts'), |
| 26 | + ]); |
| 27 | + |
| 28 | + strictEqual(result.stderr, ''); |
| 29 | + match(result.stdout, /Hello, TypeScript!/); |
| 30 | + strictEqual(result.code, 0); |
| 31 | +}); |
| 32 | + |
| 33 | +test('reconstruct error of a TypeScript file with transformation enabled and sourcemaps', async () => { |
| 34 | + const result = await spawnPromisified(process.execPath, [ |
| 35 | + '--experimental-enable-transformation', |
| 36 | + '--enable-source-maps', |
| 37 | + '--no-warnings', |
| 38 | + fixtures.path('typescript/ts/transformation/test-enum-stacktrace.ts'), |
| 39 | + ]); |
| 40 | + |
| 41 | + match(result.stderr, /test-enum-stacktrace\.ts:4:7/); |
| 42 | + strictEqual(result.stdout, ''); |
| 43 | + strictEqual(result.code, 1); |
| 44 | +}); |
| 45 | + |
| 46 | +test('reconstruct error of a complex TypeScript file with transformation enabled and sourcemaps', async () => { |
| 47 | + const result = await spawnPromisified(process.execPath, [ |
| 48 | + '--experimental-enable-transformation', |
| 49 | + '--enable-source-maps', |
| 50 | + '--no-warnings', |
| 51 | + fixtures.path('typescript/ts/transformation/test-complex-stacktrace.ts'), |
| 52 | + ]); |
| 53 | + |
| 54 | + match(result.stderr, /Calculation failed: Division by zero!/); |
| 55 | + match(result.stderr, /test-complex-stacktrace\.ts:64/); |
| 56 | + match(result.stderr, /test-complex-stacktrace\.ts:64:19/); |
| 57 | + strictEqual(result.stdout, ''); |
| 58 | + strictEqual(result.code, 1); |
| 59 | +}); |
| 60 | + |
| 61 | +test('reconstruct error of a complex TypeScript file with transformation enabled without sourcemaps', async () => { |
| 62 | + const result = await spawnPromisified(process.execPath, [ |
| 63 | + '--experimental-enable-transformation', |
| 64 | + '--no-warnings', |
| 65 | + fixtures.path('typescript/ts/transformation/test-complex-stacktrace.ts'), |
| 66 | + ]); |
| 67 | + // The stack trace is not reconstructed without sourcemaps. |
| 68 | + match(result.stderr, /Calculation failed: Division by zero!/); |
| 69 | + match(result.stderr, /test-complex-stacktrace\.ts:50/); |
| 70 | + match(result.stderr, /test-complex-stacktrace\.ts:50:19/); |
| 71 | + strictEqual(result.stdout, ''); |
| 72 | + strictEqual(result.code, 1); |
| 73 | +}); |
| 74 | + |
| 75 | +// TODO (@marco-ippolito) this should fail |
| 76 | +test('elide unused imports', async () => { |
| 77 | + const result = await spawnPromisified(process.execPath, [ |
| 78 | + '--experimental-enable-transformation', |
| 79 | + '--no-warnings', |
| 80 | + fixtures.path('typescript/ts/transformation/test-unused-import.ts'), |
| 81 | + ]); |
| 82 | + strictEqual(result.stderr, ''); |
| 83 | + strictEqual(result.stdout, ''); |
| 84 | + strictEqual(result.code, 0); |
| 85 | +}); |
0 commit comments