forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSourceMapDevToolModuleOptionsPlugin.unittest.js
118 lines (98 loc) · 3.22 KB
/
SourceMapDevToolModuleOptionsPlugin.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"use strict";
const should = require("should");
const SourceMapDevToolModuleOptionsPlugin = require("../lib/SourceMapDevToolModuleOptionsPlugin");
const applyPluginWithOptions = require('./helpers/applyPluginWithOptions');
describe("SourceMapDevToolModuleOptionsPlugin", () => {
it("has apply function", () => (new SourceMapDevToolModuleOptionsPlugin()).apply.should.be.a.Function());
describe("when applied", () => {
let eventBindings;
beforeEach(() => eventBindings = undefined);
describe("with module false and line-to-line false", () => {
beforeEach(() =>
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
module: false,
lineToLine: false
}));
it("does not bind any event handlers", () => eventBindings.length.should.be.exactly(0));
});
describe("with module true", () => {
beforeEach(() =>
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
module: true,
lineToLine: false
}));
it("binds one event handler", () => eventBindings.length.should.be.exactly(1));
describe("event handler", () => {
it("binds to build-module event", () =>
eventBindings[0].name.should.be.exactly("build-module"));
it("sets source map flag", () => {
const module = {};
eventBindings[0].handler(module);
module.should.deepEqual({
useSourceMap: true
});
});
});
});
describe("with line-to-line true", () => {
beforeEach(() =>
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
module: false,
lineToLine: true
}));
it("binds one event handler", () => eventBindings.length.should.be.exactly(1));
describe("event handler", () => {
it("binds to build-module event", () => eventBindings[0].name.should.be.exactly("build-module"));
it("sets line-to-line flag", () => {
const module = {};
eventBindings[0].handler(module);
module.should.deepEqual({
lineToLine: true
});
});
});
});
describe("with line-to-line object", () => {
beforeEach(() =>
eventBindings = applyPluginWithOptions(SourceMapDevToolModuleOptionsPlugin, {
module: false,
lineToLine: {}
}));
it("binds one event handler", () => eventBindings.length.should.be.exactly(1));
describe("event handler", () => {
it("binds to build-module event", () => eventBindings[0].name.should.be.exactly("build-module"));
describe("when module has no resource", () => {
it("makes no changes", () => {
const module = {};
eventBindings[0].handler(module);
module.should.deepEqual({});
});
});
describe("when module has a resource", () => {
it("sets line-to-line flag", () => {
const module = {
resource: "foo"
};
eventBindings[0].handler(module);
module.should.deepEqual({
lineToLine: true,
resource: "foo"
});
});
});
describe("when module has a resource with query", () => {
it("sets line-to-line flag", () => {
const module = {
resource: "foo?bar"
};
eventBindings[0].handler(module);
module.should.deepEqual({
lineToLine: true,
resource: "foo?bar"
});
});
});
});
});
});
});