Skip to content

Commit 3606c53

Browse files
Giovanni BucciJakobJingleheimer
authored andcommitted
test: refactor test-esm-type-field-errors
Co-Authored-By: Jacob Smith <jacob@frende.me> PR-URL: #54368 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e635e09 commit 3606c53

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

test/es-module/test-esm-type-field-errors.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const common = require('../common');
33
const assert = require('assert');
44
const exec = require('child_process').execFile;
5+
const { describe, it } = require('node:test');
56

67
const mjsFile = require.resolve('../fixtures/es-modules/mjs-file.mjs');
78
const cjsFile = require.resolve('../fixtures/es-modules/cjs-file.cjs');
@@ -20,18 +21,42 @@ expect('', packageTypeCommonJsMain, 'package-type-commonjs');
2021
expect('', packageWithoutTypeMain, 'package-without-type');
2122

2223
// Check that --input-type isn't allowed for files
23-
expect('--input-type=module', packageTypeModuleMain,
24-
'ERR_INPUT_TYPE_NOT_ALLOWED', true);
25-
26-
try {
27-
require('../fixtures/es-modules/package-type-module/index.js');
28-
assert.fail('Expected CJS to fail loading from type: module package.');
29-
} catch (e) {
30-
assert.strictEqual(e.name, 'Error');
31-
assert.strictEqual(e.code, 'ERR_REQUIRE_ESM');
32-
assert(e.toString().match(/require\(\) of ES Module/g));
33-
assert(e.message.match(/require\(\) of ES Module/g));
34-
}
24+
describe('ESM type field errors', { concurrency: true }, () => {
25+
it('.cjs file', () => {
26+
expect('', cjsFile, '.cjs file');
27+
});
28+
29+
it('.mjs file', () => {
30+
expect('', mjsFile, '.mjs file');
31+
});
32+
33+
it('package.json with "type": "module"', () => {
34+
expect('', packageTypeModuleMain, 'package-type-module');
35+
});
36+
37+
it('package.json with "type": "commonjs"', () => {
38+
expect('', packageTypeCommonJsMain, 'package-type-commonjs');
39+
});
40+
41+
it('package.json with no "type" field', () => {
42+
expect('', packageWithoutTypeMain, 'package-without-type');
43+
});
44+
45+
it('--input-type=module disallowed for files', () => {
46+
expect(
47+
'--input-type=module',
48+
packageTypeModuleMain,
49+
'ERR_INPUT_TYPE_NOT_ALLOWED',
50+
true,
51+
);
52+
});
53+
54+
it('--input-type=module disallowed for directories', () => {
55+
assert.throws(() => require('../fixtures/es-modules/package-type-module/index.js'), {
56+
code: 'ERR_REQUIRE_ESM'
57+
});
58+
});
59+
});
3560

3661
function expect(opt = '', inputFile, want, wantsError = false) {
3762
const argv = [inputFile];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy