Skip to content

Commit d268e13

Browse files
anshumanvevilebottnawirishabh3112
authored
fix: json flag, enable tests (#1460)
* fix: json flag, enable tests * fix: json flag, enable tests * fix: json flag, enable tests Co-authored-by: Evilebot Tnawi <evilebottnawi@users.noreply.github.com> Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
1 parent e75b3e3 commit d268e13

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

packages/webpack-cli/lib/groups/StatsGroup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class StatsGroup extends GroupHelper {
2727
this.opts.options.stats = this.args.stats;
2828
}
2929
}
30+
if (this.args.json) {
31+
this.opts.outputOptions.json = true;
32+
}
3033
}
3134

3235
run() {

test/json/json.test.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
'use strict';
2-
const { join } = require('path');
32
const { run } = require('../utils/test-utils');
4-
const webpack = require('webpack');
53

64
describe('json flag', () => {
7-
it.skip('should match the snapshot of --json command', async () => {
8-
const { stdout } = run(__dirname, [__dirname, '--json']);
9-
const jsonstdout = JSON.parse(stdout);
10-
const compiler = await webpack({
11-
entry: './index.js',
12-
output: {
13-
filename: 'main.js',
14-
path: join(__dirname, 'bin'),
15-
},
16-
});
17-
compiler.run((err, stats) => {
18-
expect(err).toBeFalsy();
19-
const webpackStats = stats.toJson({ json: true });
20-
expect(jsonstdout).toEqual(webpackStats);
21-
});
5+
it('should return valid json', () => {
6+
const { stdout } = run(__dirname, ['--json']);
7+
8+
// helper function to check if JSON is valid
9+
const parseJson = () => {
10+
return JSON.parse(stdout);
11+
};
12+
// check the JSON is valid.
13+
expect(parseJson).not.toThrow();
2214
});
2315
});

0 commit comments

Comments
 (0)