|
1 | 1 | const preset = require(`../`)
|
2 |
| -const path = require(`path`) |
3 | 2 |
|
4 |
| -it(`Specifies proper presets and plugins in Node mode`, () => { |
5 |
| - const { presets, plugins } = preset() |
6 |
| - |
7 |
| - expect(presets).toEqual([ |
8 |
| - [ |
9 |
| - expect.stringContaining(path.join(`@babel`, `preset-env`)), |
10 |
| - { |
11 |
| - debug: false, |
12 |
| - loose: true, |
13 |
| - modules: `commonjs`, |
14 |
| - shippedProposals: true, |
15 |
| - targets: { |
16 |
| - node: `current`, |
17 |
| - }, |
18 |
| - useBuiltIns: `entry`, |
19 |
| - }, |
20 |
| - ], |
21 |
| - [ |
22 |
| - expect.stringContaining(path.join(`@babel`, `preset-react`)), |
23 |
| - { development: true }, |
24 |
| - ], |
25 |
| - expect.stringContaining(path.join(`@babel`, `preset-flow`)), |
26 |
| - ]) |
27 |
| - expect(plugins).toEqual([ |
28 |
| - expect.stringContaining( |
29 |
| - path.join(`@babel`, `plugin-proposal-class-properties`) |
30 |
| - ), |
31 |
| - expect.stringContaining( |
32 |
| - path.join(`@babel`, `plugin-proposal-optional-chaining`) |
33 |
| - ), |
34 |
| - expect.stringContaining(path.join(`@babel`, `plugin-transform-runtime`)), |
35 |
| - expect.stringContaining( |
36 |
| - path.join(`@babel`, `plugin-syntax-dynamic-import`) |
37 |
| - ), |
38 |
| - ]) |
39 |
| -}) |
40 |
| - |
41 |
| -it(`Specifies proper presets and plugins in debug Node mode`, () => { |
42 |
| - const { presets, plugins } = preset(null, { debug: true }) |
43 |
| - |
44 |
| - expect(presets).toEqual([ |
45 |
| - [ |
46 |
| - expect.stringContaining(path.join(`@babel`, `preset-env`)), |
47 |
| - { |
48 |
| - debug: true, |
49 |
| - loose: true, |
50 |
| - modules: `commonjs`, |
51 |
| - shippedProposals: true, |
52 |
| - targets: { |
53 |
| - node: `current`, |
54 |
| - }, |
55 |
| - useBuiltIns: `entry`, |
56 |
| - }, |
57 |
| - ], |
58 |
| - [ |
59 |
| - expect.stringContaining(path.join(`@babel`, `preset-react`)), |
60 |
| - { development: true }, |
61 |
| - ], |
62 |
| - expect.stringContaining(path.join(`@babel`, `preset-flow`)), |
63 |
| - ]) |
64 |
| - expect(plugins).toEqual([ |
65 |
| - expect.stringContaining( |
66 |
| - path.join(`@babel`, `plugin-proposal-class-properties`) |
67 |
| - ), |
68 |
| - expect.stringContaining( |
69 |
| - path.join(`@babel`, `plugin-proposal-optional-chaining`) |
70 |
| - ), |
71 |
| - expect.stringContaining(path.join(`@babel`, `plugin-transform-runtime`)), |
72 |
| - expect.stringContaining( |
73 |
| - path.join(`@babel`, `plugin-syntax-dynamic-import`) |
74 |
| - ), |
75 |
| - ]) |
76 |
| -}) |
77 |
| - |
78 |
| -it(`Specifies proper presets and plugins in browser mode`, () => { |
79 |
| - const { presets, plugins } = preset(null, { browser: true }) |
80 |
| - |
81 |
| - expect(presets).toEqual([ |
82 |
| - [ |
83 |
| - expect.stringContaining(path.join(`@babel`, `preset-env`)), |
84 |
| - { |
85 |
| - debug: false, |
86 |
| - loose: true, |
87 |
| - modules: `commonjs`, |
88 |
| - shippedProposals: true, |
89 |
| - targets: { |
90 |
| - browsers: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`], |
91 |
| - }, |
92 |
| - useBuiltIns: false, |
93 |
| - }, |
94 |
| - ], |
95 |
| - [ |
96 |
| - expect.stringContaining(path.join(`@babel`, `preset-react`)), |
97 |
| - { development: true }, |
98 |
| - ], |
99 |
| - expect.stringContaining(path.join(`@babel`, `preset-flow`)), |
100 |
| - ]) |
101 |
| - expect(plugins).toEqual([ |
102 |
| - expect.stringContaining( |
103 |
| - path.join(`@babel`, `plugin-proposal-class-properties`) |
104 |
| - ), |
105 |
| - expect.stringContaining( |
106 |
| - path.join(`@babel`, `plugin-proposal-optional-chaining`) |
107 |
| - ), |
108 |
| - expect.stringContaining(path.join(`@babel`, `plugin-transform-runtime`)), |
109 |
| - expect.stringContaining( |
110 |
| - path.join(`@babel`, `plugin-syntax-dynamic-import`) |
111 |
| - ), |
112 |
| - ]) |
113 |
| -}) |
114 |
| - |
115 |
| -it(`Specifies proper presets and plugins in debug browser mode`, () => { |
116 |
| - const { presets, plugins } = preset(null, { browser: true, debug: true }) |
117 |
| - |
118 |
| - expect(presets).toEqual([ |
119 |
| - [ |
120 |
| - expect.stringContaining(path.join(`@babel`, `preset-env`)), |
121 |
| - { |
122 |
| - debug: true, |
123 |
| - loose: true, |
124 |
| - modules: `commonjs`, |
125 |
| - shippedProposals: true, |
126 |
| - targets: { |
127 |
| - browsers: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`], |
128 |
| - }, |
129 |
| - useBuiltIns: false, |
130 |
| - }, |
131 |
| - ], |
132 |
| - [ |
133 |
| - expect.stringContaining(path.join(`@babel`, `preset-react`)), |
134 |
| - { development: true }, |
135 |
| - ], |
136 |
| - expect.stringContaining(path.join(`@babel`, `preset-flow`)), |
137 |
| - ]) |
138 |
| - expect(plugins).toEqual([ |
139 |
| - expect.stringContaining( |
140 |
| - path.join(`@babel`, `plugin-proposal-class-properties`) |
141 |
| - ), |
142 |
| - expect.stringContaining( |
143 |
| - path.join(`@babel`, `plugin-proposal-optional-chaining`) |
144 |
| - ), |
145 |
| - expect.stringContaining(path.join(`@babel`, `plugin-transform-runtime`)), |
146 |
| - expect.stringContaining( |
147 |
| - path.join(`@babel`, `plugin-syntax-dynamic-import`) |
148 |
| - ), |
149 |
| - ]) |
| 3 | +jest.mock(`../resolver`, () => jest.fn(moduleName => moduleName)) |
| 4 | + |
| 5 | +describe(`babel-preset-gatsby-package`, () => { |
| 6 | + describe(`in node mode`, () => { |
| 7 | + it(`specifies the proper plugins`, () => { |
| 8 | + const { plugins } = preset() |
| 9 | + expect(plugins).toMatchSnapshot() |
| 10 | + }) |
| 11 | + |
| 12 | + it(`specifies proper presets`, () => { |
| 13 | + const { presets } = preset() |
| 14 | + expect(presets).toMatchSnapshot() |
| 15 | + }) |
| 16 | + |
| 17 | + it(`specifies proper presets for debugging`, () => { |
| 18 | + const { presets } = preset(null, { debug: true }) |
| 19 | + expect(presets).toMatchSnapshot() |
| 20 | + }) |
| 21 | + }) |
| 22 | + |
| 23 | + describe(`in browser mode`, () => { |
| 24 | + it(`specifies the proper plugins`, () => { |
| 25 | + const { plugins } = preset(null, { browser: true }) |
| 26 | + expect(plugins).toMatchSnapshot() |
| 27 | + }) |
| 28 | + |
| 29 | + it(`specifies proper presets`, () => { |
| 30 | + const { presets } = preset(null, { browser: true }) |
| 31 | + expect(presets).toMatchSnapshot() |
| 32 | + }) |
| 33 | + |
| 34 | + it(`specifies proper presets for debugging`, () => { |
| 35 | + const { presets } = preset(null, { browser: true, debug: true }) |
| 36 | + expect(presets).toMatchSnapshot() |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + describe(`in production mode`, () => { |
| 41 | + let env |
| 42 | + |
| 43 | + beforeAll(() => { |
| 44 | + env = process.env.BABEL_ENV |
| 45 | + process.env.BABEL_ENV = `production` |
| 46 | + }) |
| 47 | + |
| 48 | + afterAll(() => { |
| 49 | + process.env.BABEL_ENV = env |
| 50 | + }) |
| 51 | + |
| 52 | + it(`specifies proper presets for node mode`, () => { |
| 53 | + const { presets } = preset(null) |
| 54 | + expect(presets).toMatchSnapshot() |
| 55 | + }) |
| 56 | + |
| 57 | + it(`specifies proper presets for browser mode`, () => { |
| 58 | + const { presets } = preset(null, { browser: true }) |
| 59 | + expect(presets).toMatchSnapshot() |
| 60 | + }) |
| 61 | + }) |
150 | 62 | })
|
0 commit comments