Skip to content

Commit 19634b2

Browse files
committed
chore: tests for unknown config warnings
1 parent a8bedd4 commit 19634b2

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

workspaces/config/test/index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const fsMocks = {
4545
'node:fs': mockFs,
4646
}
4747

48-
const { definitions, shorthands, flatten } = t.mock('../lib/definitions/index.js', fsMocks)
48+
const { definitions, shorthands, nerfDarts, flatten } = t.mock('../lib/definitions/index.js', fsMocks)
4949
const Config = t.mock('../', fsMocks)
5050

5151
// because we used t.mock above, the require cache gets blown and we lose our direct equality
@@ -381,6 +381,8 @@ loglevel = yolo
381381
// warn logs are emitted as a side effect of validate
382382
config.validate()
383383
t.strictSame(logs.filter(l => l[0] === 'warn'), [
384+
['warn', 'Unknown builtin config "builtin-config". This will stop working in the next major version of npm.'],
385+
['warn', 'Unknown builtin config "foo". This will stop working in the next major version of npm.'],
384386
['warn', 'invalid config', 'registry="hello"', 'set in command line options'],
385387
['warn', 'invalid config', 'Must be', 'full url with "http://"'],
386388
['warn', 'invalid config', 'proxy="hello"', 'set in command line options'],
@@ -397,6 +399,13 @@ loglevel = yolo
397399
['warn', 'invalid config', 'prefix=true', 'set in command line options'],
398400
['warn', 'invalid config', 'Must be', 'valid filesystem path'],
399401
['warn', 'config', 'also', 'Please use --include=dev instead.'],
402+
['warn', 'Unknown env config "foo". This will stop working in the next major version of npm.'],
403+
['warn', 'Unknown project config "project-config". This will stop working in the next major version of npm.'],
404+
['warn', 'Unknown project config "foo". This will stop working in the next major version of npm.'],
405+
['warn', 'Unknown user config "user-config-from-builtin". This will stop working in the next major version of npm.'],
406+
['warn', 'Unknown user config "foo". This will stop working in the next major version of npm.'],
407+
['warn', 'Unknown global config "global-config". This will stop working in the next major version of npm.'],
408+
['warn', 'Unknown global config "foo". This will stop working in the next major version of npm.'],
400409
['warn', 'invalid config', 'loglevel="yolo"', `set in ${resolve(path, 'project/.npmrc')}`],
401410
['warn', 'invalid config', 'Must be one of:',
402411
['silent', 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'].join(', '),
@@ -591,6 +600,12 @@ loglevel = yolo
591600
['warn', 'invalid config', 'prefix=true', 'set in command line options'],
592601
['warn', 'invalid config', 'Must be', 'valid filesystem path'],
593602
['warn', 'config', 'also', 'Please use --include=dev instead.'],
603+
['warn', 'Unknown env config "foo". This will stop working in the next major version of npm.'],
604+
['warn', 'Unknown user config "default-user-config-in-home". This will stop working in the next major version of npm.'],
605+
['warn', 'Unknown user config "foo". This will stop working in the next major version of npm.'],
606+
['warn', 'Unknown global config "global-config". This will stop working in the next major version of npm.'],
607+
['warn', 'Unknown global config "foo". This will stop working in the next major version of npm.'],
608+
['warn', 'Unknown global config "asdf". This will stop working in the next major version of npm.'],
594609
])
595610
logs.length = 0
596611
})
@@ -1228,6 +1243,7 @@ t.test('workspaces', async (t) => {
12281243
cwd: join(`${path}/workspaces/three`),
12291244
shorthands,
12301245
definitions,
1246+
nerfDarts,
12311247
})
12321248

12331249
await config.load()
@@ -1253,6 +1269,7 @@ t.test('workspaces', async (t) => {
12531269
cwd: join(`${path}/workspaces/one`),
12541270
shorthands,
12551271
definitions,
1272+
nerfDarts,
12561273
})
12571274

12581275
await config.load()
@@ -1274,6 +1291,7 @@ t.test('workspaces', async (t) => {
12741291
cwd: join(`${path}/workspaces/one`),
12751292
shorthands,
12761293
definitions,
1294+
nerfDarts,
12771295
})
12781296

12791297
await config.load()
@@ -1295,6 +1313,7 @@ t.test('workspaces', async (t) => {
12951313
cwd: join(`${path}/workspaces/one`),
12961314
shorthands,
12971315
definitions,
1316+
nerfDarts,
12981317
})
12991318

13001319
await config.load()
@@ -1316,6 +1335,7 @@ t.test('workspaces', async (t) => {
13161335
cwd: join(`${path}/workspaces/one`),
13171336
shorthands,
13181337
definitions,
1338+
nerfDarts,
13191339
})
13201340

13211341
await config.load()
@@ -1337,6 +1357,7 @@ t.test('workspaces', async (t) => {
13371357
cwd: join(`${path}/workspaces/one`),
13381358
shorthands,
13391359
definitions,
1360+
nerfDarts,
13401361
excludeNpmCwd: true,
13411362
})
13421363

@@ -1365,6 +1386,7 @@ t.test('workspaces', async (t) => {
13651386
cwd: join(`${path}/workspaces/one`),
13661387
shorthands,
13671388
definitions,
1389+
nerfDarts,
13681390
})
13691391

13701392
await config.load()
@@ -1480,7 +1502,7 @@ t.test('catch project config prefix error', async t => {
14801502
})
14811503
const config = new Config({
14821504
npmPath: `${path}/npm`,
1483-
argv: [process.execPath, __filename, '--projectconfig', `${path}/project/.npmrc`],
1505+
argv: [process.execPath, __filename],
14841506
cwd: join(`${path}/project`),
14851507
shorthands,
14861508
definitions,
@@ -1492,7 +1514,7 @@ t.test('catch project config prefix error', async t => {
14921514
logs.length = 0
14931515
// config.load() triggers the error to be logged
14941516
await config.load()
1495-
const filtered = logs.filter(l => l[0] !== 'silly')
1517+
const filtered = logs.filter(l => l[0] === 'error')
14961518
t.match(filtered, [[
14971519
'error', 'config', `prefix cannot be changed from project config: ${path}`,
14981520
]], 'Expected error logged')

0 commit comments

Comments
 (0)