webpack/test/RawModule.unittest.js

64 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-01-18 22:27:19 +08:00
"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");
describe("RawModule", () => {
2018-01-24 20:17:21 +08:00
const source = "sourceStr attribute";
const identifier = "identifierStr attribute";
const readableIdentifier = "readableIdentifierStr attribute";
const myRawModule = new RawModule(source, identifier, readableIdentifier);
2017-01-18 22:27:19 +08:00
describe("identifier", () => {
2018-01-24 20:17:21 +08:00
it("returns value for identifierStr attribute", () => {
expect(myRawModule.identifier()).toBe("identifierStr attribute");
});
});
2017-01-18 22:27:19 +08:00
describe("size", () => {
2018-02-25 18:46:17 +08:00
it('returns value for sourceStr attribute"s length property', () => {
2017-01-18 22:27:19 +08:00
const sourceStrLength = myRawModule.sourceStr.length;
2018-01-24 20:17:21 +08:00
expect(myRawModule.size()).toBe(sourceStrLength);
});
});
2017-01-18 22:27:19 +08:00
describe("readableIdentifier", () => {
2018-02-25 18:46:17 +08:00
it(
'returns result of calling provided requestShortener"s shorten method ' +
"on readableIdentifierStr attribute",
2017-02-10 06:38:39 +08:00
() => {
const requestShortener = new RequestShortener(path.resolve());
2018-01-24 20:17:21 +08:00
expect(myRawModule.readableIdentifier(requestShortener)).toBeDefined();
2017-02-10 06:38:39 +08:00
}
);
});
2017-01-18 22:27:19 +08:00
describe("source", () => {
2018-02-25 18:46:17 +08:00
it(
"returns a new OriginalSource instance with sourceStr attribute and " +
"return value of identifier() function provided as constructor arguments",
2017-01-18 22:27:19 +08:00
() => {
2018-02-25 18:46:17 +08:00
const originalSource = new OriginalSource(
myRawModule.sourceStr,
myRawModule.identifier()
);
myRawModule.useSourceMap = true;
2018-01-24 20:17:21 +08:00
expect(myRawModule.source()).toEqual(originalSource);
2017-02-10 06:38:39 +08:00
}
);
2018-02-25 18:46:17 +08:00
it(
"returns a new RawSource instance with sourceStr attribute provided " +
2018-02-26 10:28:40 +08:00
"as constructor argument if useSourceMap is falsy",
2017-02-10 06:38:39 +08:00
() => {
const rawSource = new RawSource(myRawModule.sourceStr);
myRawModule.useSourceMap = false;
2018-01-24 20:17:21 +08:00
expect(myRawModule.source()).toEqual(rawSource);
2017-02-10 06:38:39 +08:00
}
);
});
});