From 8bc7349635a5c64b59b1bfee91a490a1f01b538f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Cruz?= Date: Sun, 21 Apr 2013 15:16:58 +0100 Subject: [PATCH] Add some more tests. --- lib/resolve/Resolver.js | 9 ++++++--- test/resolve/resolver.js | 43 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/lib/resolve/Resolver.js b/lib/resolve/Resolver.js index 3d5818c9..f01e83a1 100644 --- a/lib/resolve/Resolver.js +++ b/lib/resolve/Resolver.js @@ -145,7 +145,7 @@ Resolver.prototype._applyPkgMeta = function (meta) { if (meta.ignore && meta.ignore.length) { return Q.nfcall(glob, '**/*', { cwd: this._tempDir, dot: true, mark: true }) .then(function (files) { - var filter = this._createIgnoreFilter(meta.ignores), + var filter = this._createIgnoreFilter(meta.ignore), promises = []; // Foreach file that passes the ignore filter, @@ -158,7 +158,10 @@ Resolver.prototype._applyPkgMeta = function (meta) { // Wait for all the rimraf's to finish return Q.all(promises); - }.bind(this)); + }.bind(this)) + .then(function () { + return meta; + }); } return Q.resolve(meta); @@ -169,7 +172,7 @@ Resolver.prototype._savePkgMeta = function (meta) { return Q.nfcall(fs.writeFile, path.join(this._tempDir, '.bower.json'), contents) .then(function () { - this._pkgMeta = meta; + return this._pkgMeta = meta; }.bind(this)); }; diff --git a/test/resolve/resolver.js b/test/resolve/resolver.js index 6caee12b..3f7e1f68 100644 --- a/test/resolve/resolver.js +++ b/test/resolve/resolver.js @@ -298,7 +298,15 @@ describe('Resolver', function () { resolver._applyPkgMeta(meta) .then(function (retMeta) { expect(retMeta).to.equal(meta); - next(); + + // Test also with the ignore property because the code is different + meta = { name: 'foo', ignore: ['somefile'] }; + resolver._applyPkgMeta(meta) + .then(function (retMeta) { + expect(retMeta).to.equal(meta); + next(); + }) + .done(); }) .done(); }); @@ -411,7 +419,36 @@ describe('Resolver', function () { promise.then(done.bind(done, null), done.bind(done, null)); }); - it.skip('should resolve with the the same package meta'); - it.skip('should save the package meta to the package meta file (.bower.json)'); + it('should resolve with the the same package meta', function (next) { + var resolver = new Resolver('foo'), + meta = { name: 'foo' }; + + resolver._tempDir = tempDir; + + resolver._savePkgMeta(meta) + .then(function (retMeta) { + expect(retMeta).to.equal(meta); + next(); + }) + .done(); + }); + + it('should save the package meta to the package meta file (.bower.json)', function (next) { + var resolver = new Resolver('foo'); + + resolver._tempDir = tempDir; + + resolver._savePkgMeta({ name: 'bar' }) + .then(function (retMeta) { + fs.readFile(path.join(tempDir, '.bower.json'), function (err, contents) { + if (err) return next(err); + + contents = contents.toString(); + expect(JSON.parse(contents)).to.eql(retMeta); + next(); + }); + }) + .done(); + }); }); }); \ No newline at end of file