Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add integration tests for bower commands

  • Loading branch information...
commit 192e5af797188937253cc821e69c3793031c0a2d 1 parent deb39b8
@itsmonktastic itsmonktastic authored sheerun committed
View
5 .gitignore
@@ -1,11 +1,10 @@
/node_modules
/npm-debug.log
-/test/assets/temp
-/test/assets/temp2
-/test/assets/temp-resolve-cache
/test/assets/package-*/
+/test/assets/temp-*/
/test/reports
+/test/tmp/
/bower.json
/component.json
View
3  Gruntfile.js
@@ -13,7 +13,8 @@ module.exports = function (grunt) {
'lib/**/*.js',
'test/**/*.js',
'!test/assets/**/*',
- '!test/reports/**/*'
+ '!test/reports/**/*',
+ '!test/tmp/**/*'
]
},
simplemocha: {
View
3  package.json
@@ -70,7 +70,8 @@
"mocha": "~1.20.1",
"nock": "~0.34.1",
"proxyquire": "~1.0.1",
- "coveralls": "~2.10.0"
+ "coveralls": "~2.10.0",
+ "node-uuid": "~1.4.1"
},
"scripts": {
"test": "grunt test"
View
16 test/assets/resolve-cache/list-json-1.json
@@ -1,51 +1,51 @@
[
{
- "canonicalDir": "/test/assets/temp-resolve-cache/3668e6529b32a6d3e8931a68474e909d/0.2.0",
+ "canonicalDir": "/test/tmp/temp-resolve-cache/3668e6529b32a6d3e8931a68474e909d/0.2.0",
"pkgMeta": {
"name": "abc",
"version": "0.2.0"
}
},
{
- "canonicalDir": "/test/assets/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/0.0.1",
+ "canonicalDir": "/test/tmp/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/0.0.1",
"pkgMeta": {
"name": "foo",
"version": "0.0.1"
}
},
{
- "canonicalDir": "/test/assets/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/0.1.0",
+ "canonicalDir": "/test/tmp/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/0.1.0",
"pkgMeta": {
"name": "foo",
"version": "0.1.0"
}
},
{
- "canonicalDir": "/test/assets/temp-resolve-cache/3668e6529b32a6d3e8931a68474e909d/0.2.1",
+ "canonicalDir": "/test/tmp/temp-resolve-cache/3668e6529b32a6d3e8931a68474e909d/0.2.1",
"pkgMeta": {
"name": "foo",
"version": "0.2.1"
}
},
{
- "canonicalDir": "/test/assets/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/aa",
+ "canonicalDir": "/test/tmp/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/aa",
"pkgMeta": {
"name": "foo",
"_target": "aa"
}
},
{
- "canonicalDir": "/test/assets/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/bar",
+ "canonicalDir": "/test/tmp/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/bar",
"pkgMeta": {
"name": "foo",
"_target": "bar"
}
},
{
- "canonicalDir": "/test/assets/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/foo",
+ "canonicalDir": "/test/tmp/temp-resolve-cache/77008abea14f06f199c2f481362b48d9/foo",
"pkgMeta": {
"name": "foo",
"_target": "foo"
}
}
-]
+]
View
5 test/commands/index.js
@@ -0,0 +1,5 @@
+describe('integration tests', function () {
+ require('./init');
+ require('./install');
+ require('./uninstall');
+});
View
48 test/commands/init.js
@@ -0,0 +1,48 @@
+var path = require('path');
+var expect = require('expect.js');
+var fs = require('fs');
+
+var helpers = require('../helpers');
+var bower = helpers.require('lib/index');
+
+describe('bower init', function () {
+
+ var tempDir = helpers.createTmpDir();
+ var bowerJsonPath = path.join(tempDir, 'bower.json');
+
+ var config = {
+ cwd: tempDir,
+ interactive: true
+ };
+
+ it('generates bower.json file', function () {
+ var logger = bower.commands.init(config);
+
+ return helpers.expectEvent(logger, 'prompt')
+ .spread(function (prompt, answer) {
+ answer({
+ name: 'test-name',
+ version: 'test-version',
+ description: 'test-description',
+ moduleType: 'test-moduleType',
+ keywords: 'test-keyword',
+ authors: 'test-author',
+ license: 'test-license',
+ homepage: 'test-homepage',
+ private: true
+ });
+
+ return helpers.expectEvent(logger, 'prompt');
+ })
+ .spread(function (prompt, answer) {
+ answer({
+ prompt: true
+ });
+
+ return helpers.expectEvent(logger, 'end');
+ })
+ .then(function () {
+ expect(fs.existsSync(bowerJsonPath)).to.be(true);
+ });
+ });
+});
View
47 test/commands/install.js
@@ -0,0 +1,47 @@
+var path = require('path');
+var expect = require('expect.js');
+var fs = require('fs');
+
+var helpers = require('../helpers');
+var bower = helpers.require('lib/index');
+
+describe('bower install', function () {
+
+ var tempDir = helpers.createTmpDir();
+ var bowerJsonPath = path.join(tempDir, 'bower_components', 'underscore', 'bower.json');
+
+ function bowerJson() {
+ return JSON.parse(fs.readFileSync(bowerJsonPath));
+ }
+
+ var config = {
+ cwd: tempDir,
+ interactive: true
+ };
+
+ it('does nothing if no bower.json is present', function () {
+ var logger = bower.commands.install([], undefined, config);
+
+ return helpers.expectEvent(logger, 'end');
+ });
+
+ it.skip('installs a package', function () {
+ this.timeout(10000);
+ var logger = bower.commands.install(['underscore'], undefined, config);
+
+ return helpers.expectEvent(logger, 'end')
+ .then(function () {
+ expect(bowerJson()).to.have.key('name');
+ });
+ });
+
+ it.skip('installs package with --save flag', function () {
+ var logger = bower.commands.install(['underscore'], {save: true}, config);
+
+ return helpers.expectEvent(logger, 'end')
+ .then(function () {
+ expect(bowerJson()).to.have.key('name');
+ });
+ });
+
+});
View
48 test/commands/uninstall.js
@@ -0,0 +1,48 @@
+var path = require('path');
+var expect = require('expect.js');
+var fs = require('fs');
+
+var helpers = require('../helpers');
+var bower = helpers.require('lib/index');
+
+describe('bower uninstall', function () {
+
+ var tempDir = helpers.createTmpDir({
+ 'bower.json': {
+ name: 'hello-world',
+ dependencies: {
+ 'underscore': '*'
+ }
+ }
+ });
+
+ var bowerJsonPath = path.join(tempDir, 'bower.json');
+
+ function bowerJson() {
+ return JSON.parse(fs.readFileSync(bowerJsonPath));
+ }
+
+ var config = {
+ cwd: tempDir,
+ interactive: true
+ };
+
+ it('does not remove anything from dependencies by default', function () {
+ var logger = bower.commands.uninstall(['underscore'], undefined, config);
+
+ return helpers.expectEvent(logger, 'end')
+ .then(function () {
+ expect(bowerJson().dependencies).to.eql({ 'underscore': '*' });
+ });
+ });
+
+ it('removes dependency from bower.json if --save flag is used', function () {
+ var logger = bower.commands.uninstall(['underscore'], {save: true}, config);
+
+ return helpers.expectEvent(logger, 'end')
+ .then(function () {
+ expect(bowerJson().dependencies).to.eql({});
+ });
+ });
+
+});
View
6 test/core/packageRepository.js
@@ -18,9 +18,9 @@ describe('PackageRepository', function () {
var resolverFactoryHook;
var resolverFactoryClearHook;
var testPackage = path.resolve(__dirname, '../assets/package-a');
- var tempPackage = path.resolve(__dirname, '../assets/temp');
- var packagesCacheDir = path.join(__dirname, '../assets/temp-resolve-cache');
- var registryCacheDir = path.join(__dirname, '../assets/temp-registry-cache');
+ var tempPackage = path.resolve(__dirname, '../tmp/temp-package');
+ var packagesCacheDir = path.join(__dirname, '../tmp/temp-resolve-cache');
+ var registryCacheDir = path.join(__dirname, '../tmp/temp-registry-cache');
var mockSource = 'file://' + testPackage;
var forceCaching = true;
View
8 test/core/resolveCache.js
@@ -14,9 +14,9 @@ var md5 = require('../../lib/util/md5');
describe('ResolveCache', function () {
var resolveCache;
var testPackage = path.resolve(__dirname, '../assets/package-a');
- var tempPackage = path.resolve(__dirname, '../assets/temp');
- var tempPackage2 = path.resolve(__dirname, '../assets/temp2');
- var cacheDir = path.join(__dirname, '../assets/temp-resolve-cache');
+ var tempPackage = path.resolve(__dirname, '../tmp/temp-package');
+ var tempPackage2 = path.resolve(__dirname, '../tmp/temp2-package');
+ var cacheDir = path.join(__dirname, '../tmp/temp-resolve-cache');
before(function (next) {
// Delete cache folder
@@ -908,7 +908,7 @@ describe('ResolveCache', function () {
expect(entries).to.be.an('array');
expectedJson = fs.readFileSync(path.join(__dirname, '../assets/resolve-cache/list-json-1.json'));
- expectedJson = expectedJson.toString();
+ expectedJson = expectedJson.toString().trim();
mout.object.forOwn(entries, function (entry) {
// Trim absolute bower path from json
View
4 test/core/resolverFactory.js
@@ -421,7 +421,7 @@ describe('resolverFactory', function () {
var endpoints;
var temp;
- tempSource = path.resolve(__dirname, '../assets/tmp');
+ tempSource = path.resolve(__dirname, '../tmp/tmp');
mkdirp.sync(tempSource);
fs.writeFileSync(path.join(tempSource, '.git'), 'foo');
fs.writeFileSync(path.join(tempSource, 'file.with.multiple.dots'), 'foo');
@@ -431,7 +431,7 @@ describe('resolverFactory', function () {
// Absolute path to folder with .git file
endpoints[tempSource] = tempSource;
// Relative path to folder with .git file
- endpoints[__dirname + '/../assets/tmp'] = tempSource;
+ endpoints[__dirname + '/../tmp/tmp'] = tempSource;
// Absolute path to folder
temp = path.resolve(__dirname, '../assets/test-temp-dir');
View
8 test/core/resolvers/fsResolver.js
@@ -82,7 +82,7 @@ describe('FsResolver', function () {
it('should resolve always to true (for now..)', function (next) {
var resolver = create(testPackage);
- tempSource = path.resolve(__dirname, '../../assets/tmp');
+ tempSource = path.resolve(__dirname, '../../tmp/tmp');
mkdirp.sync(tempSource);
fs.writeFileSync(path.join(tempSource, '.bower.json'), JSON.stringify({
name: 'test'
@@ -161,7 +161,7 @@ describe('FsResolver', function () {
it('should rename to index if source is a folder with just one file in it', function (next) {
var resolver;
- tempSource = path.resolve(__dirname, '../../assets/tmp');
+ tempSource = path.resolve(__dirname, '../../tmp/tmp');
mkdirp.sync(tempSource);
resolver = create(tempSource);
@@ -181,7 +181,7 @@ describe('FsResolver', function () {
it('should not rename to index if source is a folder with just bower.json/component.json file in it', function (next) {
var resolver;
- tempSource = path.resolve(__dirname, '../../assets/tmp');
+ tempSource = path.resolve(__dirname, '../../tmp/tmp');
mkdirp.sync(tempSource);
resolver = create(tempSource);
@@ -235,7 +235,7 @@ describe('FsResolver', function () {
var mode0777;
var resolver;
- tempSource = path.resolve(__dirname, '../../assets/temp');
+ tempSource = path.resolve(__dirname, '../../tmp/temp-source');
resolver = create(tempSource);
copy.copyFile(path.join(testPackage, 'foo'), tempSource)
View
2  test/core/resolvers/gitResolver.js
@@ -13,7 +13,7 @@ var GitResolver = require('../../../lib/core/resolvers/GitResolver');
var defaultConfig = require('../../../lib/config');
describe('GitResolver', function () {
- var tempDir = path.resolve(__dirname, '../../assets/tmp');
+ var tempDir = path.resolve(__dirname, '../../tmp/tmp');
var originalrefs = GitResolver.refs;
var logger;
View
2  test/core/resolvers/resolver.js
@@ -13,7 +13,7 @@ var Resolver = require('../../../lib/core/resolvers/Resolver');
var defaultConfig = require('../../../lib/config');
describe('Resolver', function () {
- var tempDir = path.resolve(__dirname, '../../assets/tmp');
+ var tempDir = path.resolve(__dirname, '../../tmp/tmp');
var testPackage = path.resolve(__dirname, '../../assets/package-a');
var logger;
var dirMode0777;
View
2  test/core/resolvers/svnResolver.js
@@ -11,7 +11,7 @@ var SvnResolver = require('../../../lib/core/resolvers/SvnResolver');
var defaultConfig = require('../../../lib/config');
describe('SvnResolver', function () {
- var tempDir = path.resolve(__dirname, '../../assets/tmp');
+ var tempDir = path.resolve(__dirname, '../../tmp/tmp');
var testPackage = path.resolve(__dirname, '../../assets/package-svn/repo');
var testPackageAdmin = path.resolve(__dirname, '../../assets/package-svn/admin');
var originaltags = SvnResolver.tags;
View
2  test/core/resolvers/urlResolver.js
@@ -13,7 +13,7 @@ var defaultConfig = require('../../../lib/config');
describe('UrlResolver', function () {
var testPackage = path.resolve(__dirname, '../../assets/package-a');
- var tempDir = path.resolve(__dirname, '../../assets/tmp');
+ var tempDir = path.resolve(__dirname, '../../tmp/tmp');
var logger;
before(function (next) {
View
6 test/core/scripts.js
@@ -8,9 +8,9 @@ var scripts = require('../../lib/core/scripts.js');
describe('scripts', function () {
- var tempDir = path.join(__dirname, '../assets/temp-scripts');
+ var tempDir = path.join(__dirname, '../tmp/temp-scripts');
var packageName = 'package-zip';
- var packageDir = path.join('..', packageName + '.zip');
+ var packageDir = path.join(__dirname, '../assets/' + packageName + '.zip');
var config = {
cwd: tempDir,
@@ -125,4 +125,4 @@ describe('scripts', function () {
});
-});
+});
View
43 test/helpers.js
@@ -0,0 +1,43 @@
+var Q = require('q');
+var path = require('path');
+var mkdirp = require('mkdirp');
+var rimraf = require('rimraf');
+var uuid = require('node-uuid');
+var object = require('mout/object');
+var fs = require('fs');
+
+exports.require = function (name) {
+ return require(path.join(__dirname, '../', name));
+};
+
+exports.createTmpDir = function (files) {
+ var tempDir = path.join(__dirname, 'tmp/' + uuid.v4());
+
+ before(function (next) {
+ mkdirp(tempDir, next);
+
+ if (files) {
+ object.forOwn(files, function (contents, filepath) {
+ if (typeof contents === 'object') {
+ contents = JSON.stringify(contents, null, ' ');
+ }
+
+ fs.writeFileSync(path.join(tempDir, filepath), contents);
+ });
+ }
+ });
+
+ after(function (next) {
+ rimraf(tempDir, next);
+ });
+
+ return tempDir;
+};
+
+exports.expectEvent = function (emitter, eventName) {
+ var deferred = Q.defer();
+ emitter.once(eventName, function () {
+ deferred.resolve(arguments);
+ });
+ return deferred.promise;
+};
View
1  test/test.js
@@ -18,3 +18,4 @@ require('./core/resolveCache');
require('./core/packageRepository');
require('./core/scripts');
require('./core/Manager');
+require('./commands/index.js');
Please sign in to comment.
Something went wrong with that request. Please try again.