Skip to content

Commit 1eac0f9

Browse files
test: fix
1 parent 9e96927 commit 1eac0f9

17 files changed

Lines changed: 494 additions & 116 deletions

test/cli/allowedHosts-option.test.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
'use strict';
22

33
const { testBin } = require('../helpers/test-bin');
4+
const port = require('../ports-map')['cli-allowed-hosts'];
45

56
describe('"allowedHosts" CLI option', () => {
67
it('should work using "--allowed-hosts auto"', async () => {
7-
const { exitCode } = await testBin(['--allowed-hosts', 'auto']);
8+
const { exitCode } = await testBin([
9+
'--allowed-hosts',
10+
'auto',
11+
'--port',
12+
port,
13+
]);
814

915
expect(exitCode).toEqual(0);
1016
});
1117

1218
it('should work using "--allowed-hosts all"', async () => {
13-
const { exitCode } = await testBin(['--allowed-hosts', 'all']);
19+
const { exitCode } = await testBin([
20+
'--allowed-hosts',
21+
'all',
22+
'--port',
23+
port,
24+
]);
1425

1526
expect(exitCode).toEqual(0);
1627
});
1728

1829
it('should work using "--allowed-hosts testhouse.com"', async () => {
19-
const { exitCode } = await testBin(['--allowed-hosts', 'testhouse.com']);
30+
const { exitCode } = await testBin([
31+
'--allowed-hosts',
32+
'testhouse.com',
33+
'--port',
34+
port,
35+
]);
2036

2137
expect(exitCode).toEqual(0);
2238
});
@@ -27,6 +43,8 @@ describe('"allowedHosts" CLI option', () => {
2743
'testhost.com',
2844
'--allowed-hosts',
2945
'testhost1.com',
46+
'--port',
47+
port,
3048
]);
3149

3250
expect(exitCode).toEqual(0);

test/cli/basic.test.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ describe('basic', () => {
6868
path.resolve(
6969
__dirname,
7070
'../fixtures/promise-config/webpack.config.js'
71-
)
71+
),
72+
'--port',
73+
port
7274
);
7375
expect(exitCode).toEqual(0);
7476
} catch (err) {
@@ -86,7 +88,7 @@ describe('basic', () => {
8688
__dirname,
8789
'../../examples/cli/web-socket-url'
8890
);
89-
const cp = execa('node', [cliPath], { cwd: examplePath });
91+
const cp = execa('node', [cliPath, '--port', port], { cwd: examplePath });
9092

9193
cp.stdout.on('data', (data) => {
9294
const bits = data.toString();
@@ -109,7 +111,7 @@ describe('basic', () => {
109111
'../../bin/webpack-dev-server.js'
110112
);
111113
const cwd = path.resolve(__dirname, '../fixtures/cli');
112-
const cp = execa('node', [cliPath], { cwd });
114+
const cp = execa('node', [cliPath, '--port', port], { cwd });
113115

114116
let killed = false;
115117

@@ -137,9 +139,13 @@ describe('basic', () => {
137139
__dirname,
138140
'../../examples/cli/web-socket-url'
139141
);
140-
const cp = execa('node', [cliPath, '--watch-options-stdin'], {
141-
cwd: examplePath,
142-
});
142+
const cp = execa(
143+
'node',
144+
[cliPath, '--watch-options-stdin', '--port', port],
145+
{
146+
cwd: examplePath,
147+
}
148+
);
143149

144150
cp.stdout.on('data', (data) => {
145151
const bits = data.toString();
@@ -163,7 +169,11 @@ describe('basic', () => {
163169
'../../bin/webpack-dev-server.js'
164170
);
165171
const cwd = path.resolve(__dirname, '../fixtures/cli');
166-
const cp = execa('node', [cliPath, '--watch-options-stdin'], { cwd });
172+
const cp = execa(
173+
'node',
174+
[cliPath, '--watch-options-stdin', '--port', port],
175+
{ cwd }
176+
);
167177

168178
let killed = false;
169179

@@ -186,7 +196,9 @@ describe('basic', () => {
186196
it('should add dev server entry points to a single entry point', async () => {
187197
const { exitCode, stdout } = await testBin(
188198
null,
189-
'./test/fixtures/dev-server/default-config.js'
199+
'./test/fixtures/dev-server/default-config.js',
200+
'--port',
201+
port
190202
);
191203

192204
expect(exitCode).toEqual(0);
@@ -198,7 +210,9 @@ describe('basic', () => {
198210
async () => {
199211
const { exitCode, stdout } = await testBin(
200212
'--stats=verbose',
201-
'./test/fixtures/dev-server/multi-entry.js'
213+
'./test/fixtures/dev-server/multi-entry.js',
214+
'--port',
215+
port
202216
);
203217

204218
expect(exitCode).toEqual(0);
@@ -212,7 +226,9 @@ describe('basic', () => {
212226
async () => {
213227
const { exitCode, stdout } = await testBin(
214228
null,
215-
'./test/fixtures/dev-server/empty-entry.js'
229+
'./test/fixtures/dev-server/empty-entry.js',
230+
'--port',
231+
port
216232
);
217233

218234
expect(exitCode).toEqual(0);
@@ -223,7 +239,9 @@ describe('basic', () => {
223239
webpack5Test('should supports entry as descriptor', async () => {
224240
const { exitCode, stdout } = await testBin(
225241
'--stats=detailed',
226-
'./test/fixtures/entry-as-descriptor/webpack.config'
242+
'./test/fixtures/entry-as-descriptor/webpack.config',
243+
'--port',
244+
port
227245
);
228246

229247
expect(exitCode).toEqual(0);
@@ -233,7 +251,9 @@ describe('basic', () => {
233251
it('should only prepends dev server entry points to "web" target', async () => {
234252
const { exitCode, stdout } = await testBin(
235253
'--target web',
236-
'./test/fixtures/dev-server/default-config.js'
254+
'./test/fixtures/dev-server/default-config.js',
255+
'--port',
256+
port
237257
);
238258

239259
expect(exitCode).toEqual(0);
@@ -244,7 +264,9 @@ describe('basic', () => {
244264
it('should not prepend dev server entry points to "node" target', async () => {
245265
const { exitCode, stdout } = await testBin(
246266
'--target node',
247-
'./test/fixtures/dev-server/default-config.js'
267+
'./test/fixtures/dev-server/default-config.js',
268+
'--port',
269+
port
248270
);
249271

250272
expect(exitCode).toEqual(0);
@@ -255,7 +277,9 @@ describe('basic', () => {
255277
it('should prepends the hot runtime to "node" target as well', async () => {
256278
const { exitCode, stdout } = await testBin(
257279
'--target node --hot',
258-
'./test/fixtures/dev-server/default-config.js'
280+
'./test/fixtures/dev-server/default-config.js',
281+
'--port',
282+
port
259283
);
260284

261285
expect(exitCode).toEqual(0);
@@ -267,7 +291,9 @@ describe('basic', () => {
267291
async () => {
268292
const { exitCode, stdout } = await testBin(
269293
null,
270-
'./test/fixtures/dev-server/target-config.js'
294+
'./test/fixtures/dev-server/target-config.js',
295+
'--port',
296+
port
271297
);
272298

273299
expect(exitCode).toEqual(0);

test/cli/bonjour-option.test.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
'use strict';
22

33
const { testBin, normalizeStderr } = require('../helpers/test-bin');
4+
const port = require('../ports-map')['cli-bonjour'];
45

56
describe('"bonjour" CLI option', () => {
67
it('should work using "--bonjour"', async () => {
7-
const { exitCode, stderr } = await testBin(['--bonjour']);
8+
const { exitCode, stderr } = await testBin(['--bonjour', '--port', port]);
89

910
expect(exitCode).toEqual(0);
1011
expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot();
1112
});
1213

1314
it('should work using "--bonjour and --https"', async () => {
14-
const { exitCode, stderr } = await testBin(['--bonjour', '--https']);
15+
const { exitCode, stderr } = await testBin([
16+
'--bonjour',
17+
'--https',
18+
'--port',
19+
port,
20+
]);
1521

1622
expect(exitCode).toEqual(0);
1723
expect(
@@ -20,7 +26,11 @@ describe('"bonjour" CLI option', () => {
2026
});
2127

2228
it('should work using "--no-bonjour"', async () => {
23-
const { exitCode, stderr } = await testBin(['--no-bonjour']);
29+
const { exitCode, stderr } = await testBin([
30+
'--no-bonjour',
31+
'--port',
32+
port,
33+
]);
2434

2535
expect(exitCode).toEqual(0);
2636
expect(normalizeStderr(stderr, { ipv6: true })).toMatchSnapshot();

0 commit comments

Comments
 (0)