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 }
|
2018-11-08 22:26:52 +00:00
|
|
|
PerfLoader.warmup = jest.fn()
|
|
|
|
PerfLoader.warmupAll({ dev: true })
|
|
|
|
expect(PerfLoader.warmup).toHaveBeenCalledTimes(2)
|
|
|
|
expect(PerfLoader.warmup).toHaveBeenCalledWith(js, [
|
2018-10-22 21:48:06 +00:00
|
|
|
require.resolve('babel-loader'),
|
|
|
|
require.resolve('@babel/preset-env')
|
|
|
|
])
|
2018-11-08 22:26:52 +00:00
|
|
|
expect(PerfLoader.warmup).toHaveBeenCalledWith(css, ['css-loader'])
|
2018-03-30 03:24:51 +00:00
|
|
|
|
2018-11-08 22:26:52 +00:00
|
|
|
const perfLoader = new PerfLoader({
|
|
|
|
name: 'test-perf',
|
|
|
|
options: {
|
|
|
|
dev: true,
|
|
|
|
build: {
|
|
|
|
parallel: true,
|
|
|
|
cache: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
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
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|