|
2 | 2 | const { stat } = require('fs'); |
3 | 3 | const { resolve } = require('path'); |
4 | 4 | const { run } = require('../utils/test-utils'); |
5 | | -const parseNodeArgs = require('../../packages/webpack-cli/lib/utils/parse-node-args'); |
6 | 5 |
|
7 | | -describe.skip('node flags', () => { |
8 | | - it('parseNodeArgs helper must work correctly', () => { |
9 | | - [ |
10 | | - { |
11 | | - rawArgs: ['--foo', '--bar', '--baz=quux'], |
12 | | - expectedCliArgs: ['--foo', '--bar', '--baz=quux'], |
13 | | - expectedNodeArgs: [], |
14 | | - }, |
15 | | - { |
16 | | - rawArgs: ['--foo', '--bar', '--baz=quux', '--node-args', '--name1=value1', '--node-args', '--name2 value2'], |
17 | | - expectedCliArgs: ['--foo', '--bar', '--baz=quux'], |
18 | | - expectedNodeArgs: ['--name1=value1', '--name2', 'value2'], |
19 | | - }, |
20 | | - { |
21 | | - rawArgs: [ |
22 | | - '--node-args', |
23 | | - '--name1=value1', |
24 | | - '--node-args', |
25 | | - '--name2="value2"', |
26 | | - '--node-args', |
27 | | - '--name3 value3', |
28 | | - '--node-args', |
29 | | - '-k v', |
30 | | - ], |
31 | | - expectedCliArgs: [], |
32 | | - expectedNodeArgs: ['--name1=value1', '--name2="value2"', '--name3', 'value3', '-k', 'v'], |
33 | | - }, |
34 | | - ].map(({ rawArgs, expectedNodeArgs, expectedCliArgs }) => { |
35 | | - const { nodeArgs, cliArgs } = parseNodeArgs(rawArgs); |
36 | | - expect(nodeArgs).toEqual(expectedNodeArgs); |
37 | | - expect(cliArgs).toEqual(expectedCliArgs); |
38 | | - }); |
39 | | - }); |
40 | | - |
41 | | - it('is able to pass the options flags to node js', (done) => { |
42 | | - const { stdout } = run( |
43 | | - __dirname, |
44 | | - [ |
45 | | - '--node-args', |
46 | | - `--require=${resolve(__dirname, 'bootstrap.js')}`, |
47 | | - '--node-args', |
48 | | - `-r ${resolve(__dirname, 'bootstrap2.js')}`, |
49 | | - '--output', |
50 | | - './bin/[name].bundle.js', |
51 | | - ], |
52 | | - false, |
53 | | - ); |
| 6 | +describe('node flags', () => { |
| 7 | + it('is able to pass the options flags to node js', async (done) => { |
| 8 | + const { stdout, stderr } = await run(__dirname, ['--output', './bin/[name].bundle.js'], false, [ |
| 9 | + `--require=${resolve(__dirname, 'bootstrap.js')}`, |
| 10 | + `--require=${resolve(__dirname, 'bootstrap2.js')}`, |
| 11 | + ]); |
54 | 12 | expect(stdout).toContain('---from bootstrap.js---'); |
55 | 13 | expect(stdout).toContain('---from bootstrap2.js---'); |
| 14 | + expect(stderr).toBeFalsy(); |
56 | 15 | stat(resolve(__dirname, './bin/main.bundle.js'), (err, stats) => { |
57 | 16 | expect(err).toBe(null); |
58 | 17 | expect(stats.isFile()).toBe(true); |
59 | 18 | done(); |
60 | 19 | }); |
61 | 20 | }); |
62 | 21 |
|
63 | | - it('throws an error on supplying unknown flags', () => { |
64 | | - const { stderr } = run(__dirname, ['--node-args', '--unknown']); |
| 22 | + it('throws an error on supplying unknown flags', async () => { |
| 23 | + const { stderr } = await run(__dirname, [], false, ['--unknown']); |
65 | 24 | expect(stderr).toContain('bad option'); |
66 | 25 | }); |
67 | 26 |
|
68 | | - it('throws an error if no values were supplied with --max-old-space-size', () => { |
69 | | - const { stderr, stdout } = run(__dirname, ['--node-args', '--max-old-space-size']); |
| 27 | + it('throws an error if no values were supplied with --max-old-space-size', async () => { |
| 28 | + const { stderr, stdout } = await run(__dirname, [], false, ['--max-old-space-size']); |
70 | 29 | expect(stderr).toContain('missing value for flag --max-old-space-size'); |
71 | 30 | expect(stdout).toBeFalsy(); |
72 | 31 | }); |
73 | 32 |
|
74 | | - it('throws an error if an illegal value was supplied with --max-old-space-size', () => { |
75 | | - const { stderr, stdout } = run(__dirname, ['--node-args', '--max-old-space-size=1024a']); |
76 | | - expect(stderr).toContain('illegal value for flag --max-old-space-size'); |
| 33 | + it('throws an error if an illegal value was supplied with --max-old-space-size', async () => { |
| 34 | + const { stderr, stdout } = await run(__dirname, [], true, ['--max_old_space_size=1024a']); |
| 35 | + expect(stderr).toContain('Error: illegal value for flag --max_old_space_size=1024a of type size_t'); |
77 | 36 | expect(stdout).toBeFalsy(); |
78 | 37 | }); |
79 | 38 | }); |
0 commit comments