Allow preInstall hook to return false to skip npm install

This commit is contained in:
Nick O'Leary
2021-04-19 20:29:30 +01:00
parent d2432716ea
commit b4a03a56b4
4 changed files with 38 additions and 8 deletions

View File

@@ -291,16 +291,19 @@ describe('nodes/registry/installer', function() {
}).catch(done);
});
it("fails install if preInstall hook fails", function(done) {
it("skips invoking npm if preInstall returns false", function(done) {
let receivedEvent;
hooks.add("preInstall", function(event) { throw new Error("preInstall-error"); })
hooks.add("preInstall", function(event) { return false })
hooks.add("postInstall", function(event) { receivedEvent = event; })
var nodeInfo = {nodes:{module:"foo",types:["a"]}};
installer.installModule("this_wont_exist","1.2.3").catch(function(err) {
exec.run.called.should.be.false();
should.exist(receivedEvent);
done();
}).catch(done);
});
it("rollsback install if postInstall hook fails", function(done) {
hooks.add("postInstall", function(event) { throw new Error("fail"); })
installer.installModule("this_wont_exist","1.2.3").catch(function(err) {