Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
breakout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlacy committed Feb 23, 2015
1 parent 40a469e commit bc02e97
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 377 deletions.
51 changes: 51 additions & 0 deletions test/dotNotation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var gutil = require('gulp-util');
var should = require('should');
var bump = require('..');

require('mocha');

describe('gulp-bump: dot notation', function() {
var dotObject = {
subversion: {
version:'1.2.3'
}
};

it('should bump dot notation', function (done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: new Buffer(JSON.stringify(dotObject, null, 2))
});
var bumpS = bump({key: 'subversion.version'});

bumpS.once('data', function(newFile) {
var json = JSON.parse(String(newFile.contents));
json.subversion.version.should.equal('1.2.4');
done();
});
bumpS.write(fakeFile);
});

it('should bump dot notation with type', function (done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: new Buffer(JSON.stringify(dotObject, null, 2))
});
var bumpS = bump({
key: 'subversion.version',
type: 'minor'
});

bumpS.once('data', function(newFile) {
var json = JSON.parse(String(newFile.contents));
json.subversion.version.should.equal('1.3.0');
done();
});
bumpS.write(fakeFile);
});

});
82 changes: 82 additions & 0 deletions test/errorCases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var gutil = require('gulp-util');
var should = require('should');
var bump = require('..');

require('mocha');

describe('Test failure cases cases in gulp-bump', function() {

it('should fail when not detect a valid semver version', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
path: file,
contents: new Buffer('{ "version": "0.A.1" }')
});

var bumpS = bump();

bumpS.on('error', function(e) {
should.exist(e);
e.message.should.equal('Detected invalid semver version');
e.fileName.should.containEql(file);
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should fail when not detect a valid semver version and wrong key', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
path: file,
contents: new Buffer('{ "version": "0.0.1" }')
});

var bumpS = bump({key: 'appversion'});

bumpS.on('error', function(e) {
should.exist(e);
e.message.should.containEql('Detected invalid semver appversion');
e.fileName.should.containEql(file);
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should fail when supplied with an invalid JSON', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
path: file,
contents: new Buffer('{ invalid json oh no!!!}')
});

var bumpS = bump();

bumpS.on('error', function(e) {
should.exist(e);
e.name.should.equal('Error');
e.message.should.containEql('Problem parsing JSON file');
e.fileName.should.containEql(file);
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should fallback to defaults when supplied with invalid semver version', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{ "version": "0.0.1" }')
});
var bumpS = bump({version: '0.A.2'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.contents);
JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});
});
111 changes: 111 additions & 0 deletions test/fileFixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
var fs = require('fs');
var gutil = require('gulp-util');
var should = require('should');
var bump = require('..');

require('mocha');

var fixtureFile = fs.readFileSync('test/fixtures/package.json');

describe('gulp-bump: JSON File fixtures', function() {

it('should bump minor by default', function(done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile
});

var bumpS = bump();

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.path);
should.exist(newFile.contents);
String(newFile.contents).should.equal(fs.readFileSync('test/expected/default.json', 'utf8'));
done();
});
bumpS.write(fakeFile);
});

it('should bump major if options.bump = major', function(done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile
});

var bumpS = bump({type: 'major'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.path);
should.exist(newFile.contents);
String(newFile.contents).should.equal(fs.readFileSync('test/expected/major.json', 'utf8'));
done();
});
bumpS.write(fakeFile);
});

it('should bump minor if options.bump = minor', function(done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile
});

var bumpS = bump({type: 'minor'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.path);
should.exist(newFile.contents);
String(newFile.contents).should.equal(fs.readFileSync('test/expected/minor.json', 'utf8'));
done();
});
bumpS.write(fakeFile);
});

it('should set version to value specified by options.version', function(done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
contents: fixtureFile
});

var bumpS = bump({version: '1.0.0'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.path);
should.exist(newFile.contents);
String(newFile.contents).should.equal(fs.readFileSync('test/expected/version.json', 'utf8'));
done();
});
bumpS.write(fakeFile);
});

it('should set the key to a custom version', function(done) {
var fakeFile = new gutil.File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/key.json',
contents: fs.readFileSync('test/fixtures/key.json')
});

var bumpS = bump({key: 'appversion'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.path);
should.exist(newFile.contents);
String(newFile.contents).should.equal(fs.readFileSync('test/expected/key.json', 'utf8'));
done();
});
bumpS.write(fakeFile);
});
});
111 changes: 111 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
var gutil = require('gulp-util');
var should = require('should');
var bump = require('..');

require('mocha');

describe('gulp-bump: JSON comparison fixtures', function() {

it('should bump patch version by default', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{ "version": "0.0.9" }')
});

var bumpS = bump();

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.contents);
JSON.parse(newFile.contents.toString()).version.should.equal('0.0.10');
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should bump patch version as default and a key=appversion', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{ "appversion": "0.0.1" }')
});

var bumpS = bump({key: 'appversion'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.contents);
JSON.parse(newFile.contents.toString()).appversion.should.equal('0.0.2');
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should ignore invalid type and use type=patch', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{ "version": "0.0.1" }')
});

var bumpS = bump({type: 'invalidType'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.contents);
JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
return done();
});

bumpS.write(fakeFile);
bumpS.end();
});

it('should set the correct version when supplied', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{ "version": "0.0.1" }')
});

var bumpS = bump({version: '0.0.2'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.contents);
JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should set the correct version when supplied even if key did not exist', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{}')
});

var bumpS = bump({version: '0.0.2'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.contents);
JSON.parse(newFile.contents.toString()).version.should.equal('0.0.2');
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should bump prerelease version', function(done) {
var fakeFile = new gutil.File({
contents: new Buffer('{ "version": "0.0.1-0"}')
});

var bumpS = bump({type: 'prerelease'});

bumpS.once('data', function(newFile) {
should.exist(newFile);
should.exist(newFile.contents);
JSON.parse(newFile.contents.toString()).version.should.equal('0.0.1-1');
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});
});
Loading

0 comments on commit bc02e97

Please sign in to comment.