UNPKG

5.22 kBJavaScriptView Raw
1jest.mock('babel-plugin-check-es2015-constants', () => 'babel-plugin-check-es2015-constants');
2jest.mock('babel-plugin-transform-es2015-modules-commonjs', () => 'babel-plugin-transform-es2015-modules-commonjs');
3jest.mock('babel-plugin-transform-es2015-arrow-functions', () => 'babel-plugin-transform-es2015-arrow-functions');
4jest.mock('babel-plugin-transform-es2015-function-name', () => 'babel-plugin-transform-es2015-function-name');
5jest.mock('babel-plugin-transform-exponentiation-operator', () => 'babel-plugin-transform-exponentiation-operator');
6jest.mock('babel-plugin-syntax-trailing-function-commas', () => 'babel-plugin-syntax-trailing-function-commas');
7jest.mock('babel-plugin-transform-async-to-generator', () => 'babel-plugin-transform-async-to-generator');
8
9const pluginCheckConstants = require('babel-plugin-check-es2015-constants');
10const pluginModulesCommonjs = require('babel-plugin-transform-es2015-modules-commonjs');
11const pluginArrowFunctions = require('babel-plugin-transform-es2015-arrow-functions');
12const pluginFunctionName = require('babel-plugin-transform-es2015-function-name');
13const pluginExponentiationOperator = require('babel-plugin-transform-exponentiation-operator');
14const pluginTrailingFunctionCommas = require('babel-plugin-syntax-trailing-function-commas');
15const pluginAsync = require('babel-plugin-transform-async-to-generator');
16
17const preset = require('./');
18
19describe('target option', () => {
20 test('6.1 is not a valid target', () => {
21 expect(() => preset(null, { target: '6.1' })).toThrow('Preset latest-node \'target\' option must one of 6, 6.5, 7, 7.6, 8, current.');
22 });
23
24 ['6', '6.5', '7', '7.6', '8', 6, 6.5, 7, 7.6, 8, 'current'].forEach((target) => {
25 test(`${target} ${typeof target} is a valid target`, () => {
26 expect(preset(null, { target })).toBeDefined();
27 });
28 });
29});
30
31describe('modules option', () => {
32 test('xx is not a valid modules option', () => {
33 expect(() => preset(null, { target: 'current', modules: 'xx' })).toThrow('Preset latest-node \'modules\' option must be \'false\' to indicate no modules\nor \'commonjs\' (default)');
34 });
35
36 ['commonjs', false].forEach((option) => {
37 test(`${option} is a valid modules option`, () => {
38 expect(preset(null, { target: 'current', modules: option })).toBeDefined();
39 });
40 });
41});
42
43describe('loose option', () => {
44 test('xx is not a valid loose option', () => {
45 expect(() => preset(null, { target: 'current', loose: 'xx' })).toThrow('Preset latest-node \'loose\' option must be a boolean.');
46 });
47
48 [true, false].forEach((option) => {
49 test(`${option} is a valid loose option`, () => {
50 expect(preset(null, { target: 'current', loose: option })).toBeDefined();
51 });
52 });
53});
54
55describe('plugins', () => {
56 test('6', () => {
57 expect(preset(null, { target: '6' })).toEqual({
58 plugins: [
59 pluginCheckConstants,
60 [pluginModulesCommonjs, { loose: false }],
61 pluginArrowFunctions,
62 pluginFunctionName,
63 pluginExponentiationOperator,
64 pluginTrailingFunctionCommas,
65 pluginAsync,
66 ],
67 });
68 });
69
70 test('6 loose: false', () => {
71 expect(preset(null, { target: '6', loose: false })).toEqual({
72 plugins: [
73 pluginCheckConstants,
74 [pluginModulesCommonjs, { loose: false }],
75 pluginArrowFunctions,
76 pluginFunctionName,
77 pluginExponentiationOperator,
78 pluginTrailingFunctionCommas,
79 pluginAsync,
80 ],
81 });
82 });
83
84 test('6 loose: true', () => {
85 expect(preset(null, { target: '6', loose: true })).toEqual({
86 plugins: [
87 pluginCheckConstants,
88 [pluginModulesCommonjs, { loose: true }],
89 pluginArrowFunctions,
90 pluginFunctionName,
91 pluginExponentiationOperator,
92 pluginTrailingFunctionCommas,
93 pluginAsync,
94 ],
95 });
96 });
97
98 test('6 modules: false', () => {
99 expect(preset(null, { target: '6', modules: false })).toEqual({
100 plugins: [
101 pluginCheckConstants,
102 pluginArrowFunctions,
103 pluginFunctionName,
104 pluginExponentiationOperator,
105 pluginTrailingFunctionCommas,
106 pluginAsync,
107 ],
108 });
109 });
110
111 test('6.5', () => {
112 expect(preset(null, { target: '6.5' })).toEqual({
113 plugins: [
114 pluginCheckConstants,
115 [pluginModulesCommonjs, { loose: false }],
116 pluginExponentiationOperator,
117 pluginTrailingFunctionCommas,
118 pluginAsync,
119 ],
120 });
121 });
122
123 test('7', () => {
124 expect(preset(null, { target: '7' })).toEqual({
125 plugins: [
126 pluginCheckConstants,
127 [pluginModulesCommonjs, { loose: false }],
128 pluginTrailingFunctionCommas,
129 pluginAsync,
130 ],
131 });
132 });
133
134 test('7.6', () => {
135 expect(preset(null, { target: '7.6' })).toEqual({
136 plugins: [
137 pluginCheckConstants,
138 [pluginModulesCommonjs, { loose: false }],
139 pluginTrailingFunctionCommas,
140 ],
141 });
142 });
143
144 test('8', () => {
145 expect(preset(null, { target: '8' })).toEqual({
146 plugins: [
147 pluginCheckConstants,
148 [pluginModulesCommonjs, { loose: false }],
149 pluginTrailingFunctionCommas,
150 ],
151 });
152 });
153});