Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement postuninstall hooks with tests #2252

Merged
merged 2 commits into from Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/core/Project.js
Expand Up @@ -764,6 +764,9 @@ Project.prototype._removePackages = function (packages) {
.then(function () {
return that.saveJson();
})
// Run post-uninstall hook before resolving with removed packages.
.then(scripts.postuninstall.bind(
null, that._config, that._logger, packages, that._installed, that._json))
// Resolve with removed packages
.then(function () {
return mout.object.filter(packages, function (dir) {
Expand Down
1 change: 1 addition & 0 deletions lib/core/scripts.js
Expand Up @@ -89,6 +89,7 @@ var hook = function (action, ordered, config, logger, packages, installed, json)

module.exports = {
preuninstall: mout.function.partial(hook, 'preuninstall', false),
postuninstall: mout.function.partial(hook, 'postuninstall', false),
preinstall: mout.function.partial(hook, 'preinstall', true),
postinstall: mout.function.partial(hook, 'postinstall', true),
//only exposed for test
Expand Down
16 changes: 15 additions & 1 deletion test/core/scripts.js
Expand Up @@ -27,7 +27,8 @@ describe('scripts', function () {
scripts: {
preinstall: touch('preinstall_%_%'),
postinstall: touch('postinstall_%_%'),
preuninstall: touch('preuninstall_%_%')
preuninstall: touch('preuninstall_%_%'),
postuninstall: touch('postuninstall_%_%')
}
};

Expand Down Expand Up @@ -66,6 +67,19 @@ describe('scripts', function () {

});

it('should run postuninstall hook.', function (next) {

bower.commands
.uninstall([packageName], undefined, config)
.on('end', function (installed) {

expect(fs.existsSync(path.join(tempDir, 'postuninstall_' + packageName + '_' + packageName))).to.be(true);

next();
});

});

it('should not break anything when no hooks configured.', function (next) {

bower.commands
Expand Down