-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
parallel-option-failure.test.js
108 lines (86 loc) · 2.78 KB
/
parallel-option-failure.test.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os from 'os';
import Worker from 'jest-worker';
import TerserPlugin from '../src/index';
import {
compile,
getCompiler,
getErrors,
getWarnings,
removeCache,
} from './helpers';
jest.mock('os', () => {
const actualOs = require.requireActual('os');
actualOs.cpus = jest.fn(() => {
return { length: 4 };
});
return actualOs;
});
// Based on https://github.com/facebook/jest/blob/edde20f75665c2b1e3c8937f758902b5cf28a7b4/packages/jest-runner/src/__tests__/test_runner.test.js
let workerTransform;
let workerEnd;
jest.mock('jest-worker', () => {
return jest.fn().mockImplementation(() => {
return {
// eslint-disable-next-line global-require, import/no-dynamic-require
transform: (workerTransform = jest.fn(() => {
throw new Error('jest-worker failed');
})),
end: (workerEnd = jest.fn()),
};
});
});
const workerPath = require.resolve('../src/worker');
describe('parallel option', () => {
let compiler;
beforeEach(() => {
jest.clearAllMocks();
compiler = getCompiler({
entry: {
one: `${__dirname}/fixtures/entry.js`,
two: `${__dirname}/fixtures/entry.js`,
},
});
return Promise.all([removeCache()]);
});
afterEach(() => Promise.all([removeCache()]));
it('should match snapshot for errors into the "jest-worker" package', async () => {
new TerserPlugin(
getCompiler.isWebpack4()
? { parallel: true, cache: false }
: { parallel: true }
).apply(compiler);
const stats = await compile(compiler);
expect(Worker).toHaveBeenCalledTimes(1);
expect(Worker).toHaveBeenLastCalledWith(workerPath, {
numWorkers: os.cpus().length - 1,
forkOptions: {
silent: false,
},
});
expect(workerTransform).toHaveBeenCalledTimes(
Object.keys(stats.compilation.assets).length
);
expect(workerEnd).toHaveBeenCalledTimes(1);
expect(getErrors(stats)).toMatchSnapshot('errors');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
});
if (getCompiler.isWebpack4()) {
it('should match snapshot for errors into the "jest-worker" package whe the "cache" option is "true"', async () => {
new TerserPlugin({ parallel: true, cache: true }).apply(compiler);
const stats = await compile(compiler);
expect(Worker).toHaveBeenCalledTimes(1);
expect(Worker).toHaveBeenLastCalledWith(workerPath, {
numWorkers: os.cpus().length - 1,
forkOptions: {
silent: false,
},
});
expect(workerTransform).toHaveBeenCalledTimes(
Object.keys(stats.compilation.assets).length
);
expect(workerEnd).toHaveBeenCalledTimes(1);
expect(getErrors(stats)).toMatchSnapshot('errors');
expect(getWarnings(stats)).toMatchSnapshot('warnings');
});
}
});