2024-08-02 10:37:36 +00:00
|
|
|
import { skip, spawnPromisified } from '../common/index.mjs';
|
2024-07-24 16:30:06 +00:00
|
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
|
|
import { match, strictEqual } from 'node:assert';
|
|
|
|
import { test } from 'node:test';
|
|
|
|
|
2024-08-02 10:37:36 +00:00
|
|
|
if (!process.config.variables.node_use_amaro) skip('Requires Amaro');
|
|
|
|
|
2024-07-24 16:30:06 +00:00
|
|
|
test('expect failure of a .mts file with CommonJS syntax', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
fixtures.path('typescript/mts/test-mts-but-commonjs-syntax.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
strictEqual(result.stdout, '');
|
|
|
|
match(result.stderr, /require is not defined in ES module scope, you can use import instead/);
|
|
|
|
strictEqual(result.code, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('execute an .mts file importing an .mts file', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
fixtures.path('typescript/mts/test-import-module.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
match(result.stderr, /Type Stripping is an experimental feature and might change at any time/);
|
|
|
|
match(result.stdout, /Hello, TypeScript!/);
|
|
|
|
strictEqual(result.code, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('execute an .mts file importing a .ts file', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
'--no-warnings',
|
|
|
|
fixtures.path('typescript/mts/test-import-ts-file.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
strictEqual(result.stderr, '');
|
|
|
|
match(result.stdout, /Hello, TypeScript!/);
|
|
|
|
strictEqual(result.code, 0);
|
|
|
|
});
|
|
|
|
|
2024-08-03 17:15:11 +00:00
|
|
|
test('execute an .mts file importing a .ts file with default-type module', async () => {
|
2024-07-24 16:30:06 +00:00
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
2024-08-03 17:15:11 +00:00
|
|
|
'--experimental-default-type=module',
|
2024-07-24 16:30:06 +00:00
|
|
|
'--no-warnings',
|
2024-08-03 17:15:11 +00:00
|
|
|
fixtures.path('typescript/mts/test-import-ts-file.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
strictEqual(result.stderr, '');
|
|
|
|
match(result.stdout, /Hello, TypeScript!/);
|
|
|
|
strictEqual(result.code, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('execute an .mts file importing a .cts file', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
2024-07-24 16:30:06 +00:00
|
|
|
'--no-warnings',
|
|
|
|
fixtures.path('typescript/mts/test-import-commonjs.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
strictEqual(result.stderr, '');
|
|
|
|
match(result.stdout, /Hello, TypeScript!/);
|
|
|
|
strictEqual(result.code, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('execute an .mts file with wrong default module', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
2024-09-26 14:21:37 +00:00
|
|
|
'--no-experimental-require-module',
|
2024-07-24 16:30:06 +00:00
|
|
|
'--experimental-default-type=commonjs',
|
|
|
|
fixtures.path('typescript/mts/test-import-module.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
strictEqual(result.stdout, '');
|
|
|
|
match(result.stderr, /Error \[ERR_REQUIRE_ESM\]: require\(\) of ES Module/);
|
|
|
|
strictEqual(result.code, 1);
|
|
|
|
});
|
|
|
|
|
2024-09-26 14:21:37 +00:00
|
|
|
test('execute an .mts file with wrong default module', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
'--experimental-require-module',
|
|
|
|
'--experimental-default-type=commonjs',
|
|
|
|
fixtures.path('typescript/mts/test-import-module.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
match(result.stdout, /Hello, TypeScript!/);
|
|
|
|
strictEqual(result.code, 0);
|
|
|
|
});
|
|
|
|
|
2024-07-24 16:30:06 +00:00
|
|
|
test('execute an .mts file from node_modules', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
fixtures.path('typescript/mts/test-mts-node_modules.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
|
|
|
|
strictEqual(result.stdout, '');
|
|
|
|
strictEqual(result.code, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('execute a .cts file from node_modules', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
fixtures.path('typescript/mts/test-cts-node_modules.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
|
|
|
|
strictEqual(result.stdout, '');
|
|
|
|
strictEqual(result.code, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('execute a .ts file from node_modules', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
fixtures.path('typescript/mts/test-ts-node_modules.mts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
|
|
|
|
strictEqual(result.stdout, '');
|
|
|
|
strictEqual(result.code, 1);
|
|
|
|
});
|
2024-08-03 17:15:11 +00:00
|
|
|
|
|
|
|
test('execute an empty .ts file', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
'--no-warnings',
|
|
|
|
fixtures.path('typescript/ts/test-empty-file.ts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
strictEqual(result.stderr, '');
|
|
|
|
strictEqual(result.stdout, '');
|
|
|
|
strictEqual(result.code, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('execute .ts file importing a module', async () => {
|
|
|
|
const result = await spawnPromisified(process.execPath, [
|
|
|
|
'--experimental-strip-types',
|
|
|
|
'--no-warnings',
|
|
|
|
fixtures.path('typescript/ts/test-import-fs.ts'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
strictEqual(result.stderr, '');
|
|
|
|
strictEqual(result.stdout, 'Hello, TypeScript!\n');
|
|
|
|
strictEqual(result.code, 0);
|
|
|
|
});
|