-
-
Notifications
You must be signed in to change notification settings - Fork 666
Expand file tree
/
Copy pathoutput-flags.test.js
More file actions
162 lines (138 loc) · 7.82 KB
/
output-flags.test.js
File metadata and controls
162 lines (138 loc) · 7.82 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'use strict';
const { run, hyphenToUpperCase } = require('../utils/test-utils');
const { flagsFromCore } = require('../../packages/webpack-cli/lib/utils/cli-flags');
const outputFlags = flagsFromCore.filter(({ name }) => name.startsWith('output-'));
describe('output config related flag', () => {
outputFlags.forEach((flag) => {
// extract property name from flag name
let property = flag.name.split('output-')[1];
if (property.includes('environment-')) {
property = property.split('environment-')[1];
}
const propName = hyphenToUpperCase(property);
if (flag.type === Boolean && !flag.name.includes('output-library')) {
it(`should config --${flag.name} correctly`, () => {
let { stderr, stdout } = run(__dirname, [`--${flag.name}`]);
if (flag.name === 'output-module') {
//'output.module: true' is only allowed when 'experiments.outputModule' is enabled
stdout = run(__dirname, [`--${flag.name}`, '--experiments-output-module']).stdout;
expect(stdout).toContain('module: true');
} else if (flag.name.includes('-reset')) {
const option = propName.split('Reset')[0];
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${option}: []`);
} else {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: true`);
}
});
it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);
if (flag.name.includes('loading-types-reset')) {
expect(stderr).toBeFalsy();
if (flag.name === 'output-enabled-wasm-loading-types-reset') {
expect(stdout).toContain(`enabledWasmLoadingTypes: [ 'fetch' ]`);
} else {
expect(stdout).toContain(`enabledChunkLoadingTypes: [ 'jsonp', 'import-scripts' ]`);
}
} else if (flag.name.includes('-reset')) {
const option = propName.split('Reset')[0];
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${option}: []`);
} else {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: false`);
}
});
}
if (flag.type === Number) {
it(`should config --${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--${flag.name}`, '10']);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: 10`);
});
}
if (flag.type === String && !flag.name.includes('output-library')) {
it(`should config --${flag.name} correctly`, () => {
let { stderr, stdout } = run(__dirname, [`--${flag.name}`, 'test']);
if (flag.name === 'output-cross-origin-loading') {
stdout = run(__dirname, [`--${flag.name}`, 'anonymous']).stdout;
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: 'anonymous'`);
} else if (flag.name === 'output-chunk-format') {
stdout = run(__dirname, [`--${flag.name}`, 'commonjs']).stdout;
expect(stdout).toContain(`${propName}: 'commonjs'`);
} else if (flag.name === 'output-enabled-library-types') {
stdout = run(__dirname, [`--${flag.name}`, 'global']).stdout;
expect(stdout).toContain(`${propName}: [ 'global' ]`);
} else if (flag.name === 'output-chunk-loading') {
stdout = run(__dirname, [`--${flag.name}`, 'jsonp']).stdout;
expect(stdout).toContain(`${propName}: 'jsonp'`);
} else if (flag.name === 'output-enabled-chunk-loading-types' || flag.name === 'output-enabled-wasm-loading-types') {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;
expect(stdout).toContain(`${propName}: [ 'async-node' ]`);
} else if (flag.name === 'output-enabled-library-type') {
stdout = run(__dirname, [`--${flag.name}`, 'amd']).stdout;
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: 'amd'`);
} else if (flag.name === 'output-hash-function') {
stdout = run(__dirname, [`--${flag.name}`, 'sha256']).stdout;
stderr = run(__dirname, [`--${flag.name}`, 'sha256']).stderr;
expect(stderr).toBeFalsy();
expect(stdout).toContain(`hashFunction: 'sha256'`);
} else if (flag.name === 'output-script-type') {
stdout = run(__dirname, [`--${flag.name}`, 'module']).stdout;
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: 'module'`);
} else if (flag.name === 'output-enabled-library-types') {
stdout = run(__dirname, [`--${flag.name}`, 'var']).stdout;
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: [ 'var' ]`);
} else if (flag.name === 'output-path') {
expect(stdout).toContain('test');
} else if (flag.name === 'output-worker-chunk-loading') {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;
expect(stdout).toContain(`${propName}: 'async-node'`);
} else if (flag.name === 'output-worker-chunk-loading') {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;
expect(stdout).toContain(`${propName}: 'async-node'`);
} else if (flag.name === 'output-chunk-format') {
stdout = run(__dirname, [`--${flag.name}`, 'commonjs']).stdout;
expect(stdout).toContain(`${propName}: 'commonjs'`);
} else if (flag.name.includes('wasm')) {
stdout = run(__dirname, [`--${flag.name}`, 'async-node']).stdout;
expect(stdout).toContain(`${propName}: 'async-node'`);
} else {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: 'test'`);
}
});
}
if (flag.name.includes('output-library')) {
it(`should config name, type and export correctly`, () => {
const { stderr, stdout } = run(__dirname, [
'--output-library-name',
'myLibrary',
'--output-library-type',
'var',
'--output-library-export',
'myExport',
'--output-library-auxiliary-comment',
'comment',
'--output-library-umd-named-define',
]);
expect(stderr).toBeFalsy();
expect(stdout).toContain('myLibrary');
expect(stdout).toContain(`type: 'var'`);
expect(stdout).toContain('export: [Array]');
expect(stdout).toContain(`auxiliaryComment: 'comment'`);
expect(stdout).toContain('umdNamedDefine: true');
});
it('should be succesful with --output-library-reset correctly', () => {
const { stderr, stdout } = run(__dirname, ['--output-library-reset']);
expect(stderr).toBeFalsy();
expect(stdout).toContain('name: []');
});
}
});
});