forked from webpack/webpack-cli
/
output-named-bundles.test.js
49 lines (40 loc) · 2.18 KB
/
output-named-bundles.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
47
48
49
'use strict';
const { statSync } = require('fs');
const { resolve } = require('path');
const { run } = require('../../utils/test-utils');
describe('output flag named bundles', () => {
it('should output file given as flag instead of in configuration', () => {
const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', './binary'], false);
expect(stderr).toBeFalsy();
const stats = statSync(resolve(__dirname, './binary/a.bundle.js'));
expect(stats.isFile()).toBe(true);
});
it('should resolve the path to binary/a.bundle.js as ./binary/a.bundle.js', () => {
const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js'), '--output-path', 'binary'], false);
expect(stderr).toBeFalsy();
const stats = statSync(resolve(__dirname, './binary/a.bundle.js'));
expect(stats.isFile()).toBe(true);
});
it('should create multiple bundles with an overriding flag', () => {
const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.single.config.js'), '--output-path', './bin'], false);
expect(stderr).toBeFalsy();
let stats = statSync(resolve(__dirname, './bin/b.bundle.js'));
expect(stats.isFile()).toBe(true);
stats = statSync(resolve(__dirname, './bin/c.bundle.js'));
expect(stats.isFile()).toBe(true);
});
it('should successfully compile multiple entries', () => {
const { stderr } = run(__dirname, ['-c', resolve(__dirname, 'webpack.multiple.config.js')], false);
expect(stderr).toBeFalsy();
let stats = statSync(resolve(__dirname, './bin/b.bundle.js'));
expect(stats.isFile()).toBe(true);
stats = statSync(resolve(__dirname, './bin/c.bundle.js'));
expect(stats.isFile()).toBe(true);
});
it('should output file in bin directory using default webpack config with warning for empty output value', () => {
const { stdout, stderr, exitCode } = run(__dirname, ['--output-path'], false);
expect(stderr).toEqual("error: option '-o, --output-path <value>' argument missing");
expect(exitCode).toEqual(1);
expect(stdout).toBeFalsy();
});
});