Skip to content

Commit

Permalink
Take webpack stats params from config file if available (#48)
Browse files Browse the repository at this point in the history
* Take webpack stats params from config file if available (else fallback to default)
  • Loading branch information
orm-forks authored and jogold committed Feb 6, 2018
1 parent b7b4f4a commit b10ece1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/lib/wpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/__mocks__/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (configs, callback) => {
const stats = {
data: configs,
hasErrors: () => configs === 'statsError',
toString: () => configs,
toString: jest.fn(),
};

return callback(null, stats);
Expand Down
17 changes: 15 additions & 2 deletions test/wpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit b10ece1

Please sign in to comment.