renovate/test/workers/branch/package-json.spec.js
Rhys Arkins 552b5e68c5 Refactor helpers (#382)
* Move yarn and npm helpers into branch worker

* Fix name

* Move package-json helper

* Update name

* Move changelog

* Move github-app

* Remove unused platform

* Move logger

* Fix lint
2017-06-29 07:29:41 +02:00

61 lines
1.8 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const packageJson = require('../../../lib/workers/branch/package-json');
const logger = require('../../_fixtures/logger');
function readFixture(fixture) {
return fs.readFileSync(
path.resolve(__dirname, `../../_fixtures/package-json/${fixture}`),
'utf8'
);
}
const input01Content = readFixture('inputs/01.json');
describe('workers/branch/package-json', () => {
describe('.setNewValue(currentFileContent, depType, depName, newVersion, logger)', () => {
it('replaces a dependency value', () => {
const outputContent = readFixture('outputs/011.json');
const testContent = packageJson.setNewValue(
input01Content,
'dependencies',
'cheerio',
'0.22.1',
logger
);
testContent.should.equal(outputContent);
});
it('replaces only the first instance of a value', () => {
const outputContent = readFixture('outputs/012.json');
const testContent = packageJson.setNewValue(
input01Content,
'devDependencies',
'angular-touch',
'1.6.1',
logger
);
testContent.should.equal(outputContent);
});
it('replaces only the second instance of a value', () => {
const outputContent = readFixture('outputs/013.json');
const testContent = packageJson.setNewValue(
input01Content,
'devDependencies',
'angular-sanitize',
'1.6.1',
logger
);
testContent.should.equal(outputContent);
});
it('handles the case where the desired version is already supported', () => {
const testContent = packageJson.setNewValue(
input01Content,
'devDependencies',
'angular-touch',
'1.5.8',
logger
);
testContent.should.equal(input01Content);
});
});
});