forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSourceMapDevToolModuleOptionsPlugin.unittest.js
147 lines (128 loc) · 3.25 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"use strict";
const SourceMapDevToolModuleOptionsPlugin = require("../lib/SourceMapDevToolModuleOptionsPlugin");
const applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
describe("SourceMapDevToolModuleOptionsPlugin", () => {
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", () => {
expect(eventBindings.length).toBe(0);
});
});
describe("with module true", () => {
beforeEach(() => {
eventBindings = applyPluginWithOptions(
SourceMapDevToolModuleOptionsPlugin,
{
module: true,
lineToLine: false
}
);
});
it("binds one event handler", () => {
expect(eventBindings.length).toBe(1);
});
describe("event handler", () => {
it("binds to build-module event", () => {
expect(eventBindings[0].name).toBe("build-module");
});
it("sets source map flag", () => {
const module = {};
eventBindings[0].handler(module);
expect(module).toEqual({
useSourceMap: true
});
});
});
});
describe("with line-to-line true", () => {
beforeEach(
() =>
(eventBindings = applyPluginWithOptions(
SourceMapDevToolModuleOptionsPlugin,
{
module: false,
lineToLine: true
}
))
);
it("binds one event handler", () => {
expect(eventBindings.length).toBe(1);
});
describe("event handler", () => {
it("binds to build-module event", () => {
expect(eventBindings[0].name).toBe("build-module");
});
it("sets line-to-line flag", () => {
const module = {};
eventBindings[0].handler(module);
expect(module).toEqual({
lineToLine: true
});
});
});
});
describe("with line-to-line object", () => {
beforeEach(() => {
eventBindings = applyPluginWithOptions(
SourceMapDevToolModuleOptionsPlugin,
{
module: false,
lineToLine: {}
}
);
});
it("binds one event handler", () => {
expect(eventBindings.length).toBe(1);
});
describe("event handler", () => {
it("binds to build-module event", () => {
expect(eventBindings[0].name).toBe("build-module");
});
describe("when module has no resource", () => {
it("makes no changes", () => {
const module = {};
eventBindings[0].handler(module);
expect(module).toEqual({});
});
});
describe("when module has a resource", () => {
it("sets line-to-line flag", () => {
const module = {
resource: "foo"
};
eventBindings[0].handler(module);
expect(module).toEqual({
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);
expect(module).toEqual({
lineToLine: true,
resource: "foo?bar"
});
});
});
});
});
});
});