diff --git a/src/lib/wpack.js b/src/lib/wpack.js index 6310cfc..881bfcd 100644 --- a/src/lib/wpack.js +++ b/src/lib/wpack.js @@ -62,7 +62,8 @@ const run = configs => webpack(configs, (err, stats) => { if (err) reject(new Error(`Webpack compilation error: ${err}`)); - console.log(stats.toString({ // eslint-disable-line no-console + // eslint-disable-next-line no-console + console.log(stats.toString(configs[0].stats ? configs[0].stats : { colors: true, hash: false, chunks: false, diff --git a/test/__mocks__/webpack.js b/test/__mocks__/webpack.js index d322b07..6482298 100644 --- a/test/__mocks__/webpack.js +++ b/test/__mocks__/webpack.js @@ -5,7 +5,7 @@ module.exports = (configs, callback) => { const stats = { data: configs, hasErrors: () => configs === 'statsError', - toString: () => configs, + toString: jest.fn(), }; return callback(null, stats); diff --git a/test/wpack.test.js b/test/wpack.test.js index 1225932..95e04c2 100644 --- a/test/wpack.test.js +++ b/test/wpack.test.js @@ -58,9 +58,22 @@ test('createConfigs', () => { describe('run', () => { require('webpack'); // eslint-disable-line global-require, import/no-unresolved - test('run', () => + test('run with default stats', () => wpack.run('config') - .then(stats => expect(stats.data).toBe('config'))); + .then((stats) => { + expect(stats.data).toBe('config'); + expect(stats.toString).toHaveBeenCalledWith({ + colors: true, + hash: false, + chunks: false, + version: false, + }); + })); + + test('run with custom stats', () => + wpack.run([{ name: 'config1', stats: { colors: false } }]) + .then(stats => + expect(stats.toString).toHaveBeenCalledWith({ colors: false }))); test('run with error', () => wpack.run('err')