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