/
test-esm-type-flag-cli-entry.mjs
92 lines (80 loc) · 3.02 KB
/
test-esm-type-flag-cli-entry.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { spawnPromisified } from '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import { describe, it } from 'node:test';
import { match, strictEqual } from 'node:assert';
describe('--experimental-default-type=module should not support extension searching', { concurrency: true }, () => {
it('should support extension searching under --experimental-default-type=commonjs', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=commonjs',
'index',
], {
cwd: fixtures.path('es-modules/package-without-type'),
});
strictEqual(stdout, 'package-without-type\n');
strictEqual(stderr, '');
strictEqual(code, 0);
strictEqual(signal, null);
});
it('should error with implicit extension under --experimental-default-type=module', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
'index',
], {
cwd: fixtures.path('es-modules/package-without-type'),
});
match(stderr, /ENOENT.*Did you mean to import .*index\.js"\?/s);
strictEqual(stdout, '');
strictEqual(code, 1);
strictEqual(signal, null);
});
});
describe('--experimental-default-type=module should not parse paths as URLs', { concurrency: true }, () => {
it('should not parse a `?` in a filename as starting a query string', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
'file#1.js',
], {
cwd: fixtures.path('es-modules/package-without-type'),
});
strictEqual(stderr, '');
strictEqual(stdout, 'file#1\n');
strictEqual(code, 0);
strictEqual(signal, null);
});
it('should resolve `..`', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
'../package-without-type/file#1.js',
], {
cwd: fixtures.path('es-modules/package-without-type'),
});
strictEqual(stderr, '');
strictEqual(stdout, 'file#1\n');
strictEqual(code, 0);
strictEqual(signal, null);
});
it('should allow a leading `./`', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
'./file#1.js',
], {
cwd: fixtures.path('es-modules/package-without-type'),
});
strictEqual(stderr, '');
strictEqual(stdout, 'file#1\n');
strictEqual(code, 0);
strictEqual(signal, null);
});
it('should not require a leading `./`', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
'--experimental-default-type=module',
'file#1.js',
], {
cwd: fixtures.path('es-modules/package-without-type'),
});
strictEqual(stderr, '');
strictEqual(stdout, 'file#1\n');
strictEqual(code, 0);
strictEqual(signal, null);
});
});