/
options-tests.js
108 lines (96 loc) · 2.65 KB
/
options-tests.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
jest.autoMockOff();
const mocks = [
"babel-plugin-minify-constant-folding",
"babel-plugin-minify-dead-code-elimination",
"babel-plugin-minify-flip-comparisons",
"babel-plugin-minify-guarded-expressions",
"babel-plugin-minify-infinity",
"babel-plugin-minify-mangle-names",
"babel-plugin-minify-numeric-literals",
"babel-plugin-minify-replace",
"babel-plugin-minify-simplify",
"babel-plugin-minify-type-constructors",
"babel-plugin-transform-inline-consecutive-adds",
"babel-plugin-transform-member-expression-literals",
"babel-plugin-transform-merge-sibling-variables",
"babel-plugin-transform-minify-booleans",
"babel-plugin-transform-property-literals",
"babel-plugin-transform-regexp-constructors",
"babel-plugin-transform-remove-console",
"babel-plugin-transform-remove-debugger",
"babel-plugin-transform-remove-undefined",
"babel-plugin-transform-simplify-comparison-operators",
"babel-plugin-transform-undefined-to-void",
];
mocks.forEach((mockName) => {
// it's called mockName for jest(babel-jest-plugin) workaround
jest.mock(mockName, () => mockName);
});
const preset = require("../src/index");
function getPlugins(opts) {
return preset({}, opts).presets[0].plugins;
}
function testOpts(opts) {
expect({
input: opts,
output: getPlugins(opts)
}).toMatchSnapshot();
}
describe("preset-options", () => {
it("should be a function", () => {
expect(typeof preset).toBe("function");
});
it("should return defaults with no options", () => {
expect(getPlugins()).toMatchSnapshot();
expect(getPlugins({})).toMatchSnapshot();
expect(getPlugins(null)).toMatchSnapshot();
});
it("should handle simple options", () => {
testOpts({
mangle: false,
deadcode: false
});
});
it("should pass options to respective plugin when its an object", () => {
testOpts({
mangle: {
blacklist: ["foo", "bar"]
}
});
});
it("should handle groups - remove entire group", () => {
testOpts({
unsafe: false
});
});
it("should handle individual items in a group of options", () => {
testOpts({
unsafe: {
flipComparisons: false
},
mangle: false
});
});
it("should handle options that are delegated to multiple other options", () => {
testOpts({
keepFnName: false,
keepClassName: false
});
testOpts({
keepFnName: true,
keepClassName: true,
mangle: {
blacklist: ["foo", "bar"]
}
});
testOpts({
keepFnName: true,
keepClassName: true,
mangle: {
blacklist: ["baz"],
keepFnName: false,
keepClassName: false,
}
});
});
});