feat: throw an Error if package.json has duplicate "repository" key (#1656)

This commit is contained in:
Gregor Martynus
2020-10-11 14:59:51 -07:00
committed by GitHub
parent 18e35b28ad
commit b8fb35c7e1
5 changed files with 46 additions and 7 deletions
+18
View File
@@ -516,3 +516,21 @@ test('Throw an Error if one of the shareable config cannot be found', async (t)
code: 'MODULE_NOT_FOUND',
});
});
test('Throw an Error if package.json has duplicate "repository" key', async (t) => {
// Create a git repository, set the current working directory at the root of the repo
const {cwd} = await gitRepo();
// Create package.json with duplicate "repository" key
await writeFile(
path.resolve(cwd, 'package.json'),
`{
"repository": "https://github.com/octocat/repository",
"repository": "https://github.com/octocat/repository"
}`
);
const error = await t.throwsAsync(t.context.getConfig({cwd}));
t.is(error.code, 'EDUPLICATEREPOSITORYKEY');
t.is(error.message, 'Duplicate `"repository"` key in package.json.');
});