/
info-output.test.js
46 lines (38 loc) · 1.59 KB
/
info-output.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const { red } = require('colorette');
const { runInfo } = require('../utils/test-utils');
describe('basic info usage', () => {
it('gets info without flags', () => {
const { stdout, stderr } = runInfo([], __dirname);
// stdout should include many details which will be
// unique for each computer
expect(stdout).toContain('System:');
expect(stdout).toContain('Node');
expect(stdout).toContain('npm');
expect(stdout).toContain('Yarn');
expect(stderr).toHaveLength(0);
});
it('gets info as json', () => {
const { stdout, stderr } = runInfo(['--output="json"'], __dirname);
expect(stdout).toContain('"System":');
expect(stderr).toHaveLength(0);
const parse = () => {
const output = JSON.parse(stdout);
expect(output['System']).toBeTruthy();
expect(output['Binaries']).toBeTruthy();
expect(output['System']['OS']).toBeTruthy();
expect(output['System']['CPU']).toBeTruthy();
};
expect(parse).not.toThrow();
});
it('gets info as markdown', () => {
const { stdout, stderr } = runInfo(['--output="markdown"'], __dirname);
expect(stdout).toContain('## System:');
expect(stderr).toHaveLength(0);
});
it('shows a warning if an invalid value is supplied', () => {
const { stdout, stderr } = runInfo(['--output="unknown"'], __dirname);
expect(stderr).toContain(`[webpack-cli] ${red(`"unknown" is not a valid value for output\n`)}`);
expect(stdout).toBeTruthy();
});
});