Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/webpack-cli/lib/groups/StatsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class StatsGroup extends GroupHelper {
this.opts.options.stats = this.args.stats;
}
}
if (this.args.json) {
this.opts.outputOptions.json = true;
}
}

run() {
Expand Down
26 changes: 9 additions & 17 deletions test/json/json.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
'use strict';
const { join } = require('path');
const { run } = require('../utils/test-utils');
const webpack = require('webpack');

describe('json flag', () => {
it.skip('should match the snapshot of --json command', async () => {
const { stdout } = run(__dirname, [__dirname, '--json']);
const jsonstdout = JSON.parse(stdout);
const compiler = await webpack({
entry: './index.js',
output: {
filename: 'main.js',
path: join(__dirname, 'bin'),
},
});
compiler.run((err, stats) => {
expect(err).toBeFalsy();
const webpackStats = stats.toJson({ json: true });
expect(jsonstdout).toEqual(webpackStats);
});
it('should return valid json', () => {
const { stdout } = run(__dirname, ['--json']);

// helper function to check if JSON is valid
const parseJson = () => {
return JSON.parse(stdout);
};
// check the JSON is valid.
expect(parseJson).not.toThrow();
});
});