generated from sonofmagic/monorepo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.test.ts
76 lines (70 loc) · 2.17 KB
/
webpack.test.ts
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
import path from 'pathe'
import utwm from '@/webpack'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import { compile, getErrors, getMemfsCompiler5, getWarnings, readAssets } from 'webpack-build-utils'
const context = path.resolve(__dirname, 'fixtures/webpack-repo')
describe('webpack build', () => {
it('common', async () => {
const compiler = getMemfsCompiler5({
mode: 'production',
entry: path.resolve(context, './src/index.js'),
context,
plugins: [new MiniCssExtractPlugin()],
output: {
path: path.resolve(context, './dist'),
filename: 'index.js',
},
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
},
],
},
})
const stats = await compile(compiler)
// get all Assets as Record<string,string>
expect(readAssets(compiler, stats)).toMatchSnapshot('assets')
// get all error
expect(getErrors(stats)).toMatchSnapshot('errors')
// get all warnings
expect(getWarnings(stats)).toMatchSnapshot('warnings')
})
it.skip('with plugin', async () => {
const compiler = getMemfsCompiler5({
mode: 'production',
entry: path.resolve(context, './src/index.js'),
context,
plugins: [new MiniCssExtractPlugin()],
output: {
path: path.resolve(context, './dist'),
filename: 'index.js',
},
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
},
],
},
})
utwm({
classListPath: path.resolve(context, '.tw-patch/tw-class-list.json'),
}).apply(compiler)
const stats = await compile(compiler)
// get all Assets as Record<string,string>
expect(readAssets(compiler, stats)).toMatchSnapshot('assets')
// get all error
expect(getErrors(stats)).toMatchSnapshot('errors')
// get all warnings
expect(getWarnings(stats)).toMatchSnapshot('warnings')
})
// webpack({}, (err, stats) => {
// if (err || stats.hasErrors()) {
// // ...
// }
// // Done processing
// });
})