forked from oxc-project/oxc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminify.test.ts
More file actions
56 lines (50 loc) · 1.49 KB
/
Copy pathminify.test.ts
File metadata and controls
56 lines (50 loc) · 1.49 KB
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
import { Worker } from 'node:worker_threads';
import { describe, expect, it } from 'vitest';
import { minify } from '../index';
describe('simple', () => {
const code = '/*! legal comment */\nfunction foo() { var bar; bar(undefined) } foo();';
it('matches output', () => {
const ret = minify('test.js', code, { sourcemap: true });
expect(ret).toStrictEqual({
'code': 'function foo(){var e;e(void 0)}foo();',
'map': {
'mappings': 'AACA,SAAS,KAAM,CAAE,IAAIA,EAAK,SAAc,AAAE,CAAC,KAAK',
'names': [
'bar',
],
'sources': [
'test.js',
],
'sourcesContent': [
code,
],
'version': 3,
},
});
});
it('can turn off everything', () => {
const ret = minify('test.js', code, { compress: false, mangle: false, codegen: { removeWhitespace: false } });
expect(ret).toStrictEqual({
'code': 'function foo() {\n\tvar bar;\n\tbar(undefined);\n}\nfoo();\n',
});
});
it('defaults to esnext', () => {
const code = 'try { foo } catch (e) {}';
const ret = minify('test.js', code);
expect(ret.code).toBe('try{foo}catch{}');
});
});
describe('worker', () => {
it('should run', async () => {
const code = await new Promise((resolve, reject) => {
const worker = new Worker('./test/worker.mjs');
worker.on('error', (err) => {
reject(err);
});
worker.on('exit', (code) => {
resolve(code);
});
});
expect(code).toBe(0);
});
});