Skip to content

Commit

Permalink
fix: json flag, enable tests (#1460)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Apr 14, 2020
1 parent e75b3e3 commit d268e13
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
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();
});
});

0 comments on commit d268e13

Please sign in to comment.