mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 21:46:29 +00:00
adds helpful error message when files is overridden or empty
This commit is contained in:
parent
c4a0484759
commit
d4dc4e262b
2 changed files with 22 additions and 0 deletions
|
@ -19,6 +19,15 @@ const NoNameConfigFile = {
|
||||||
contributorsPerLine: 6,
|
contributorsPerLine: 6,
|
||||||
contributors: [],
|
contributors: [],
|
||||||
}
|
}
|
||||||
|
const NoFilesConfigFile = {
|
||||||
|
projectOwner: 'jfmengels',
|
||||||
|
projectName: 'all-contributors-cli',
|
||||||
|
imageSize: 100,
|
||||||
|
commit: false,
|
||||||
|
contributorsPerLine: 6,
|
||||||
|
contributors: [],
|
||||||
|
files: [],
|
||||||
|
}
|
||||||
|
|
||||||
test('Reading an absent configuration file throws a helpful error', () => {
|
test('Reading an absent configuration file throws a helpful error', () => {
|
||||||
expect(() => configFile.readConfig(absentFile)).toThrowError(
|
expect(() => configFile.readConfig(absentFile)).toThrowError(
|
||||||
|
@ -41,3 +50,11 @@ test('Should throw error and not allow editing config file if project name or ow
|
||||||
configFile.writeConfig(incompleteConfigFilePath, NoNameConfigFile),
|
configFile.writeConfig(incompleteConfigFilePath, NoNameConfigFile),
|
||||||
).toThrow(`Error! Project name is not set in ${incompleteConfigFilePath}`)
|
).toThrow(`Error! Project name is not set in ${incompleteConfigFilePath}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test(`throws if 'files' was overridden in .all-contributorsrc and is empty`, () => {
|
||||||
|
expect(() =>
|
||||||
|
configFile.writeConfig(incompleteConfigFilePath, NoFilesConfigFile),
|
||||||
|
).toThrow(
|
||||||
|
`Error! Project files was overridden and is empty in ${incompleteConfigFilePath}`,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
|
@ -24,6 +24,11 @@ function writeConfig(configPath, content) {
|
||||||
if (!content.projectName) {
|
if (!content.projectName) {
|
||||||
throw new Error(`Error! Project name is not set in ${configPath}`)
|
throw new Error(`Error! Project name is not set in ${configPath}`)
|
||||||
}
|
}
|
||||||
|
if (!content.files.length) {
|
||||||
|
throw new Error(
|
||||||
|
`Error! Project files was overridden and is empty in ${configPath}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`)
|
return pify(fs.writeFile)(configPath, `${JSON.stringify(content, null, 2)}\n`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue