From 8dbffe6fa76f33e88933e22d96ce28eb3db32c35 Mon Sep 17 00:00:00 2001 From: Mickael Daniel Date: Tue, 25 Dec 2012 13:50:57 +0100 Subject: [PATCH] Move completion cache results to ~/.bower/cache/__bowercompletion__ for cache-clean command to be able to clean it. __bowercompletion__ to avoid potential naming conflicts. --- lib/core/config.js | 2 +- test/completion.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/core/config.js b/lib/core/config.js index 7dfe7050..de800f8a 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -26,7 +26,7 @@ var folder = process.platform === 'win32' var config = require('rc') ('bower', { cache : path.join(roaming, folder, 'cache'), links : path.join(roaming, folder, 'links'), - completion : path.join(roaming, folder, 'completion'), + completion : path.join(roaming, folder, 'cache/__bowercompletion__'), json : 'component.json', endpoint : 'https://bower.herokuapp.com', directory : 'components' diff --git a/test/completion.js b/test/completion.js index cbe6af74..42b98144 100644 --- a/test/completion.js +++ b/test/completion.js @@ -5,6 +5,7 @@ var path = require('path'); var assert = require('assert'); var complete = require('../lib/util/completion'); +var config = require('../lib/core/config'); var command = require('../lib/commands/completion'); var commands = require('../lib/commands'); @@ -126,4 +127,33 @@ describe('completion', function () { cmd.on('end', done); }); + + + describe('completion cache clean', function() { + + it('caches the result of /packages to ~/.bower/cache/__bowercompletion__', function(done) { + complete.log = function() {}; + + var cmd = command(['install', 'jquery-'], { + COMP_CWORD: '2', + COMP_LINE: 'bower install jquery-', + COMP_POINT: '14' + }); + + cmd.on('end', function() { + var cache = path.join(config.completion, 'install.json'); + fs.stat(cache, done); + }); + }) + + it('is cleared with cache-clean command', function(done) { + commands['cache-clean']().on('end', function() { + var cache = path.join(config.completion, 'install.json'); + fs.stat(cache, function(err) { + done(err ? null : new Error('completion results wasn\'t cleaned')); + }); + }); + }); + + }); });