forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRawModule.unittest.js
84 lines (74 loc) · 2.48 KB
/
RawModule.unittest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
const RawModule = require("../lib/RawModule");
const OriginalSource = require("webpack-sources").OriginalSource;
const RawSource = require("webpack-sources").RawSource;
const RequestShortener = require("../lib/RequestShortener");
const path = require("path");
const crypto = require("crypto");
describe("RawModule", () => {
const source = "sourceStr attribute";
const identifier = "identifierStr attribute";
const readableIdentifier = "readableIdentifierStr attribute";
const myRawModule = new RawModule(source, identifier, readableIdentifier);
describe("identifier", () => {
it("returns value for identifierStr attribute", () => {
expect(myRawModule.identifier()).toBe("identifierStr attribute");
});
});
describe("size", () => {
it('returns value for sourceStr attribute"s length property', () => {
const sourceStrLength = myRawModule.sourceStr.length;
expect(myRawModule.size()).toBe(sourceStrLength);
});
});
describe("readableIdentifier", () => {
it(
'returns result of calling provided requestShortener"s shorten method ' +
"on readableIdentifierStr attribute",
() => {
const requestShortener = new RequestShortener(path.resolve());
expect(myRawModule.readableIdentifier(requestShortener)).toBeDefined();
}
);
});
describe("needRebuild", () => {
it("returns false", () => {
expect(myRawModule.needRebuild()).toBe(false);
});
});
describe("source", () => {
it(
"returns a new OriginalSource instance with sourceStr attribute and " +
"return value of identifier() function provided as constructor arguments",
() => {
const originalSource = new OriginalSource(
myRawModule.sourceStr,
myRawModule.identifier()
);
myRawModule.useSourceMap = true;
expect(myRawModule.source()).toEqual(originalSource);
}
);
it(
"returns a new RawSource instance with sourceStr attribute provided " +
"as constructor argument if useSourceMap is falsy",
() => {
const rawSource = new RawSource(myRawModule.sourceStr);
myRawModule.useSourceMap = false;
expect(myRawModule.source()).toEqual(rawSource);
}
);
});
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"'));
expect(hashFoo).not.toBe(hashBar);
});
});
});