Skip to content

Commit

Permalink
Merge pull request #5085 from jbellenger/jbellenger/rawmodule-hash
Browse files Browse the repository at this point in the history
fix RawModule hashing
  • Loading branch information
sokra committed Jun 18, 2017
2 parents 316d4b9 + 8c9dc14 commit 3da4f3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/RawModule.js
Expand Up @@ -47,4 +47,8 @@ module.exports = class RawModule extends Module {
return new RawSource(this.sourceStr);
}

updateHash(hash) {
hash.update(this.sourceStr);
super.updateHash(hash);
}
};
15 changes: 15 additions & 0 deletions test/RawModule.test.js
Expand Up @@ -6,6 +6,7 @@ const RawSource = require("webpack-sources").RawSource;
const RequestShortener = require("../lib/RequestShortener");
const should = require("should");
const path = require("path");
const crypto = require("crypto");

describe("RawModule", () => {
let myRawModule;
Expand Down Expand Up @@ -62,4 +63,18 @@ describe("RawModule", () => {
}
);
});

describe("updateHash", () => {
it("should include sourceStr in its hash", () => {
const hashModule = (module) => {
const hash = crypto.createHash("sha256");
module.updateHash(hash);
return hash.digest("hex");
};

const hashFoo = hashModule(new RawModule("\"foo\""));
const hashBar = hashModule(new RawModule("\"bar\""));
hashFoo.should.not.equal(hashBar);
});
});
});

0 comments on commit 3da4f3e

Please sign in to comment.