3
3
/* eslint-disable
4
4
array-bracket-spacing,
5
5
*/
6
- const path = require ( 'path' ) ;
6
+ const { unlink } = require ( 'fs' ) ;
7
+ const { join, resolve } = require ( 'path' ) ;
7
8
const execa = require ( 'execa' ) ;
8
9
const runDevServer = require ( './helpers/run-webpack-dev-server' ) ;
9
10
10
- const httpsCertificateDirectory = path . join (
11
- __dirname ,
12
- 'fixtures/https-certificate'
13
- ) ;
14
- const caPath = path . join ( httpsCertificateDirectory , 'ca.pem' ) ;
15
- const pfxPath = path . join ( httpsCertificateDirectory , 'server.pfx' ) ;
16
- const keyPath = path . join ( httpsCertificateDirectory , 'server.key' ) ;
17
- const certPath = path . join ( httpsCertificateDirectory , 'server.crt' ) ;
11
+ const httpsCertificateDirectory = join ( __dirname , 'fixtures/https-certificate' ) ;
12
+ const caPath = join ( httpsCertificateDirectory , 'ca.pem' ) ;
13
+ const pfxPath = join ( httpsCertificateDirectory , 'server.pfx' ) ;
14
+ const keyPath = join ( httpsCertificateDirectory , 'server.key' ) ;
15
+ const certPath = join ( httpsCertificateDirectory , 'server.crt' ) ;
18
16
19
17
describe ( 'CLI' , ( ) => {
20
18
it ( '--progress' , ( done ) => {
21
19
runDevServer ( '--progress' )
22
20
. then ( ( output ) => {
23
21
expect ( output . code ) . toEqual ( 0 ) ;
24
- expect ( output . stderr . indexOf ( '0% compiling' ) >= 0 ) . toBe ( true ) ;
22
+ expect ( output . stderr . includes ( '0% compiling' ) ) . toBe ( true ) ;
25
23
done ( ) ;
26
24
} )
27
25
. catch ( done ) ;
@@ -31,7 +29,7 @@ describe('CLI', () => {
31
29
runDevServer ( '--bonjour' )
32
30
. then ( ( output ) => {
33
31
expect ( output . code ) . toEqual ( 0 ) ;
34
- expect ( output . stdout . indexOf ( 'Bonjour' ) >= 0 ) . toBe ( true ) ;
32
+ expect ( output . stdout . includes ( 'Bonjour' ) ) . toBe ( true ) ;
35
33
done ( ) ;
36
34
} )
37
35
. catch ( done ) ;
@@ -41,7 +39,7 @@ describe('CLI', () => {
41
39
runDevServer ( '--https' )
42
40
. then ( ( output ) => {
43
41
expect ( output . code ) . toEqual ( 0 ) ;
44
- expect ( output . stdout . indexOf ( 'Project is running at' ) >= 0 ) . toBe ( true ) ;
42
+ expect ( output . stdout . includes ( 'Project is running at' ) ) . toBe ( true ) ;
45
43
done ( ) ;
46
44
} )
47
45
. catch ( done ) ;
@@ -53,7 +51,7 @@ describe('CLI', () => {
53
51
)
54
52
. then ( ( output ) => {
55
53
expect ( output . code ) . toEqual ( 0 ) ;
56
- expect ( output . stdout . indexOf ( 'Project is running at' ) >= 0 ) . toBe ( true ) ;
54
+ expect ( output . stdout . includes ( 'Project is running at' ) ) . toBe ( true ) ;
57
55
done ( ) ;
58
56
} )
59
57
. catch ( done ) ;
@@ -82,9 +80,29 @@ describe('CLI', () => {
82
80
. catch ( done ) ;
83
81
} ) ;
84
82
83
+ // The Unix socket to listen to (instead of a host).
84
+ it ( '--socket' , ( done ) => {
85
+ const socketPath = join ( '.' , 'webpack.sock' ) ;
86
+
87
+ runDevServer ( `--socket ${ socketPath } ` )
88
+ . then ( ( output ) => {
89
+ expect ( output . code ) . toEqual ( 0 ) ;
90
+
91
+ if ( process . platform === 'win32' ) {
92
+ done ( ) ;
93
+ } else {
94
+ expect ( output . stdout . includes ( socketPath ) ) . toBe ( true ) ;
95
+ unlink ( socketPath , ( ) => {
96
+ done ( ) ;
97
+ } ) ;
98
+ }
99
+ } )
100
+ . catch ( done ) ;
101
+ } ) ;
102
+
85
103
it ( 'should exit the process when SIGINT is detected' , ( done ) => {
86
- const cliPath = path . resolve ( __dirname , '../bin/webpack-dev-server.js' ) ;
87
- const examplePath = path . resolve ( __dirname , '../examples/cli/public' ) ;
104
+ const cliPath = resolve ( __dirname , '../bin/webpack-dev-server.js' ) ;
105
+ const examplePath = resolve ( __dirname , '../examples/cli/public' ) ;
88
106
const cp = execa ( 'node' , [ cliPath ] , { cwd : examplePath } ) ;
89
107
90
108
cp . stdout . on ( 'data' , ( data ) => {
@@ -101,8 +119,8 @@ describe('CLI', () => {
101
119
} ) ;
102
120
103
121
it ( 'should exit the process when SIGINT is detected, even before the compilation is done' , ( done ) => {
104
- const cliPath = path . resolve ( __dirname , '../bin/webpack-dev-server.js' ) ;
105
- const examplePath = path . resolve ( __dirname , '../examples/cli/public' ) ;
122
+ const cliPath = resolve ( __dirname , '../bin/webpack-dev-server.js' ) ;
123
+ const examplePath = resolve ( __dirname , '../examples/cli/public' ) ;
106
124
const cp = execa ( 'node' , [ cliPath ] , { cwd : examplePath } ) ;
107
125
let killed = false ;
108
126
@@ -120,8 +138,8 @@ describe('CLI', () => {
120
138
} ) ;
121
139
122
140
it ( 'should use different random port when multiple instances are started on different processes' , ( done ) => {
123
- const cliPath = path . resolve ( __dirname , '../bin/webpack-dev-server.js' ) ;
124
- const examplePath = path . resolve ( __dirname , '../examples/cli/public' ) ;
141
+ const cliPath = resolve ( __dirname , '../bin/webpack-dev-server.js' ) ;
142
+ const examplePath = resolve ( __dirname , '../examples/cli/public' ) ;
125
143
126
144
const cp = execa ( 'node' , [ cliPath ] , { cwd : examplePath } ) ;
127
145
const cp2 = execa ( 'node' , [ cliPath ] , { cwd : examplePath } ) ;
0 commit comments