Skip to content

Commit

Permalink
Update bower version tests, refs bower#2139.
Browse files Browse the repository at this point in the history
`bower version` currently takes the version from the "version" field of
bower.json, but the spec says that bower ignores it.

This commit updates the `bower version` tests so that they are
consistent with the spec. Now, the tests are based on the assumption
that `bower version` should only use git tags.
  • Loading branch information
hdgarrood committed Jan 8, 2016
1 parent 3154444 commit 51d50b7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
71 changes: 38 additions & 33 deletions test/commands/version.js
Expand Up @@ -3,87 +3,92 @@ var expect = require('expect.js');
var helpers = require('../helpers');
var version = helpers.require('lib/commands').version;

describe('bower list', function () {
describe('bower version', function () {

var mainPackage = new helpers.TempDir({
'bower.json': {
name: 'foobar',
version: '0.0.0'
}
});

var gitPackage = new helpers.TempDir({
'v0.0.0': {
'bower.json': {
name: 'foobar',
version: '0.0.0'
}
}
});

var packageWithoutTags = new helpers.TempDir({});


it('bumps patch version', function() {
mainPackage.prepare();
mainPackage.prepareGit();

return helpers.run(version, ['patch', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.readJson('bower.json').version).to.be('0.0.1');
expect(mainPackage.latestGitTag()).to.be('0.0.1');
});
});

it('bumps minor version', function() {
mainPackage.prepare();
mainPackage.prepareGit();

return helpers.run(version, ['minor', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.readJson('bower.json').version).to.be('0.1.0');
expect(mainPackage.latestGitTag()).to.be('0.1.0');
});
});

it('bumps major version', function() {
mainPackage.prepare();
mainPackage.prepareGit();

return helpers.run(version, ['major', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.readJson('bower.json').version).to.be('1.0.0');
expect(mainPackage.latestGitTag()).to.be('1.0.0');
});
});

it('changes version', function() {
mainPackage.prepare();
mainPackage.prepareGit();

return helpers.run(version, ['1.2.3', {}, { cwd: mainPackage.path }]).then(function() {
expect(mainPackage.readJson('bower.json').version).to.be('1.2.3');
expect(mainPackage.latestGitTag()).to.be('1.2.3');
});
});

it('returns the new version', function() {
mainPackage.prepare();
mainPackage.prepareGit();

return helpers.run(version, ['major', {}, { cwd: mainPackage.path }]).then(function(results) {
expect(results[0]).to.be('1.0.0');
});
});

it('bumps patch version, create commit, and tag', function() {
gitPackage.prepareGit();

return helpers.run(version, ['patch', {}, { cwd: gitPackage.path }]).then(function() {
expect(gitPackage.readJson('bower.json').version).to.be('0.0.1');
it('bumps with custom commit message', function() {
mainPackage.prepareGit();

var tags = gitPackage.git('tag');
return helpers.run(version, ['patch', { message: 'Bumping %s, because what'}, { cwd: mainPackage.path }]).then(function() {
var tags = mainPackage.git('tag');
expect(tags).to.be('v0.0.0\nv0.0.1\n');
var message = gitPackage.git('log', '--pretty=format:%s', '-n1');
expect(message).to.be('v0.0.1');
var message = mainPackage.git('log', '--pretty=format:%s', '-n1');
expect(message).to.be('Bumping 0.0.1, because what');
});
});

it('bumps with custom commit message', function() {
gitPackage.prepareGit();

return helpers.run(version, ['patch', { message: 'Bumping %s, because what'}, { cwd: gitPackage.path }]).then(function() {
expect(gitPackage.readJson('bower.json').version).to.be('0.0.1');
it('creates commit and tags', function() {
mainPackage.prepareGit();

var tags = gitPackage.git('tag');
return helpers.run(version, ['patch', {}, { cwd: mainPackage.path }]).then(function() {
var tags = mainPackage.git('tag');
expect(tags).to.be('v0.0.0\nv0.0.1\n');
var message = gitPackage.git('log', '--pretty=format:%s', '-n1');
expect(message).to.be('Bumping 0.0.1, because what');
var message = mainPackage.git('log', '--pretty=format:%s', '-n1');
expect(message).to.be('v0.0.1');
});
});

it('assumes v0.0.0 when no tags exist', function() {
packageWithoutTags.prepareGit();
packageWithoutTags.create({
'index.js': 'console.log("hello, world");'
});
packageWithoutTags.git('add', '-A');
packageWithoutTags.git('commit', '-m"commit"');

return helpers.run(version, ['major', {}, { cwd: packageWithoutTags.path }]).then(function() {
expect(packageWithoutTags.latestGitTag()).to.be('1.0.0');
});
});
});
15 changes: 15 additions & 0 deletions test/helpers.js
Expand Up @@ -14,6 +14,7 @@ var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
var spawnSync = require('spawn-sync');
var config = require('../lib/config');
var nock = require('nock');
var semver = require('semver');

// For better promise errors
Q.longStackSupport = true;
Expand Down Expand Up @@ -155,6 +156,20 @@ exports.TempDir = (function() {
}
};

TempDir.prototype.latestGitTag = function () {
var versions = this.git('tag')
.split(/\r?\n/)
.map(function(t) { return t.slice(1); })
.filter(function(t) { return semver.valid(t); })
.sort(semver.compare);

if (versions.length >= 1) {
return versions[0];
} else {
throw new Error('No valid git version tags found.');
}
};

TempDir.prototype.exists = function (name) {
return fs.existsSync(path.join(this.path, name));
};
Expand Down

0 comments on commit 51d50b7

Please sign in to comment.