/
node-api-tests.js
55 lines (44 loc) · 1.18 KB
/
node-api-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
jest.autoMockOff();
const minify = require("../src/index");
const sampleInput = `
function foo() {
const bar = x(1);
const baz = y(2);
return z(bar, baz);
}
`;
describe("babel-minify Node API", () => {
it("simple usage", () => {
expect(minify(sampleInput).code).toMatchSnapshot();
});
it("throw on invalid options", () => {
expect(() => minify(sampleInput, { foo: false, bar: true }).code).toThrow();
});
it("override default minify options", () => {
const minifyOpts = { mangle: false };
expect(minify(sampleInput, minifyOpts).code).toMatchSnapshot();
});
it("override nested minify options", () => {
const minifyOpts = { mangle: { keepFnName: false } };
expect(minify(sampleInput, minifyOpts).code).toMatchSnapshot();
});
it("preserve default comments", () => {
const code = `
/* @license MIT */
(function() {
/*! mylib.js */
function a() {}
a();
})();
`;
expect(minify(code, {}).code).toMatchSnapshot();
});
it("remove comments ", () => {
const code = `
/* foo */
var a = 10;
!function(){}() // blah
`;
expect(minify(code, {}).code).toMatchSnapshot();
});
});