Skip to content

Commit

Permalink
fix: resolved import issue with assert module
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcanaltin committed Jan 24, 2025
1 parent 23b8955 commit 05c573f
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions test/es-module/test-typescript-commonjs.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { skip, spawnPromisified } from '../common/index.mjs';

Check failure on line 1 in test/es-module/test-typescript-commonjs.mjs

View workflow job for this annotation

GitHub Actions / test-linux

--- stdout --- Test failure: 'expect failure of an .mts file with CommonJS syntax' Location: test/es-module/test-typescript-commonjs.mjs:61:1 AssertionError [ERR_ASSERTION]: stderr does not contain the expected warning at TestContext.<anonymous> (file:///home/runner/work/node/node/dir%20with%20$unusual%22chars%3F'%C3%A5%C3%9F%E2%88%82%C6%92%C2%A9%E2%88%86%C2%AC%E2%80%A6%60/test/es-module/test-typescript-commonjs.mjs:70:12) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Test.run (node:internal/test_runner/test:981:9) at async Test.processPendingSubtests (node:internal/test_runner/test:678:7) { generatedMessage: false, code: 'ERR_ASSERTION', actual: '(node:212541) Warning: Failed to load the ES module: /home/runner/work/node/node/dir%20with $unusual"chars?\'Ã¥Ã\x9Fâ\x88\x82Æ\x92©â\x88\x86¬â\x80¦`/test/fixtures/typescript/cts/test-cts-but-module-syntax.cts. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.\n' + '(Use `node --trace-warnings ...` to show where the warning was created)\n' + '/home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/typescript/cts/test-cts-but-module-syntax.cts:1\n' + "import util from 'node:util';\n" + '^^^^^^\n' + '\n' + 'SyntaxError: Cannot use import statement outside a module\n' + ' at wrapSafe (node:internal/modules/cjs/loader:1670:18)\n' + ' at Module._compile (node:internal/modules/cjs/loader:1712:20)\n' + ' at Object.loadCTS [as .cts] (node:internal/modules/cjs/loader:1801:10)\n' + '...', expected: 'Failed to load the ES module: /home/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/typescript/cts/test-cts-but-module-syntax.cts. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.', operator: 'includes' } Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout "/home/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-typescript-commonjs.mjs"

Check failure on line 1 in test/es-module/test-typescript-commonjs.mjs

View workflow job for this annotation

GitHub Actions / test-macOS (macos-14)

--- stdout --- Test failure: 'expect failure of an .mts file with CommonJS syntax' Location: test/es-module/test-typescript-commonjs.mjs:61:1 AssertionError [ERR_ASSERTION]: stderr does not contain the expected warning at TestContext.<anonymous> (file:///Users/runner/work/node/node/dir%20with%20$unusual%22chars%3F'%C3%A5%C3%9F%E2%88%82%C6%92%C2%A9%E2%88%86%C2%AC%E2%80%A6%60/test/es-module/test-typescript-commonjs.mjs:70:12) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Test.run (node:internal/test_runner/test:981:9) at async Test.processPendingSubtests (node:internal/test_runner/test:678:7) { generatedMessage: false, code: 'ERR_ASSERTION', actual: '(node:72164) Warning: Failed to load the ES module: /Users/runner/work/node/node/dir%20with $unusual"chars?\'Ã¥Ã\x9Fâ\x88\x82Æ\x92©â\x88\x86¬â\x80¦`/test/fixtures/typescript/cts/test-cts-but-module-syntax.cts. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.\n' + '(Use `node --trace-warnings ...` to show where the warning was created)\n' + '/Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/typescript/cts/test-cts-but-module-syntax.cts:1\n' + "import util from 'node:util';\n" + '^^^^^^\n' + '\n' + 'SyntaxError: Cannot use import statement outside a module\n' + ' at wrapSafe (node:internal/modules/cjs/loader:1670:18)\n' + ' at Module._compile (node:internal/modules/cjs/loader:1712:20)\n' + ' at Object.loadCTS [as .cts] (node:internal/modules/cjs/loader:1801:10)\n' + '...', expected: 'Failed to load the ES module: /Users/runner/work/node/node/dir%20with $unusual"chars?\'åß∂ƒ©∆¬…`/test/fixtures/typescript/cts/test-cts-but-module-syntax.cts. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.', operator: 'includes' } Command: out/Release/node --test-reporter=./test/common/test-error-reporter.js --test-reporter-destination=stdout "/Users/runner/work/node/node/dir%20with $unusual"chars?'åß∂ƒ©∆¬…`/test/es-module/test-typescript-commonjs.mjs"
import * as fixtures from '../common/fixtures.mjs';
import { match, strictEqual, assert } from 'node:assert';
import * as assert from 'node:assert';
import { test } from 'node:test';

if (!process.config.variables.node_use_amaro) skip('Requires Amaro');
Expand All @@ -14,9 +14,9 @@ test('require a .ts file with explicit extension succeeds', async () => {
cwd: fixtures.path('typescript/ts'),
});

strictEqual(result.stderr, '');
strictEqual(result.stdout, 'Hello, TypeScript!\n');
strictEqual(result.code, 0);
assert.strictEqual(result.stderr, '');
assert.strictEqual(result.stdout, 'Hello, TypeScript!\n');
assert.strictEqual(result.code, 0);
});

