UNPKG

3.7 kBPlain TextView Raw
1import { create as berunJs } from '@berun/berun'
2import presetReact from '../src/preset-react'
3
4test('Gets Webpack core configuration', () => {
5 const berun = berunJs(presetReact)
6
7 expect(berun.webpack.get('mode')).toEqual('development')
8
9 expect(berun.webpack.get('devtool')).toEqual('cheap-module-source-map')
10
11 expect(berun.webpack.node.entries()).toEqual({
12 dgram: 'empty',
13 fs: 'empty',
14 net: 'empty',
15 tls: 'empty',
16 childProcess: 'empty'
17 })
18
19 expect(berun.webpack.output.entries()).toMatchObject({
20 pathinfo: true,
21 filename: 'static/js/[name].js',
22 chunkFilename: 'static/js/[name].chunk.js',
23 publicPath: '/',
24 devtoolModuleFilenameTemplate: expect.any(Function)
25 })
26
27 expect(berun.webpack.performance.entries()).toEqual({
28 hints: false
29 })
30
31 expect(berun.webpack.entry('main').values()).toEqual([
32 '/Volumes/DATA/projects/berun/packages/runner-web-polyfills/src/polyfills.ts',
33 '/Volumes/DATA/projects/berun/node_modules/react-dev-utils/webpackHotDevClient.js',
34 '/Volumes/DATA/projects/berun/packages/runner-webpack/src/index.ts'
35 ])
36
37 expect(berun.webpack.module.get('strictExportPresence')).toEqual(true)
38
39 expect(berun.webpack.module.rule('parser').entries()).toEqual({
40 parser: {
41 requireEnsure: false
42 }
43 })
44})
45
46test('Gets Webpack resolve configuration', () => {
47 const berun = berunJs(presetReact)
48
49 expect(berun.webpack.resolve.toConfig()).toMatchObject({
50 alias: {
51 '@babel/runtime':
52 '/Volumes/DATA/projects/berun/node_modules/@babel/runtime',
53 'react-native': 'react-native-web'
54 },
55 extensions: [
56 '.ts',
57 '.tsx',
58 '.web.js',
59 '.mjs',
60 '.js',
61 '.json',
62 '.web.jsx',
63 '.jsx'
64 ],
65 modules: ['node_modules'],
66 plugins: expect.arrayContaining([expect.any(Object)])
67 })
68})
69
70test('Gets Webpack production core configuration', () => {
71 process.env.NODE_ENV = 'production'
72 const berun = berunJs(presetReact)
73
74 expect(berun.webpack.get('mode')).toEqual('production')
75
76 expect(berun.webpack.get('devtool')).toEqual(false)
77
78 expect(berun.webpack.get('bail')).toEqual(true)
79
80 expect(berun.webpack.node.entries()).toEqual({
81 dgram: 'empty',
82 fs: 'empty',
83 net: 'empty',
84 tls: 'empty',
85 childProcess: 'empty'
86 })
87
88 expect(berun.webpack.output.entries()).toMatchObject({
89 path: '/Volumes/DATA/projects/berun/packages/runner-webpack/build',
90 filename: 'static/js/[name].[chunkhash:8].js',
91 chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
92 publicPath: '/',
93 devtoolModuleFilenameTemplate: expect.any(Function)
94 })
95
96 expect(berun.webpack.performance.entries()).toEqual({
97 hints: false
98 })
99
100 expect(berun.webpack.entry('main').values()).toEqual([
101 '/Volumes/DATA/projects/berun/packages/runner-web-polyfills/src/polyfills.ts',
102 '/Volumes/DATA/projects/berun/packages/runner-webpack/src/index.ts'
103 ])
104
105 expect(berun.webpack.module.get('strictExportPresence')).toEqual(true)
106
107 expect(berun.webpack.module.rule('parser').entries()).toEqual({
108 parser: {
109 requireEnsure: false
110 }
111 })
112})
113
114test('Gets Webpack production resolve configuration', () => {
115 process.env.NODE_ENV = 'production'
116 const berun = berunJs(presetReact)
117
118 expect(berun.webpack.resolve.toConfig()).toMatchObject({
119 alias: {
120 '@babel/runtime':
121 '/Volumes/DATA/projects/berun/node_modules/@babel/runtime',
122 'react-native': 'react-native-web'
123 },
124 extensions: [
125 '.ts',
126 '.tsx',
127 '.web.js',
128 '.mjs',
129 '.js',
130 '.json',
131 '.web.jsx',
132 '.jsx'
133 ],
134 modules: ['node_modules'],
135 plugins: expect.arrayContaining([expect.any(Object)])
136 })
137})