Fix missing dev dependencies (#35)

* Add test for missing devDependencies case

* Add check for depType
This commit is contained in:
Rhys Arkins 2017-01-13 10:03:32 +01:00 committed by GitHub
parent 6842afddac
commit 74c3aba2ba
3 changed files with 40 additions and 3 deletions

View file

@ -23,7 +23,7 @@ function extractDependencies(packageJson) {
const depTypes = ['dependencies', 'devDependencies']; const depTypes = ['dependencies', 'devDependencies'];
return depTypes.reduce((allDeps, depType) => { return depTypes.reduce((allDeps, depType) => {
// loop through each dependency within a type // loop through each dependency within a type
const depNames = Object.keys(packageJson[depType]) || []; const depNames = packageJson[depType] ? Object.keys(packageJson[depType]) : [];
return allDeps.concat(depNames.map(depName => ({ return allDeps.concat(depNames.map(depName => ({
depType, depType,
depName, depName,

View file

@ -0,0 +1,30 @@
{
"name": "renovate",
"description": "Client node modules for renovate",
"version": "1.0.0",
"author": "Rhys Arkins <rhys@keylocation.sg>",
"bugs": "https://github.com/singapore/renovate/issues",
"contributors": [
{
"name": "Rhys Arkins"
}
],
"dependencies": {
"autoprefixer": "6.5.0",
"bower": "~1.6.0",
"browserify": "13.1.0",
"browserify-css": "0.9.2",
"cheerio": "0.22.0",
"config": "1.21.0"
},
"homepage": "https://keylocation.sg",
"keywords": [
"Key Location",
"Singapore"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "http://github.com/singapore/renovate.git"
}
}

View file

@ -7,19 +7,26 @@ chai.should();
npm.setLogger(winston); npm.setLogger(winston);
const inputContent = fs.readFileSync('./test/_fixtures/package.json/inputs/01.json', 'utf8'); const input01Content = fs.readFileSync('./test/_fixtures/package.json/inputs/01.json', 'utf8');
const input02Content = fs.readFileSync('./test/_fixtures/package.json/inputs/02.json', 'utf8');
describe('npm helper', () => { describe('npm helper', () => {
describe('extractDependencies', () => { describe('extractDependencies', () => {
const extractedDependencies = npm.extractDependencies(JSON.parse(inputContent));
it('returns an array of correct length', () => { it('returns an array of correct length', () => {
const extractedDependencies = npm.extractDependencies(JSON.parse(input01Content));
extractedDependencies.should.be.instanceof(Array); extractedDependencies.should.be.instanceof(Array);
extractedDependencies.should.have.length(10); extractedDependencies.should.have.length(10);
}); });
it('each element contains non-null depType, depName, currentVersion', () => { it('each element contains non-null depType, depName, currentVersion', () => {
const extractedDependencies = npm.extractDependencies(JSON.parse(input01Content));
extractedDependencies.every(dep => dep.depType && dep.depName && dep.currentVersion) extractedDependencies.every(dep => dep.depType && dep.depName && dep.currentVersion)
.should.eql(true); .should.eql(true);
}); });
it('supports null devDependencies', () => {
const extractedDependencies = npm.extractDependencies(JSON.parse(input02Content));
extractedDependencies.should.be.instanceof(Array);
extractedDependencies.should.have.length(6);
});
}); });
describe('getUpgrades', () => { describe('getUpgrades', () => {
const testVersions = ['0.1.0', '1.0.0', '1.0.1', '1.1.0', '2.0.0-alpha1', '2.0.0', '2.0.1', '3.0.0', '3.1.0']; const testVersions = ['0.1.0', '1.0.0', '1.0.1', '1.1.0', '2.0.0-alpha1', '2.0.0', '2.0.1', '3.0.0', '3.1.0'];