This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
test.js
103 lines (86 loc) · 2.5 KB
/
test.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
'use strict';
const TerserOptimizer = require('.');
const createPlugin = config => {
return new TerserOptimizer({
plugins: {},
...config,
});
};
const path = 'file.js';
const data = '(function() {var first = 5; window.second = first;})()';
const uglified = 'window.second=5;';
const modern = `
// All credits to Netflix for providing this approach to ES6 feature detection.
/* https://gist.github.com/DaBs/89ccc2ffd1d435efdacff05248514f38 */
class ಠ_ಠ extends Array {
constructor(j = "a", ...c) {
const q = (({u: e}) => {
return { [\`s\${c}\`]: Symbol(j) };
})({});
super(j, q, ...c);
}
}
new Promise((f) => {
const a = function* (){
return "\u{20BB7}".match(/./u)[0].length === 2 || true;
};
for (let vre of a()) {
const [uw, as, he, re] = [
new Set(),
new WeakSet(),
new Map(),
new WeakMap(),
];
break;
}
f(new Proxy({}, {
get: (han, h) => h in han ? han[h] : "42".repeat(0o10)
}),);
}).then(bi => new ಠ_ಠ(bi.rd));
`;
describe('terser-brunch', () => {
it('should have `optimize` method', () => {
createPlugin().should.respondTo('optimize');
});
it('should compile and produce valid result', async () => {
(await createPlugin().optimize({data, path})).should.eql({data: uglified});
});
it('should optimize modern JavaScript', async () => {
const {data} = (await createPlugin().optimize({data: modern, path}));
const arr = await eval(data);
arr.should.be.an('array');
arr[0].should.equal('4242424242424242');
arr[1].s.should.be.a('symbol');
});
it('should produce source maps', async () => {
const plugin = createPlugin({
sourceMaps: true,
});
(await plugin.optimize({data, path})).should.eql({
data: uglified,
map: '{"version":3,"sources":["0"],"names":["window","second"],"mappings":"AAA4BA,OAAOC,OAAV"}',
});
});
it('should return ignored files as-is',async () => {
const path = 'ignored.js';
const map = '{"version": 3}';
const plugin = createPlugin({
plugins: {
terser: {
ignored: path,
},
},
});
(await plugin.optimize({data, path, map})).should.eql({data, map});
});
it('should match ignored files correctly', async () => {
const plugin = createPlugin({
plugins: {
terser: {
ignored: 'ignored.js',
},
},
});
(await plugin.optimize({data, path: 'file.js'})).should.eql({data: uglified});
});
});