Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/util/__tests__/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ const NoNameConfigFile = {
contributorsPerLine: 6,
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', () => {
expect(() => configFile.readConfig(absentFile)).toThrowError(
Expand All @@ -41,3 +50,11 @@ test('Should throw error and not allow editing config file if project name or ow
configFile.writeConfig(incompleteConfigFilePath, NoNameConfigFile),
).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}`,
)
})
5 changes: 5 additions & 0 deletions src/util/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function writeConfig(configPath, content) {
if (!content.projectName) {
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`)
}

Expand Down