Skip to content

Commit 105d77f

Browse files
committed
Adds --no-warning
1 parent 9c8d726 commit 105d77f

File tree

3 files changed

+65
-30
lines changed

3 files changed

+65
-30
lines changed

test/es-module/test-esm-package-map.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,37 +33,43 @@ describe('ESM: --experimental-package-map', () => {
3333
describe('basic resolution', () => {
3434
it('resolves a direct dependency', async () => {
3535
const { code, stdout, stderr } = await spawnPromisified(execPath, [
36+
'--no-warnings',
3637
'--experimental-package-map', packageMapPath,
3738
'--input-type=module',
3839
'--eval',
3940
`import dep from 'dep-a'; console.log(dep);`,
4041
], { cwd: fixtures.path('package-map/root') });
4142

43+
assert.strictEqual(stderr, '');
4244
assert.match(stdout, /dep-a-value/);
4345
assert.strictEqual(code, 0, stderr);
4446
});
4547

4648
it('resolves a subpath export', async () => {
4749
const { code, stdout, stderr } = await spawnPromisified(execPath, [
50+
'--no-warnings',
4851
'--experimental-package-map', packageMapPath,
4952
'--input-type=module',
5053
'--eval',
5154
`import util from 'dep-a/lib/util'; console.log(util);`,
5255
], { cwd: fixtures.path('package-map/root') });
5356

57+
assert.strictEqual(stderr, '');
5458
assert.match(stdout, /dep-a-util/);
5559
assert.strictEqual(code, 0, stderr);
5660
});
5761

5862
it('resolves transitive dependency from allowed package', async () => {
5963
const { code, stdout, stderr } = await spawnPromisified(execPath, [
64+
'--no-warnings',
6065
'--experimental-package-map', packageMapPath,
6166
'--input-type=module',
6267
'--eval',
6368
// dep-b can access dep-a
6469
`import depB from 'dep-b'; console.log(depB);`,
6570
], { cwd: fixtures.path('package-map/root') });
6671

72+
assert.strictEqual(stderr, '');
6773
assert.match(stdout, /dep-b using dep-a-value/);
6874
assert.strictEqual(code, 0, stderr);
6975
});
@@ -74,18 +80,21 @@ describe('ESM: --experimental-package-map', () => {
7480
describe('resolution boundaries', () => {
7581
it('falls back for builtin modules', async () => {
7682
const { code, stdout, stderr } = await spawnPromisified(execPath, [
83+
'--no-warnings',
7784
'--experimental-package-map', packageMapPath,
7885
'--input-type=module',
7986
'--eval',
8087
`import fs from 'node:fs'; console.log(typeof fs.readFileSync);`,
8188
], { cwd: fixtures.path('package-map/root') });
8289

90+
assert.strictEqual(stderr, '');
8391
assert.match(stdout, /function/);
8492
assert.strictEqual(code, 0, stderr);
8593
});
8694

8795
it('throws when parent not in map', async () => {
8896
const { code, stderr } = await spawnPromisified(execPath, [
97+
'--no-warnings',
8998
'--experimental-package-map', packageMapPath,
9099
'--input-type=module',
91100
'--eval',
@@ -102,6 +111,7 @@ describe('ESM: --experimental-package-map', () => {
102111
describe('error handling', () => {
103112
it('throws ERR_PACKAGE_MAP_INVALID for invalid JSON', async () => {
104113
const { code, stderr } = await spawnPromisified(execPath, [
114+
'--no-warnings',
105115
'--experimental-package-map',
106116
fixtures.path('package-map/package-map-invalid-syntax.json'),
107117
'--input-type=module',
@@ -114,6 +124,7 @@ describe('ESM: --experimental-package-map', () => {
114124

115125
it('throws ERR_PACKAGE_MAP_INVALID for missing packages field', async () => {
116126
const { code, stderr } = await spawnPromisified(execPath, [
127+
'--no-warnings',
117128
'--experimental-package-map',
118129
fixtures.path('package-map/package-map-invalid-schema.json'),
119130
'--input-type=module',
@@ -127,6 +138,7 @@ describe('ESM: --experimental-package-map', () => {
127138

128139
it('throws ERR_PACKAGE_MAP_KEY_NOT_FOUND for undefined dependency key', async () => {
129140
const { code, stderr } = await spawnPromisified(execPath, [
141+
'--no-warnings',
130142
'--experimental-package-map',
131143
fixtures.path('package-map/package-map-missing-dep.json'),
132144
'--input-type=module',
@@ -140,6 +152,7 @@ describe('ESM: --experimental-package-map', () => {
140152

141153
it('throws for non-existent map file', async () => {
142154
const { code, stderr } = await spawnPromisified(execPath, [
155+
'--no-warnings',
143156
'--experimental-package-map', '/nonexistent/package-map.json',
144157
'--input-type=module',
145158
'--eval', `import x from 'dep-a';`,
@@ -152,6 +165,7 @@ describe('ESM: --experimental-package-map', () => {
152165

153166
it('throws ERR_PACKAGE_MAP_INVALID for unsupported URL scheme in path', async () => {
154167
const { code, stderr } = await spawnPromisified(execPath, [
168+
'--no-warnings',
155169
'--experimental-package-map',
156170
fixtures.path('package-map/package-map-https-path.json'),
157171
'--input-type=module',
@@ -166,18 +180,21 @@ describe('ESM: --experimental-package-map', () => {
166180

167181
it('accepts file:// URLs in path', async () => {
168182
const { code, stdout, stderr } = await spawnPromisified(execPath, [
183+
'--no-warnings',
169184
'--experimental-package-map', fileUrlFixturePath,
170185
'--input-type=module',
171186
'--eval',
172187
`import dep from 'dep-a'; console.log(dep);`,
173188
], { cwd: fixtures.path('package-map/root') });
174189

190+
assert.strictEqual(stderr, '');
175191
assert.match(stdout, /dep-a-value/);
176192
assert.strictEqual(code, 0, stderr);
177193
});
178194

179195
it('throws ERR_PACKAGE_MAP_INVALID for duplicate package paths', async () => {
180196
const { code, stderr } = await spawnPromisified(execPath, [
197+
'--no-warnings',
181198
'--experimental-package-map',
182199
fixtures.path('package-map/package-map-duplicate-path.json'),
183200
'--input-type=module',
@@ -196,11 +213,13 @@ describe('ESM: --experimental-package-map', () => {
196213
describe('disabled by default', () => {
197214
it('has no impact when flag not set', async () => {
198215
const { code, stdout, stderr } = await spawnPromisified(execPath, [
216+
'--no-warnings',
199217
'--input-type=module',
200218
'--eval',
201219
`import fs from 'node:fs'; console.log('ok');`,
202220
]);
203221

222+
assert.strictEqual(stderr, '');
204223
assert.match(stdout, /ok/);
205224
assert.strictEqual(code, 0, stderr);
206225
});
@@ -211,24 +230,28 @@ describe('ESM: --experimental-package-map', () => {
211230
describe('package.json exports integration', () => {
212231
it('respects conditional exports (import)', async () => {
213232
const { code, stdout, stderr } = await spawnPromisified(execPath, [
233+
'--no-warnings',
214234
'--experimental-package-map', packageMapPath,
215235
'--input-type=module',
216236
'--eval',
217237
`import { format } from 'dep-a'; console.log(format);`,
218238
], { cwd: fixtures.path('package-map/root') });
219239

240+
assert.strictEqual(stderr, '');
220241
assert.match(stdout, /esm/); // Should get ESM export
221242
assert.strictEqual(code, 0, stderr);
222243
});
223244

224245
it('respects pattern exports', async () => {
225246
const { code, stdout, stderr } = await spawnPromisified(execPath, [
247+
'--no-warnings',
226248
'--experimental-package-map', packageMapPath,
227249
'--input-type=module',
228250
'--eval',
229251
`import util from 'dep-a/lib/util'; console.log(util);`,
230252
], { cwd: fixtures.path('package-map/root') });
231253

254+
assert.strictEqual(stderr, '');
232255
assert.match(stdout, /dep-a-util/);
233256
assert.strictEqual(code, 0, stderr);
234257
});
@@ -259,13 +282,15 @@ describe('ESM: --experimental-package-map', () => {
259282
// incorrectly matched as inside pkg (at ./pkg) just because
260283
// the string "./pkg-other" starts with "./pkg"
261284
const { code, stdout, stderr } = await spawnPromisified(execPath, [
285+
'--no-warnings',
262286
'--experimental-package-map',
263287
fixtures.path('package-map/package-map-path-prefix.json'),
264288
'--input-type=module',
265289
'--eval',
266290
`import pkg from 'pkg'; console.log(pkg);`,
267291
], { cwd: fixtures.path('package-map/pkg-other') });
268292

293+
assert.strictEqual(stderr, '');
269294
assert.match(stdout, /pkg-value/);
270295
assert.strictEqual(code, 0, stderr);
271296
});
@@ -276,13 +301,15 @@ describe('ESM: --experimental-package-map', () => {
276301
describe('external package paths', () => {
277302
it('resolves packages outside the package map directory via relative paths', async () => {
278303
const { code, stdout, stderr } = await spawnPromisified(execPath, [
304+
'--no-warnings',
279305
'--experimental-package-map',
280306
fixtures.path('package-map/nested-project/package-map-external-deps.json'),
281307
'--input-type=module',
282308
'--eval',
283309
`import dep from 'dep-a'; console.log(dep);`,
284310
], { cwd: fixtures.path('package-map/nested-project/src') });
285311

312+
assert.strictEqual(stderr, '');
286313
assert.match(stdout, /dep-a-value/);
287314
assert.strictEqual(code, 0, stderr);
288315
});
@@ -297,12 +324,14 @@ describe('ESM: --experimental-package-map', () => {
297324
// app-18 and app-19 both import 'react', but the package map wires
298325
// them to react@18 and react@19 respectively.
299326
const { code, stdout, stderr } = await spawnPromisified(execPath, [
327+
'--no-warnings',
300328
'--experimental-package-map', versionForkMap,
301329
'--input-type=module',
302330
'--eval',
303331
`import app18 from 'app-18'; import app19 from 'app-19'; console.log(app18); console.log(app19);`,
304332
], { cwd: fixtures.path('package-map/root') });
305333

334+
assert.strictEqual(stderr, '');
306335
assert.match(stdout, /app-18 using react 18/);
307336
assert.match(stdout, /app-19 using react 19/);
308337
assert.strictEqual(code, 0, stderr);
@@ -319,12 +348,14 @@ describe('ESM: --experimental-package-map', () => {
319348
// path (./root). The longest matching path should win, so code in
320349
// inner should resolve dep-a (inner's dep), not be treated as root.
321350
const { code, stdout, stderr } = await spawnPromisified(execPath, [
351+
'--no-warnings',
322352
'--experimental-package-map', longestPathMap,
323353
'--input-type=module',
324354
'--eval',
325355
`import inner from 'inner'; console.log(inner);`,
326356
], { cwd: fixtures.path('package-map/root') });
327357

358+
assert.strictEqual(stderr, '');
328359
assert.match(stdout, /inner using dep-a-value/);
329360
assert.strictEqual(code, 0, stderr);
330361
});
@@ -333,6 +364,7 @@ describe('ESM: --experimental-package-map', () => {
333364
// Root does not list dep-a in its dependencies, so importing it
334365
// from root should fail with ERR_MODULE_NOT_FOUND.
335366
const { code, stderr } = await spawnPromisified(execPath, [
367+
'--no-warnings',
336368
'--experimental-package-map', longestPathMap,
337369
'--input-type=module',
338370
'--eval',

test/parallel/test-package-map-cli.js

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('--experimental-package-map CLI behavior', () => {
1414

1515
it('works via NODE_OPTIONS', onlyIfNodeOptionsSupport, () => {
1616
const { status, stdout, stderr } = spawnSync(process.execPath, [
17+
'--no-warnings',
1718
'-e',
1819
`const dep = require('dep-a'); console.log(dep);`,
1920
], {
@@ -25,6 +26,7 @@ describe('--experimental-package-map CLI behavior', () => {
2526
},
2627
});
2728

29+
assert.strictEqual(stderr, '');
2830
assert.match(stdout, /dep-a-value/);
2931
assert.strictEqual(status, 0, stderr);
3032
});
@@ -46,6 +48,7 @@ describe('--experimental-package-map CLI behavior', () => {
4648

4749
it('accepts relative path', () => {
4850
const { status, stdout, stderr } = spawnSync(process.execPath, [
51+
'--no-warnings',
4952
'--experimental-package-map', '../package-map.json',
5053
'-e',
5154
`const dep = require('dep-a'); console.log(dep.default);`,
@@ -54,50 +57,23 @@ describe('--experimental-package-map CLI behavior', () => {
5457
encoding: 'utf8',
5558
});
5659

60+
assert.strictEqual(stderr, '');
5761
// Relative path ../package-map.json resolved from cwd (root/)
5862
assert.match(stdout, /dep-a-value/);
5963
assert.strictEqual(status, 0, stderr);
6064
});
6165

6266
it('accepts absolute path', () => {
6367
const { status, stderr } = spawnSync(process.execPath, [
68+
'--no-warnings',
6469
'--experimental-package-map', fixtures.path('package-map/package-map.json'),
6570
'-e',
6671
`console.log('ok');`,
6772
], {
6873
encoding: 'utf8',
6974
});
7075

71-
assert.strictEqual(status, 0, stderr);
72-
});
73-
74-
it('does not emit warning when flag not set', () => {
75-
const { status, stderr } = spawnSync(process.execPath, [
76-
'-e',
77-
`console.log('ok');`,
78-
], {
79-
encoding: 'utf8',
80-
});
81-
82-
assert.doesNotMatch(stderr, /ExperimentalWarning/);
83-
assert.doesNotMatch(stderr, /[Pp]ackage map/);
84-
assert.strictEqual(status, 0, stderr);
85-
});
86-
87-
it('can be combined with other flags', () => {
88-
const { status, stdout, stderr } = spawnSync(process.execPath, [
89-
'--experimental-package-map', fixtures.path('package-map/package-map.json'),
90-
'--no-warnings',
91-
'-e',
92-
`const dep = require('dep-a'); console.log(dep);`,
93-
], {
94-
cwd: fixtures.path('package-map/root'),
95-
encoding: 'utf8',
96-
});
97-
98-
assert.match(stdout, /dep-a-value/);
99-
// Warning should be suppressed
100-
assert.doesNotMatch(stderr, /ExperimentalWarning/);
76+
assert.strictEqual(stderr, '');
10177
assert.strictEqual(status, 0, stderr);
10278
});
10379
});

0 commit comments

Comments
 (0)