-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.test.js
84 lines (70 loc) · 2.9 KB
/
index.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
import CoreJsAutoUpgradePlugin, { rewriteCoreJsRequest } from './index';
describe('CoreJsAutoUpgradePlugin', () => {
it('should be constructable, without options', () => {
expect(() => new CoreJsAutoUpgradePlugin()).not.toThrow()
});
it('should be constructable, with options', () => {
expect(() => new CoreJsAutoUpgradePlugin({
resolveFrom: __dirname,
})).not.toThrow()
});
});
describe('rewriteCoreJsRequest', () => {
const fakeRequire = jest.mock();
describe('rewrite `core-js/modules/*`', () => {
it('should rewrite `core-js/modules/es6.*` import to `core-js/modules/es.*`', () => {
expect(rewriteCoreJsRequest('core-js/modules/es6.object.is-frozen.js')).toBe(
'core-js/modules/es.object.is-frozen.js'
);
});
it('should rewrite `core-js/modules/es7.*` import to `core-js/modules/esnext.*`', () => {
expect(rewriteCoreJsRequest('core-js/modules/es7.math.iaddh.js')).toBe(
'core-js/modules/esnext.math.iaddh.js'
);
});
it('should rewrite `core-js/modules/es.*` import to `core-js/modules/es.*`', () => {
expect(rewriteCoreJsRequest('core-js/modules/es.object.is-frozen.js')).toBe(
'core-js/modules/es.object.is-frozen.js'
);
});
it('should rewrite `core-js/modules/esnext.*` import to `core-js/modules/esnext.*`', () => {
expect(rewriteCoreJsRequest('core-js/modules/esnext.set.some.js')).toBe(
'core-js/modules/esnext.set.some.js'
);
});
});
describe('rewrite `core-js/library/fn/*`', () => {
it('should rewrite `core-js/library/*` import to `core-js-pure/features/*`', () => {
expect(rewriteCoreJsRequest('core-js/library/fn/object/assign')).toBe(
'core-js-pure/features/object/assign'
);
});
});
describe('rewrite `core-js/es(5|6|7)/*`', () => {
it('should not rewrite `core-js/es5` import', () => {
expect(rewriteCoreJsRequest('core-js/es5')).toBeNull();
});
it('should rewrite `core-js/es6/*` import to `core-js/es/*`', () => {
expect(rewriteCoreJsRequest('core-js/es6/object.js')).toBe('core-js/es/object');
expect(rewriteCoreJsRequest('core-js/es6/parse-int')).toBe('core-js/es/parse-int');
});
it('should not rewrite `core-js/es7` import`', () => {
expect(rewriteCoreJsRequest('core-js/es7/array.js')).toBeNull();
});
});
describe('rewrite `core-js/object/*`', () => {
it('should rewrite `core-js/object/*` import to `core-js/features/*`', () => {
expect(rewriteCoreJsRequest('core-js/object/assign.js')).toBe(
'core-js/features/object/assign.js'
);
expect(rewriteCoreJsRequest('../core-js/object/assign')).toBe(
'../core-js/features/object/assign'
);
});
});
it('should preserve request prefix when upgrading the request', () => {
expect(rewriteCoreJsRequest('../foo/core-js/modules/es6.bar.js')).toBe(
'../foo/core-js/modules/es.bar.js'
);
});
});