test('eval require a .ts file with implicit extension fails', async () => {
Expand All @@ -28,9 +28,9 @@ test('eval require a .ts file with implicit extension fails', async () => {
cwd: fixtures.path('typescript/ts'),
});

strictEqual(result.stdout, '');
match(result.stderr, /Error: Cannot find module/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /Error: Cannot find module/);
assert.strictEqual(result.code, 1);
});

test('eval require a .cts file with implicit extension fails', async () => {
Expand All @@ -42,9 +42,9 @@ test('eval require a .cts file with implicit extension fails', async () => {
cwd: fixtures.path('typescript/ts'),
});

strictEqual(result.stdout, '');
match(result.stderr, /Error: Cannot find module/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /Error: Cannot find module/);
assert.strictEqual(result.code, 1);
});

test('require a .ts file with implicit extension fails', async () => {
Expand All @@ -53,16 +53,16 @@ test('require a .ts file with implicit extension fails', async () => {
fixtures.path('typescript/cts/test-extensionless-require.ts'),
]);

strictEqual(result.stdout, '');
match(result.stderr, /Error: Cannot find module/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /Error: Cannot find module/);
assert.strictEqual(result.code, 1);
});

test('expect failure of an .mts file with CommonJS syntax', async () => {
const testFilePath = fixtures.path('typescript/cts/test-cts-but-module-syntax.cts');
const result = await spawnPromisified(process.execPath, [testFilePath]);

strictEqual(result.stdout, '');
assert.strictEqual(result.stdout, '');

const expectedWarning = `Failed to load the ES module: ${testFilePath}. Make sure to set "type": "module" in the nearest package.json file or use the .mjs extension.`;

Expand All @@ -77,7 +77,7 @@ test('expect failure of an .mts file with CommonJS syntax', async () => {
throw e;
}

strictEqual(result.code, 1);
assert.strictEqual(result.code, 1);
});

test('execute a .cts file importing a .cts file', async () => {
Expand All @@ -86,9 +86,9 @@ test('execute a .cts file importing a .cts file', async () => {
fixtures.path('typescript/cts/test-require-commonjs.cts'),
]);

strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
assert.strictEqual(result.stderr, '');
assert.match(result.stdout, /Hello, TypeScript!/);
assert.strictEqual(result.code, 0);
});

test('execute a .cts file importing a .ts file export', async () => {
Expand All @@ -97,9 +97,9 @@ test('execute a .cts file importing a .ts file export', async () => {
fixtures.path('typescript/cts/test-require-ts-file.cts'),
]);

strictEqual(result.stderr, '');
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
assert.strictEqual(result.stderr, '');
assert.match(result.stdout, /Hello, TypeScript!/);
assert.strictEqual(result.code, 0);
});

test('execute a .cts file importing a .mts file export', async () => {
Expand All @@ -108,9 +108,9 @@ test('execute a .cts file importing a .mts file export', async () => {
fixtures.path('typescript/cts/test-require-mts-module.cts'),
]);

strictEqual(result.stdout, '');
match(result.stderr, /Error \[ERR_REQUIRE_ESM\]: require\(\) of ES Module/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /Error \[ERR_REQUIRE_ESM\]: require\(\) of ES Module/);
assert.strictEqual(result.code, 1);
});

test('execute a .cts file importing a .mts file export', async () => {
Expand All @@ -119,28 +119,28 @@ test('execute a .cts file importing a .mts file export', async () => {
fixtures.path('typescript/cts/test-require-mts-module.cts'),
]);

match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
assert.match(result.stdout, /Hello, TypeScript!/);
assert.strictEqual(result.code, 0);
});

test('expect failure of a .cts file in node_modules', async () => {
const result = await spawnPromisified(process.execPath, [
fixtures.path('typescript/cts/test-cts-node_modules.cts'),
]);

strictEqual(result.stdout, '');
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
assert.strictEqual(result.code, 1);
});

test('expect failure of a .ts file in node_modules', async () => {
const result = await spawnPromisified(process.execPath, [
fixtures.path('typescript/cts/test-ts-node_modules.cts'),
]);

strictEqual(result.stdout, '');
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
assert.strictEqual(result.code, 1);
});

test('expect failure of a .cts requiring esm without default type module', async () => {
Expand All @@ -149,9 +149,9 @@ test('expect failure of a .cts requiring esm without default type module', async
fixtures.path('typescript/cts/test-mts-node_modules.cts'),
]);

strictEqual(result.stdout, '');
match(result.stderr, /ERR_REQUIRE_ESM/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /ERR_REQUIRE_ESM/);
assert.strictEqual(result.code, 1);
});

test('expect failure of a .cts file requiring esm in node_modules', async () => {
Expand All @@ -160,7 +160,7 @@ test('expect failure of a .cts file requiring esm in node_modules', async () =>
fixtures.path('typescript/cts/test-mts-node_modules.cts'),
]);

strictEqual(result.stdout, '');
match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
strictEqual(result.code, 1);
assert.strictEqual(result.stdout, '');
assert.match(result.stderr, /ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING/);
assert.strictEqual(result.code, 1);
});

0 comments on commit 05c573f

Please sign in to comment.