From 2e24cd18441e5705bb9332cb6494ba00dc2712cb Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Tue, 14 Apr 2020 12:02:57 +0530 Subject: [PATCH 1/3] fix: json flag, enable tests --- packages/webpack-cli/lib/groups/StatsGroup.js | 3 ++ test/json/json.test.js | 49 ++++++++++++------- 2 files changed, 35 insertions(+), 17 deletions(-) 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..cfe3c1a06a4 100644 --- a/test/json/json.test.js +++ b/test/json/json.test.js @@ -1,23 +1,38 @@ '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 JSON is valid + const parseJson = () => { + return JSON.parse(stdout); + }; + const jsonOutput = parseJson(); + // check the JSON is valid. + expect(parseJson).not.toThrow(); + + // JSON return the correct keys + expect(Object.keys(jsonOutput)).toEqual([ + 'errors', + 'warnings', + 'version', + 'hash', + 'time', + 'builtAt', + 'publicPath', + 'outputPath', + 'assetsByChunkName', + 'assets', + 'filteredAssets', + 'entrypoints', + 'namedChunkGroups', + 'chunks', + 'modules', + 'filteredModules', + 'logging', + 'children', + ]); }); }); From c93774dd4080f64668c6e92752f6e0cfc6eb57ab Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Tue, 14 Apr 2020 12:05:51 +0530 Subject: [PATCH 2/3] fix: json flag, enable tests --- test/json/json.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/json/json.test.js b/test/json/json.test.js index cfe3c1a06a4..fd34a5112cb 100644 --- a/test/json/json.test.js +++ b/test/json/json.test.js @@ -5,14 +5,15 @@ describe('json flag', () => { it('should return valid json', () => { const { stdout } = run(__dirname, ['--json']); - // helper function to check JSON is valid + // helper function to check if JSON is valid const parseJson = () => { return JSON.parse(stdout); }; - const jsonOutput = parseJson(); // check the JSON is valid. expect(parseJson).not.toThrow(); + const jsonOutput = parseJson(); + // JSON return the correct keys expect(Object.keys(jsonOutput)).toEqual([ 'errors', From a6c0818f2d210a5015cc459119f94c7f7d167e1e Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Tue, 14 Apr 2020 12:27:49 +0530 Subject: [PATCH 3/3] fix: json flag, enable tests --- test/json/json.test.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/test/json/json.test.js b/test/json/json.test.js index fd34a5112cb..d4c8c84d710 100644 --- a/test/json/json.test.js +++ b/test/json/json.test.js @@ -11,29 +11,5 @@ describe('json flag', () => { }; // check the JSON is valid. expect(parseJson).not.toThrow(); - - const jsonOutput = parseJson(); - - // JSON return the correct keys - expect(Object.keys(jsonOutput)).toEqual([ - 'errors', - 'warnings', - 'version', - 'hash', - 'time', - 'builtAt', - 'publicPath', - 'outputPath', - 'assetsByChunkName', - 'assets', - 'filteredAssets', - 'entrypoints', - 'namedChunkGroups', - 'chunks', - 'modules', - 'filteredModules', - 'logging', - 'children', - ]); }); });