-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathend-project.test.js
160 lines (133 loc) · 4.67 KB
/
end-project.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'use strict';
const babelCore = require('@babel/core');
const serializerPath = require('jest-serializer-path');
const preset = require('./end-project');
const env = process.env.NODE_ENV;
expect.addSnapshotSerializer(serializerPath);
afterEach(() => {
process.env.NODE_ENV = env;
});
it('should have the right config with the default options', () => {
expect(preset()).toMatchSnapshot();
});
describe('modules', () => {
it('should set modules to false if options.modules is disabled', () => {
expect(preset(null, { modules: false })).toMatchSnapshot();
});
it('should set modules to false by default if BABEL_ENV is es', () => {
process.env.BABEL_ENV = 'es';
try {
expect(preset(null)).toMatchSnapshot();
} finally {
delete process.env.BABEL_ENV;
}
});
});
describe('loose', () => {
it('should disable loose if options.loose is disabled', () => {
expect(preset(null, { loose: true })).toMatchSnapshot();
});
});
describe('react', () => {
it('should enable react plugins if options.react is enabled and enable development goodies', () => {
expect(preset(null, { react: true })).toMatchSnapshot();
});
it('should enable react optimizations if options.env is production', () => {
expect(preset(null, { env: 'production', react: true })).toMatchSnapshot();
});
});
describe('lodash', () => {
it('should disable the lodash plugin if options.lodash is disabled', () => {
expect(preset(null, { lodash: false })).toMatchSnapshot();
});
it('should pass any options to the lodash plugin', () => {
expect(preset(null, { lodash: { id: 'recompose' } })).toMatchSnapshot();
});
});
describe('targets', () => {
it('should return a default config that target browsers and node', () => {
expect(preset()).toMatchSnapshot();
});
it('should return a config for node if options.targets is set to node', () => {
expect(preset(null, { targets: ['node'] })).toMatchSnapshot();
});
it('should return a config for browsers if options.targets is set to browsers', () => {
expect(preset(null, { targets: ['browsers'] })).toMatchSnapshot();
});
it('should allow overriding options.targets with an object', () => {
expect(preset(null, { targets: { node: 'current' } })).toMatchSnapshot();
});
});
describe('env', () => {
it('should take into consideration process.env.NODE_ENV', () => {
process.env.NODE_ENV = 'development';
expect(preset(null, { react: true })).toMatchSnapshot();
process.env.NODE_ENV = 'production';
expect(preset(null, { react: true })).toMatchSnapshot();
});
});
describe('dynamicImport', () => {
it('should take into consideration options.dynamicImport', () => {
expect(preset(null, { dynamicImport: false })).toMatchSnapshot();
});
});
describe('functional', () => {
describe('object-rest-spread', () => {
it('should handle correctly', () => {
expect(
babelCore.transform(`
var z = { x, ...y };
`, preset()).code
).toMatchSnapshot();
});
it('should handle correctly for target with support', () => {
const targets = {
chrome: '60',
};
expect(
babelCore.transform(`
var z = { x, ...y };
`, preset(null, { targets })).code
).toMatchSnapshot();
});
});
describe('class-properties', () => {
it('should handle correctly', () => {
expect(
babelCore.transform(`
class Bork {
static a = 'foo';
static b;
x = 'bar';
y;
}
`, preset()).code
).toMatchSnapshot();
});
});
describe('optional-chaining', () => {
it('should handle correctly', () => {
expect(
babelCore.transform(`
const obj = {
foo: {
bar: {
baz: 42,
},
},
};
const baz = obj?.foo?.bar?.baz;
`, preset()).code
).toMatchSnapshot();
});
});
describe('nullish-coalescing-operator', () => {
it('should handle correctly', () => {
expect(
babelCore.transform(`
const foo = object.foo ?? 'bar';
`, preset()).code
).toMatchSnapshot();
});
});
});