Skip to content

Commit f207a60

Browse files
committed
Add auto detect ncurc tests. Minor cleanup.
1 parent cecce57 commit f207a60

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/bin/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ ${chalk.dim.underline(
120120

121121
// load .ncurc
122122
// Do not load when global option is set
123-
// Do not load when tests are running (an be overridden if configFilePath is set explicitly, or --mergeConfig option specified)
123+
// Do not load when tests are running (can be overridden if configFilePath is set explicitly, or --mergeConfig option specified)
124124
const rcResult =
125125
!programOpts.global && (!process.env.NCU_TESTS || configFilePath || mergeConfig)
126126
? await getNcuRc({ configFileName, configFilePath, packageFile, color })

src/lib/findPackage.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ async function findPackage(options: Options) {
3636
`No ${pkgFileName}`,
3737
)}\n\nPlease add a ${pkgFileName} to the current directory, specify the ${chalk.cyan(
3838
'--packageFile',
39-
)} or ${chalk.cyan('--packageData')} options, or pipe a ${pkgFileName} to stdin.`,
39+
)} or ${chalk.cyan('--packageData')} options, or pipe a ${pkgFileName} to stdin and specify ${chalk.cyan(
40+
'--stdin',
41+
)}.`,
4042
)
4143
}
4244

test/rc-config.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,38 @@ describe('rc-config', () => {
133133
await fs.rm(tempDir, { recursive: true, force: true })
134134
}
135135
})
136+
137+
it('auto detect .ncurc.json', async () => {
138+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
139+
const configFile = path.join(tempDir, '.ncurc.json')
140+
const pkgFile = path.join(tempDir, 'package.json')
141+
await fs.writeFile(configFile, '{"filter": "ncu-test-v2"}', 'utf-8')
142+
await fs.writeFile(pkgFile, '{ "dependencies": { "ncu-test-v2": "1.0.0", "ncu-test-tag": "0.1.0" } }', 'utf-8')
143+
try {
144+
// awkwardly, we have to set mergeConfig to enable autodetecting the rcconfig because otherwise it is explicitly disabled for tests
145+
const text = await spawn('node', [bin, '--mergeConfig'], { cwd: tempDir })
146+
// On OSX tempDir is /var/folders/cb/12345, but npm-check-updates recieves /private/var/folders/cb/12345 (maybe symlink?).
147+
// Therefore, ignore any directories prepended to the config file path.
148+
text.should.match(new RegExp(`Using config file ([^\n]*)?${configFile}`))
149+
} finally {
150+
await fs.rm(tempDir, { recursive: true, force: true })
151+
}
152+
})
153+
154+
it('auto detect .ncurc.cjs', async () => {
155+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
156+
const configFile = path.join(tempDir, '.ncurc.cjs')
157+
const pkgFile = path.join(tempDir, 'package.json')
158+
await fs.writeFile(configFile, 'module.exports = { "filter": "ncu-test-v2" }', 'utf-8')
159+
await fs.writeFile(pkgFile, '{ "dependencies": { "ncu-test-v2": "1.0.0", "ncu-test-tag": "0.1.0" } }', 'utf-8')
160+
try {
161+
// awkwardly, we have to set mergeConfig to enable autodetecting the rcconfig because otherwise it is explicitly disabled for tests
162+
const text = await spawn('node', [bin, '--mergeConfig'], { cwd: tempDir })
163+
// On OSX tempDir is /var/folders/cb/12345, but npm-check-updates recieves /private/var/folders/cb/12345 (maybe symlink?).
164+
// Therefore, ignore any directories prepended to the config file path.
165+
text.should.match(new RegExp(`Using config file ([^\n]*)?${configFile}`))
166+
} finally {
167+
await fs.rm(tempDir, { recursive: true, force: true })
168+
}
169+
})
136170
})

0 commit comments

Comments
 (0)