Fix #5806, TypeError on ExternalModule hash.update

undefined must be coerced to `false`
This commit is contained in:
Samuel Reed 2017-10-11 13:53:12 -05:00
parent 551ea76838
commit c9bad176fd
No known key found for this signature in database
GPG Key ID: 011E698EE329F38B
2 changed files with 29 additions and 1 deletions

View File

@ -120,7 +120,7 @@ class ExternalModule extends Module {
updateHash(hash) {
hash.update(this.type);
hash.update(JSON.stringify(this.request));
hash.update(JSON.stringify(this.optional));
hash.update(JSON.stringify(Boolean(this.optional)));
super.updateHash(hash);
}
}

View File

@ -340,4 +340,32 @@ module.exports = some/request;`;
hashedText.should.containEql("12345678");
});
});
describe("#updateHash without optional", function() {
let hashedText;
let hash;
beforeEach(function() {
hashedText = "";
hash = {
update: (text) => {
hashedText += text;
}
};
// Note no set of `externalModule.optional`, which crashed externals in 3.7.0
externalModule.id = 12345678;
externalModule.updateHash(hash);
});
it("updates hash with request", function() {
hashedText.should.containEql("some/request");
});
it("updates hash with type", function() {
hashedText.should.containEql("some-type");
});
it("updates hash with optional flag", function() {
hashedText.should.containEql("false");
});
it("updates hash with module id", function() {
hashedText.should.containEql("12345678");
});
});
});