2018-03-30 03:24:51 +00:00
|
|
|
import path from 'path'
|
2018-12-01 10:13:28 +00:00
|
|
|
import PerfLoader from '../../packages/webpack/src/utils/perf-loader'
|
2018-03-30 03:24:51 +00:00
|
|
|
|
|
|
|
describe('webpack configuration', () => {
|
|
|
|
test('performance loader', () => {
|
|
|
|
const js = { name: 'js', poolTimeout: Infinity }
|
|
|
|
const css = { name: 'css', poolTimeout: Infinity }
|
2020-12-22 17:07:50 +00:00
|
|
|
const resolveModule = jest.fn(id => id)
|
2018-11-08 22:26:52 +00:00
|
|
|
PerfLoader.warmup = jest.fn()
|
2020-12-22 17:07:50 +00:00
|
|
|
PerfLoader.warmupAll({ dev: true, resolveModule })
|
2018-11-08 22:26:52 +00:00
|
|
|
expect(PerfLoader.warmup).toHaveBeenCalledTimes(2)
|
|
|
|
expect(PerfLoader.warmup).toHaveBeenCalledWith(js, [
|
2020-12-22 17:07:50 +00:00
|
|
|
'babel-loader',
|
|
|
|
'@babel/preset-env'
|
2018-10-22 21:48:06 +00:00
|
|
|
])
|
2018-11-08 22:26:52 +00:00
|
|
|
expect(PerfLoader.warmup).toHaveBeenCalledWith(css, ['css-loader'])
|
2018-03-30 03:24:51 +00:00
|
|
|
|
2019-02-18 17:00:51 +00:00
|
|
|
const perfLoader = new PerfLoader(
|
|
|
|
'test-perf',
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
dev: true
|
|
|
|
},
|
|
|
|
buildOptions: {
|
2018-11-08 22:26:52 +00:00
|
|
|
parallel: true,
|
|
|
|
cache: true
|
|
|
|
}
|
2020-12-22 17:07:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
resolveModule
|
2018-11-08 22:26:52 +00:00
|
|
|
}
|
2019-02-18 17:00:51 +00:00
|
|
|
)
|
2018-11-08 22:26:52 +00:00
|
|
|
expect(perfLoader.workerPools).toMatchObject({ js, css })
|
|
|
|
const loaders = perfLoader.use('js')
|
|
|
|
const cacheDirectory = path.resolve('node_modules/.cache/cache-loader/test-perf')
|
2018-03-30 03:24:51 +00:00
|
|
|
expect(loaders).toMatchObject([
|
|
|
|
{ loader: 'cache-loader', options: { cacheDirectory } },
|
2018-11-08 22:26:52 +00:00
|
|
|
{ loader: 'thread-loader', options: js }
|
2018-03-30 03:24:51 +00:00
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|