-
-
Notifications
You must be signed in to change notification settings - Fork 591
/
target-flag.test.js
94 lines (73 loc) · 3.61 KB
/
target-flag.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
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
'use strict';
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`, () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--target', `${val}`]);
expect(exitCode).toBe(0);
expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
if (isWebpack5) {
expect(stdout).toContain(`target: [ '${val}' ]`);
} else {
expect(stdout).toContain(`target: '${val}'`);
}
});
it(`should accept ${val} with -t alias`, () => {
const { exitCode, stderr, stdout } = run(__dirname, ['-t', `${val}`]);
expect(exitCode).toBe(0);
expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
if (isWebpack5) {
expect(stdout).toContain(`target: [ '${val}' ]`);
} else {
expect(stdout).toContain(`target: '${val}'`);
}
});
});
it(`should throw error with invalid value for --target`, () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--target', 'invalid']);
expect(exitCode).toBe(2);
if (isWebpack5) {
expect(stderr).toContain(`Unknown target 'invalid'`);
} else {
expect(stderr).toContain('Invalid configuration object');
}
expect(stdout).toBeFalsy();
});
if (isWebpack5) {
it('should allow multiple targets', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--target', 'node', '--target', 'async-node']);
expect(exitCode).toBe(0);
expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stdout).toContain(`target: [ 'node', 'async-node' ]`);
});
it('should throw an error for invalid target in multiple syntax', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--target', 'node', '--target', 'invalid']);
expect(exitCode).toBe(2);
expect(stderr).toContain(`Error: Unknown target 'invalid'`);
expect(stdout).toBeFalsy();
});
it('should throw an error for incompatible multiple targets', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--target', 'node', '--target', 'web']);
expect(exitCode).toBe(2);
expect(stderr).toContain('Error: Universal Chunk Loading is not implemented yet');
expect(stdout).toBeFalsy();
});
it('should reset target from node to async-node with --target-reset', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--target-reset', '--target', 'async-node']);
expect(exitCode).toBe(0);
expect(stderr).toContain('Compilation starting...');
expect(stderr).toContain('Compilation finished');
expect(stdout).toContain(`target: [ 'async-node' ]`);
});
it('should throw error if target is an empty array', () => {
const { exitCode, stderr, stdout } = run(__dirname, ['--target-reset']);
expect(exitCode).toBe(2);
expect(stderr).toContain('Invalid configuration object');
expect(stdout).toBeFalsy();
});
}
});