diff --git a/packages/webpack-cli/lib/groups/StatsGroup.js b/packages/webpack-cli/lib/groups/StatsGroup.js index 4686bb8e8f9..36fc0e30ccd 100644 --- a/packages/webpack-cli/lib/groups/StatsGroup.js +++ b/packages/webpack-cli/lib/groups/StatsGroup.js @@ -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() { diff --git a/test/json/json.test.js b/test/json/json.test.js index e8ce94745c1..d4c8c84d710 100644 --- a/test/json/json.test.js +++ b/test/json/json.test.js @@ -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(); }); });