-
-
Notifications
You must be signed in to change notification settings - Fork 667
Expand file tree
/
Copy pathtarget-flag.test.js
More file actions
43 lines (37 loc) · 1.58 KB
/
target-flag.test.js
File metadata and controls
43 lines (37 loc) · 1.58 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
'use strict';
const { stat } = require('fs');
const { resolve } = require('path');
const { run, isWebpack5 } = require('../../utils/test-utils');
const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload'];
describe('--target flag', () => {
targetValues.forEach((val) => {
it(`should accept ${val} with --target flag`, (done) => {
const { stdout, stderr } = run(__dirname, ['--target', `${val}`]);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`target: '${val}'`);
stat(resolve(__dirname, 'bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});
it(`should accept ${val} with -t alias`, (done) => {
const { stdout, stderr } = run(__dirname, ['-t', `${val}`]);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`target: '${val}'`);
stat(resolve(__dirname, 'bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
});
});
it(`should throw error with invalid value for --target`, () => {
const { stderr } = run(__dirname, ['--target', 'invalid']);
if (isWebpack5) {
expect(stderr).toContain(`Error: Unknown target 'invalid'`);
} else {
expect(stderr).toContain('Invalid configuration object');
}
});
});