diff --git a/src/TaskRunner.js b/src/TaskRunner.js index eb2ff652..4bfe8d6c 100644 --- a/src/TaskRunner.js +++ b/src/TaskRunner.js @@ -49,12 +49,21 @@ export default class TaskRunner { this.worker = new Worker(workerPath, { numWorkers }); - // Show syntax error from jest-worker // https://github.com/facebook/jest/issues/8872#issuecomment-524822081 + const workerStdout = this.worker.getStdout(); + + if (workerStdout) { + workerStdout.on('data', (chunk) => { + return process.stdout.write(chunk); + }); + } + const workerStderr = this.worker.getStderr(); if (workerStderr) { - workerStderr.pipe(process.stderr); + workerStderr.on('data', (chunk) => { + return process.stderr.write(chunk); + }); } } diff --git a/test/TerserPlugin.test.js b/test/TerserPlugin.test.js index 08c52ee0..f86f60f2 100644 --- a/test/TerserPlugin.test.js +++ b/test/TerserPlugin.test.js @@ -10,6 +10,7 @@ import ChunkTemplate from 'webpack/lib/ChunkTemplate'; import TerserPlugin from '../src/index'; import { + BrokenCodePlugin, compile, countPlugins, getCompiler, @@ -438,4 +439,134 @@ describe('TerserPlugin', () => { expect(getErrors(stats)).toMatchSnapshot('errors'); expect(getWarnings(stats)).toMatchSnapshot('warnings'); }); + + it('should emit an error on a broken code in parallel mode', async () => { + const compiler = getCompiler({ + entry: { + one: `${__dirname}/fixtures/entry.js`, + two: `${__dirname}/fixtures/entry.js`, + }, + }); + + new BrokenCodePlugin().apply(compiler); + + new TerserPlugin({ parallel: true }).apply(compiler); + + const stats = await compile(compiler); + + expect(readsAssets(compiler, stats)).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + }); + + it('should emit an error on a broken code in not parallel mode', async () => { + const compiler = getCompiler({ + entry: { + one: `${__dirname}/fixtures/entry.js`, + two: `${__dirname}/fixtures/entry.js`, + }, + }); + + new BrokenCodePlugin().apply(compiler); + + new TerserPlugin({ parallel: false }).apply(compiler); + + const stats = await compile(compiler); + + expect(readsAssets(compiler, stats)).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + }); + + it('should write stdout and stderr of workers to stdout and stderr of main process in parallel mode', async () => { + const { write: stdoutWrite } = process.stdout; + const { write: stderrWrite } = process.stderr; + + let stdoutOutput = ''; + let stderrOutput = ''; + + process.stdout.write = (str) => { + stdoutOutput += str; + }; + + process.stderr.write = (str) => { + stderrOutput += str; + }; + + const compiler = getCompiler({ + entry: { + one: `${__dirname}/fixtures/empty.js`, + two: `${__dirname}/fixtures/empty.js`, + }, + }); + + new TerserPlugin({ + parallel: true, + minify: () => { + // eslint-disable-next-line no-console + process.stdout.write('stdout\n'); + // eslint-disable-next-line no-console + process.stderr.write('stderr\n'); + + return { code: '' }; + }, + }).apply(compiler); + + const stats = await compile(compiler); + + expect(stdoutOutput).toMatchSnapshot('process stdout output'); + expect(stderrOutput).toMatchSnapshot('process stderr output'); + expect(readsAssets(compiler, stats)).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + + process.stdout.write = stdoutWrite; + process.stderr.write = stderrWrite; + }); + + it('should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode', async () => { + const { write: stdoutWrite } = process.stdout; + const { write: stderrWrite } = process.stderr; + + let stdoutOutput = ''; + let stderrOutput = ''; + + process.stdout.write = (str) => { + stdoutOutput += str; + }; + + process.stderr.write = (str) => { + stderrOutput += str; + }; + + const compiler = getCompiler({ + entry: { + one: `${__dirname}/fixtures/empty.js`, + two: `${__dirname}/fixtures/empty.js`, + }, + }); + + new TerserPlugin({ + parallel: false, + minify: () => { + // eslint-disable-next-line no-console + process.stdout.write('stdout\n'); + // eslint-disable-next-line no-console + process.stderr.write('stderr\n'); + + return { code: '' }; + }, + }).apply(compiler); + + const stats = await compile(compiler); + + expect(stdoutOutput).toMatchSnapshot('process stdout output'); + expect(stderrOutput).toMatchSnapshot('process stderr output'); + expect(readsAssets(compiler, stats)).toMatchSnapshot('assets'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + + process.stdout.write = stdoutWrite; + process.stderr.write = stderrWrite; + }); }); diff --git a/test/__snapshots__/TerserPlugin.test.js.snap.webpack4 b/test/__snapshots__/TerserPlugin.test.js.snap.webpack4 index be37dbb4..43fdf8ec 100644 --- a/test/__snapshots__/TerserPlugin.test.js.snap.webpack4 +++ b/test/__snapshots__/TerserPlugin.test.js.snap.webpack4 @@ -68,6 +68,40 @@ exports[`TerserPlugin buildWarning method 5`] = `"Terser Plugin: Warning [http:/ exports[`TerserPlugin buildWarning method 6`] = `null`; +exports[`TerserPlugin should emit an error on a broken code in not parallel mode: assets 1`] = ` +Object { + "broken.js": "\`Broken===", + "one.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);", + "two.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);", +} +`; + +exports[`TerserPlugin should emit an error on a broken code in not parallel mode: errors 1`] = ` +Array [ + "Error: broken.js from Terser +Unterminated template [broken.js:1,0]", +] +`; + +exports[`TerserPlugin should emit an error on a broken code in not parallel mode: warnings 1`] = `Array []`; + +exports[`TerserPlugin should emit an error on a broken code in parallel mode: assets 1`] = ` +Object { + "broken.js": "\`Broken===", + "one.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);", + "two.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);", +} +`; + +exports[`TerserPlugin should emit an error on a broken code in parallel mode: errors 1`] = ` +Array [ + "Error: broken.js from Terser +Unterminated template [broken.js:1,0]", +] +`; + +exports[`TerserPlugin should emit an error on a broken code in parallel mode: warnings 1`] = `Array []`; + exports[`TerserPlugin should regenerate hash: assets 1`] = ` Object { "4.4.f1a57a9ca1b30ec6dc5a.js": "(window.webpackJsonp=window.webpackJsonp||[]).push([[4],{4:function(n,p,s){\\"use strict\\";s.r(p),p.default=\\"async-dep\\"}}]);", @@ -313,3 +347,49 @@ exports[`TerserPlugin should work in multi compiler mode: warnings 1`] = `Array exports[`TerserPlugin should work in multi compiler mode: warnings 2`] = `Array []`; exports[`TerserPlugin should work in multi compiler mode: warnings 3`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: assets 1`] = ` +Object { + "one.js": "", + "two.js": "", +} +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: errors 1`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: process stderr output 1`] = ` +"stderr +stderr +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: process stdout output 1`] = ` +"stdout +stdout +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: warnings 1`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = ` +Object { + "one.js": "", + "two.js": "", +} +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: errors 1`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stderr output 1`] = ` +"stderr +stderr +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stdout output 1`] = ` +"stdout +stdout +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/TerserPlugin.test.js.snap.webpack5 b/test/__snapshots__/TerserPlugin.test.js.snap.webpack5 index 19860644..85da1b9f 100644 --- a/test/__snapshots__/TerserPlugin.test.js.snap.webpack5 +++ b/test/__snapshots__/TerserPlugin.test.js.snap.webpack5 @@ -68,6 +68,40 @@ exports[`TerserPlugin buildWarning method 5`] = `"Terser Plugin: Warning [http:/ exports[`TerserPlugin buildWarning method 6`] = `null`; +exports[`TerserPlugin should emit an error on a broken code in not parallel mode: assets 1`] = ` +Object { + "broken.js": "\`Broken===", + "one.js": "(()=>{var r={791:r=>{r.exports=function(){console.log(7)}}},o={};!function t(e){if(o[e])return o[e].exports;var n=o[e]={exports:{}};return r[e](n,n.exports,t),n.exports}(791)})();", + "two.js": "(()=>{var r={791:r=>{r.exports=function(){console.log(7)}}},o={};!function t(e){if(o[e])return o[e].exports;var n=o[e]={exports:{}};return r[e](n,n.exports,t),n.exports}(791)})();", +} +`; + +exports[`TerserPlugin should emit an error on a broken code in not parallel mode: errors 1`] = ` +Array [ + "Error: broken.js from Terser +Unterminated template [broken.js:1,0]", +] +`; + +exports[`TerserPlugin should emit an error on a broken code in not parallel mode: warnings 1`] = `Array []`; + +exports[`TerserPlugin should emit an error on a broken code in parallel mode: assets 1`] = ` +Object { + "broken.js": "\`Broken===", + "one.js": "(()=>{var r={791:r=>{r.exports=function(){console.log(7)}}},o={};!function t(e){if(o[e])return o[e].exports;var n=o[e]={exports:{}};return r[e](n,n.exports,t),n.exports}(791)})();", + "two.js": "(()=>{var r={791:r=>{r.exports=function(){console.log(7)}}},o={};!function t(e){if(o[e])return o[e].exports;var n=o[e]={exports:{}};return r[e](n,n.exports,t),n.exports}(791)})();", +} +`; + +exports[`TerserPlugin should emit an error on a broken code in parallel mode: errors 1`] = ` +Array [ + "Error: broken.js from Terser +Unterminated template [broken.js:1,0]", +] +`; + +exports[`TerserPlugin should emit an error on a broken code in parallel mode: warnings 1`] = `Array []`; + exports[`TerserPlugin should regenerate hash: assets 1`] = ` Object { "598.598.231e24cc7ba6b0dd72f5.js": "(window.webpackJsonp=window.webpackJsonp||[]).push([[598],{598:(s,n,p)=>{\\"use strict\\";p.r(n),p.d(n,{default:()=>w});const w=\\"async-dep\\"}}]);", @@ -261,3 +295,49 @@ exports[`TerserPlugin should work in multi compiler mode: warnings 1`] = `Array exports[`TerserPlugin should work in multi compiler mode: warnings 2`] = `Array []`; exports[`TerserPlugin should work in multi compiler mode: warnings 3`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: assets 1`] = ` +Object { + "one.js": "", + "two.js": "", +} +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: errors 1`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: process stderr output 1`] = ` +"stderr +stderr +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: process stdout output 1`] = ` +"stdout +stdout +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in not parallel mode: warnings 1`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: assets 1`] = ` +Object { + "one.js": "", + "two.js": "", +} +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: errors 1`] = `Array []`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stderr output 1`] = ` +"stderr +stderr +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: process stdout output 1`] = ` +"stdout +stdout +" +`; + +exports[`TerserPlugin should write stdout and stderr of workers to stdout and stderr of main process in parallel mode: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/parallel-option-failure.test.js.snap.webpack4 b/test/__snapshots__/parallel-option-failure.test.js.snap.webpack4 deleted file mode 100644 index 41faf0fb..00000000 --- a/test/__snapshots__/parallel-option-failure.test.js.snap.webpack4 +++ /dev/null @@ -1,23 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`parallel option should match snapshot for errors into the "jest-worker" package whe the "cache" option is "true": errors 1`] = ` -Array [ - "Error: one.js from Terser -Error: jest-worker failed", - "Error: two.js from Terser -Error: jest-worker failed", -] -`; - -exports[`parallel option should match snapshot for errors into the "jest-worker" package whe the "cache" option is "true": warnings 1`] = `Array []`; - -exports[`parallel option should match snapshot for errors into the "jest-worker" package: errors 1`] = ` -Array [ - "Error: one.js from Terser -Error: jest-worker failed", - "Error: two.js from Terser -Error: jest-worker failed", -] -`; - -exports[`parallel option should match snapshot for errors into the "jest-worker" package: warnings 1`] = `Array []`; diff --git a/test/__snapshots__/parallel-option-failure.test.js.snap.webpack5 b/test/__snapshots__/parallel-option-failure.test.js.snap.webpack5 deleted file mode 100644 index 59a76d41..00000000 --- a/test/__snapshots__/parallel-option-failure.test.js.snap.webpack5 +++ /dev/null @@ -1,12 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`parallel option should match snapshot for errors into the "jest-worker" package: errors 1`] = ` -Array [ - "Error: one.js from Terser -Error: jest-worker failed", - "Error: two.js from Terser -Error: jest-worker failed", -] -`; - -exports[`parallel option should match snapshot for errors into the "jest-worker" package: warnings 1`] = `Array []`; diff --git a/test/fixtures/empty.js b/test/fixtures/empty.js new file mode 100644 index 00000000..e69de29b diff --git a/test/helpers/BrokenCodePlugin.js b/test/helpers/BrokenCodePlugin.js new file mode 100644 index 00000000..231b3ba9 --- /dev/null +++ b/test/helpers/BrokenCodePlugin.js @@ -0,0 +1,16 @@ +import { RawSource } from 'webpack-sources'; + +export default class BrokenCodePlugin { + apply(compiler) { + const plugin = { name: this.constructor.name }; + + compiler.hooks.compilation.tap(plugin, (compilation) => { + compilation.hooks.additionalChunkAssets.tap(plugin, () => { + compilation.additionalChunkAssets.push('broken.js'); + + // eslint-disable-next-line no-param-reassign + compilation.assets['broken.js'] = new RawSource('`Broken==='); + }); + }); + } +} diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index 7f14a00d..6d4b625d 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -14,6 +14,7 @@ export default function getCompiler(options = {}) { entry: path.resolve(__dirname, '../fixtures/entry.js'), optimization: { minimize: false, + noEmitOnErrors: false, }, output: { pathinfo: false, diff --git a/test/helpers/index.js b/test/helpers/index.js index e7c7bdd3..ccddbb17 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -1,3 +1,4 @@ +import BrokenCodePlugin from './BrokenCodePlugin'; import compile from './compile'; import countPlugins from './countPlugins'; import execute from './execute'; @@ -11,6 +12,7 @@ import normalizeErrors from './normalizeErrors'; import removeCache from './removeCache'; export { + BrokenCodePlugin, compile, countPlugins, execute, diff --git a/test/parallel-option-failure.test.js b/test/parallel-option-failure.test.js deleted file mode 100644 index 0dcc6532..00000000 --- a/test/parallel-option-failure.test.js +++ /dev/null @@ -1,117 +0,0 @@ -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()), - getStderr: jest.fn(() => { - console.warn('jest-worker warning from getStderr'); - }), - }; - }); -}); - -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 warning = jest.spyOn(console, 'warn'); - - const stats = await compile(compiler); - - expect(warning).toHaveBeenLastCalledWith( - 'jest-worker warning from getStderr' - ); - - expect(Worker).toHaveBeenCalledTimes(1); - expect(Worker).toHaveBeenLastCalledWith(workerPath, { - numWorkers: Math.min(2, os.cpus().length - 1), - }); - 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 warning = jest.spyOn(console, 'warn'); - - const stats = await compile(compiler); - - expect(warning).toHaveBeenLastCalledWith( - 'jest-worker warning from getStderr' - ); - - expect(Worker).toHaveBeenCalledTimes(1); - expect(Worker).toHaveBeenLastCalledWith(workerPath, { - numWorkers: Math.min(2, os.cpus().length - 1), - }); - expect(workerTransform).toHaveBeenCalledTimes( - Object.keys(stats.compilation.assets).length - ); - expect(workerEnd).toHaveBeenCalledTimes(1); - - expect(getErrors(stats)).toMatchSnapshot('errors'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - }); - } -}); diff --git a/test/parallel-option.test.js b/test/parallel-option.test.js index e26343d7..23aafcaf 100644 --- a/test/parallel-option.test.js +++ b/test/parallel-option.test.js @@ -37,6 +37,7 @@ jest.mock('jest-worker', () => { )), end: (workerEnd = jest.fn()), getStderr: jest.fn(), + getStdout: jest.fn(), }; }); });