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

Commit

Permalink
remove gulp-util, add dotnotation type test
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlacy committed Sep 22, 2015
1 parent ffa9596 commit f264fd1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 45 deletions.
26 changes: 23 additions & 3 deletions test/dotNotation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');
var bump = require('..');

Expand All @@ -14,7 +14,7 @@ require('mocha');
};

it('should bump dot notation', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand All @@ -31,7 +31,7 @@ require('mocha');
});

it('should bump dot notation with type', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand All @@ -50,4 +50,24 @@ require('mocha');
bumpS.write(fakeFile);
});

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

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

});
39 changes: 16 additions & 23 deletions test/errorCases.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,68 @@
'use strict';

var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');
var bump = require('..');

require('mocha');

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

var fakeFile = new File({
path: 'some-dir/dummyfile.js',
contents: new Buffer('{ "version": "0.0.0" }')
});

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" }')
});

fakeFile.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);
e.fileName.should.containEql(fakeFile.path);
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" }')
});
it('should fail with an invalid semver version', function(done) {
fakeFile.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);
e.fileName.should.containEql(fakeFile.path);
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!!!}')
});
fakeFile.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);
e.fileName.should.containEql(fakeFile.path);
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" }')
});
fakeFile.contents = new Buffer('{ "version": "0.0.1" }');

var bumpS = bump({version: '0.A.2'});

bumpS.once('data', function(newFile) {
Expand Down
12 changes: 6 additions & 6 deletions test/fileFixtures.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var fs = require('fs');
var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');
var bump = require('..');

Expand All @@ -12,7 +12,7 @@ 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({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand All @@ -32,7 +32,7 @@ describe('gulp-bump: JSON File fixtures', function() {
});

it('should bump major if options.bump = major', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand All @@ -52,7 +52,7 @@ describe('gulp-bump: JSON File fixtures', function() {
});

it('should bump minor if options.bump = minor', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand All @@ -72,7 +72,7 @@ describe('gulp-bump: JSON File fixtures', function() {
});

it('should set version to value specified by options.version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand All @@ -92,7 +92,7 @@ describe('gulp-bump: JSON File fixtures', function() {
});

it('should set the key to a custom version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/key.json',
Expand Down
18 changes: 9 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');
var bump = require('..');

Expand All @@ -9,7 +9,7 @@ require('mocha');
describe('gulp-bump: JSON comparison fixtures', function() {

it('should bump patch version by default', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.9" }'),
path: 'test/fixtures/test.json'
});
Expand All @@ -27,7 +27,7 @@ describe('gulp-bump: JSON comparison fixtures', function() {
});

it('should bump patch version as default and a key=appversion', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "appversion": "0.0.1" }'),
path: 'test/fixtures/test.json'
});
Expand All @@ -45,7 +45,7 @@ describe('gulp-bump: JSON comparison fixtures', function() {
});

it('should ignore invalid type and use type=patch', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1" }'),
path: 'test/fixtures/test.json'
});
Expand All @@ -64,7 +64,7 @@ describe('gulp-bump: JSON comparison fixtures', function() {
});

it('should set the correct version when supplied', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1" }'),
path: 'test/fixtures/test.json'
});
Expand All @@ -82,7 +82,7 @@ describe('gulp-bump: JSON comparison fixtures', function() {
});

it('should set the correct version when supplied even if key did not exist', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{}'),
path: 'test/fixtures/test.json'
});
Expand All @@ -100,7 +100,7 @@ describe('gulp-bump: JSON comparison fixtures', function() {
});

it('should bump prerelease version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1-0"}'),
path: 'test/fixtures/test.json'
});
Expand All @@ -118,7 +118,7 @@ describe('gulp-bump: JSON comparison fixtures', function() {
});

it('should bump to a prerelease version with a preid', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.0.1"}'),
path: 'test/fixtures/test.json'
});
Expand All @@ -136,7 +136,7 @@ describe('gulp-bump: JSON comparison fixtures', function() {
});

it('should bump preid version', function(done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
contents: new Buffer('{ "version": "0.1.0-zeta.1"}'),
path: 'test/fixtures/test.json'
});
Expand Down
8 changes: 4 additions & 4 deletions test/whitespacePreserving.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var gutil = require('gulp-util');
var File = require('vinyl');
var should = require('should');
var bump = require('..');

Expand All @@ -12,7 +12,7 @@ describe('gulp-bump: Whitespace preserving', function() {
var expectedObj = { version: '1.0.1' };

var createFile = function (tabType) {
return new gutil.File({
return new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('gulp-bump: Whitespace preserving', function() {
});

it('should preserve whitespace at end', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand All @@ -70,7 +70,7 @@ describe('gulp-bump: Whitespace preserving', function() {
});

it('should not add new line to file', function (done) {
var fakeFile = new gutil.File({
var fakeFile = new File({
base: 'test/',
cwd: 'test/',
path: 'test/fixtures/package.json',
Expand Down

0 comments on commit f264fd1

Please sign in to comment.