Skip to content

Commit

Permalink
fix(buildNumber): check build number for being a strict integer
Browse files Browse the repository at this point in the history
BREAKING CHANGE: build number must now be a strict integer

CLOSES: #37
  • Loading branch information
gligoran committed Oct 3, 2017
1 parent 5134fe9 commit f70f228
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"precommit": "npm run coverage",
"report-coverage": "nyc report --reporter=lcov",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"test": "npm run lint && mocha --compilers js:babel-register",
"test": "npm run lint && mocha --require babel-register",
"test:watch": "npm test -- --watch --reporter mocha-better-spec-reporter --reporter-options clear-screen=true",
"upload-coverage": "codecov"
},
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import fs from 'fs';
import {
Parser,
Builder
} from 'xml2js';
import { Parser, Builder } from 'xml2js';

import rethrow from './rethrow';

Expand Down Expand Up @@ -44,6 +41,11 @@ function cordovaSetVersion(...args) {
return;
}

if (buildNumber && buildNumber !== parseInt(buildNumber, 10)) {
callback(new TypeError('"buildNumber" argument must be an integer'));
return;
}

fs.readFile(configPath, 'UTF-8', (error, data) => {
if (error) {
callback(error);
Expand Down
12 changes: 12 additions & 0 deletions test/index.build-number-callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ function buildNumberCallbackTest() {
done();
});
});

it('should return an error about buildNumber type', done => {
fs.copySync(entryConfigFiles.MALFORMED, tempConfigFile);

cordovaSetVersion(86.2, error => {
expect(error).to.exist();
expect(error.message).to.contain('buildNumber');
expect(error.message).to.contain('must be an');

done();
});
});
});
}

Expand Down
21 changes: 14 additions & 7 deletions test/index.build-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ import { describe, it } from 'mocha';
import { expect } from 'chai';
import fs from 'fs-extra';

import useFakeRethrow from './use-fake-rethrow';
import { tempProvidedConfigFile, entryConfigFiles } from './configs';
import cordovaSetVersion from '../src/index';
import { tempConfigFile, entryConfigFiles } from './configs';

function buildNumberTest() {
describe('(buildNumber)', () => {
it('should not throw an error', done => {
fs.copySync(entryConfigFiles.VERSION_AND_BUILD, tempProvidedConfigFile);
it('should not throw an error', () => {
fs.copySync(entryConfigFiles.VERSION_AND_BUILD, tempConfigFile);

const cordovaSetVersion = useFakeRethrow(done);
expect(cordovaSetVersion.bind(null, 86)).to.not.throw();
});

it('should throw an error about buildNumber type', () => {
fs.copySync(entryConfigFiles.VERSION_AND_BUILD, tempConfigFile);

expect(cordovaSetVersion.bind(null, 86))
.to.not.throw();
expect(cordovaSetVersion.bind(null, 86.9))
.to.throw(TypeError)
.to.have.property('message')
.that.contains('buildNumber')
.that.contains('must be an');
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions test/index.config-path-build-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function configPathBuildNumberTest() {

const cordovaSetVersion = useFakeRethrow(done);

expect(cordovaSetVersion.bind(null, tempProvidedConfigFile, 86))
.to.not.throw();
expect(cordovaSetVersion.bind(null, tempProvidedConfigFile, 86)).to.not.throw();
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions test/index.config-path-version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function configPathVersionTest() {

const cordovaSetVersion = useFakeRethrow(done);

expect(cordovaSetVersion.bind(null, tempProvidedConfigFile, '2.4.9'))
.to.not.throw();
expect(cordovaSetVersion.bind(null, tempProvidedConfigFile, '2.4.9')).to.not.throw();
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions test/index.config-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ function configPathTest() {

const cordovaSetVersion = useFakeRethrow(done);

expect(cordovaSetVersion.bind(null, tempProvidedConfigFile))
.to.not.throw();
expect(cordovaSetVersion.bind(null, tempProvidedConfigFile)).to.not.throw();
});
});
}
Expand Down
3 changes: 1 addition & 2 deletions test/index.no-arguments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ function noArgumentsTest() {

const cordovaSetVersion = useFakeRethrow(done);

expect(cordovaSetVersion.bind(null))
.to.not.throw();
expect(cordovaSetVersion.bind(null)).to.not.throw();
});
});
}
Expand Down
1 change: 1 addition & 0 deletions test/index.nulls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function nullsTest() {

it('(configPath, null)', done => {
fs.copySync(entryConfigFiles.VERSION_AND_BUILD, tempProvidedConfigFile);
fs.copySync(entryPackageFiles.GOOD, tempPackageFile);

const csv = useFakeRethrow(done);

Expand Down
3 changes: 1 addition & 2 deletions test/index.version-build-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function versionBuildNumberTest() {

const cordovaSetVersion = useFakeRethrow(done);

expect(cordovaSetVersion.bind(null, '2.4.9', 86))
.to.not.throw();
expect(cordovaSetVersion.bind(null, '2.4.9', 86)).to.not.throw();
});
});
}
Expand Down
7 changes: 3 additions & 4 deletions test/index.version.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { expect } from 'chai';
import fs from 'fs-extra';

import useFakeRethrow from './use-fake-rethrow';
import { tempProvidedConfigFile, entryConfigFiles } from './configs';
import { tempConfigFile, entryConfigFiles } from './configs';
import { tempPackageFile, entryPackageFiles } from './packages';

function versionTest() {
describe('(version)', () => {
it('should not throw an error', done => {
fs.copySync(entryConfigFiles.VERSION_AND_BUILD, tempProvidedConfigFile);
fs.copySync(entryConfigFiles.VERSION_AND_BUILD, tempConfigFile);
fs.copySync(entryPackageFiles.GOOD, tempPackageFile);

const cordovaSetVersion = useFakeRethrow(done);

expect(cordovaSetVersion.bind(null, '2.4.9'))
.to.not.throw();
expect(cordovaSetVersion.bind(null, '2.4.9')).to.not.throw();
});
});
}
Expand Down
7 changes: 6 additions & 1 deletion test/use-fake-rethrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ function useFakeRethrow(done) {

function fakeRethrow() {
return error => { // eslint-disable-line no-unused-vars
done();
if (error) {
done(error);
throw error;
} else {
done();
}
};
}
}
Expand Down

0 comments on commit f70f228

Please sign in to comment.