1+ /**
2+ * @jest -environment node
3+ */
4+
15'use strict' ;
26
37const { join, resolve } = require ( 'path' ) ;
@@ -16,20 +20,6 @@ const keyPath = resolve(httpsCertificateDirectory, 'server.key');
1620const certPath = resolve ( httpsCertificateDirectory , 'server.crt' ) ;
1721
1822describe ( 'CLI' , ( ) => {
19- it ( '--progress' , ( done ) => {
20- testBin ( '--progress' )
21- . then ( ( output ) => {
22- expect ( output . code ) . toEqual ( 0 ) ;
23- expect ( output . stderr ) . toContain ( '0% compiling' ) ;
24- // should not profile
25- expect ( output . stderr ) . not . toContain (
26- 'ms after chunk modules optimization'
27- ) ;
28- done ( ) ;
29- } )
30- . catch ( done ) ;
31- } ) ;
32-
3323 it ( '--quiet' , async ( done ) => {
3424 const output = await testBin ( `--quiet --colors=false --port ${ port1 } ` ) ;
3525 expect ( output . code ) . toEqual ( 0 ) ;
@@ -42,43 +32,41 @@ describe('CLI', () => {
4232 done ( ) ;
4333 } ) ;
4434
35+ it ( '--progress' , async ( ) => {
36+ const { exitCode, stderr } = await testBin ( '--progress' ) ;
37+ expect ( exitCode ) . toEqual ( 0 ) ;
38+ expect ( stderr . includes ( '0% compiling' ) ) . toBe ( true ) ;
39+ // should not profile
40+ expect ( output . stderr ) . not . toContain (
41+ 'ms after chunk modules optimization'
42+ ) ;
43+ } ) ;
44+
4545 it ( '--progress --profile' , async ( ) => {
46- const { code , stderr } = await testBin ( '--progress --profile' ) ;
47- expect ( code ) . toEqual ( 0 ) ;
46+ const { exitCode , stderr } = await testBin ( '--progress --profile' ) ;
47+ expect ( exitCode ) . toEqual ( 0 ) ;
4848 // should profile
4949 expect ( stderr . includes ( 'after chunk modules optimization' ) ) . toBe ( true ) ;
5050 } ) ;
5151
52- it ( '--bonjour' , ( done ) => {
53- testBin ( '--bonjour' )
54- . then ( ( output ) => {
55- expect ( output . code ) . toEqual ( 0 ) ;
56- expect ( output . stdout ) . toContain ( 'Bonjour' ) ;
57- done ( ) ;
58- } )
59- . catch ( done ) ;
52+ it ( '--bonjour' , async ( ) => {
53+ const { exitCode, stdout } = await testBin ( '--bonjour' ) ;
54+ expect ( exitCode ) . toEqual ( 0 ) ;
55+ expect ( stdout . includes ( 'Bonjour' ) ) . toBe ( true ) ;
6056 } ) ;
6157
62- it ( '--https' , ( done ) => {
63- testBin ( '--https' )
64- . then ( ( output ) => {
65- expect ( output . code ) . toEqual ( 0 ) ;
66- expect ( output . stdout ) . toContain ( 'Project is running at' ) ;
67- done ( ) ;
68- } )
69- . catch ( done ) ;
58+ it ( '--https' , async ( ) => {
59+ const { exitCode, stdout } = await testBin ( '--https' ) ;
60+ expect ( exitCode ) . toEqual ( 0 ) ;
61+ expect ( stdout . includes ( 'Project is running at' ) ) . toBe ( true ) ;
7062 } ) ;
7163
7264 it ( '--https --cacert --pfx --key --cert --pfx-passphrase' , async ( ) => {
73- const { code , stdout } = await testBin (
65+ const { exitCode , stdout } = await testBin (
7466 `--https --cacert ${ caPath } --pfx ${ pfxPath } --key ${ keyPath } --cert ${ certPath } --pfx-passphrase webpack-dev-server`
75- )
76- . then ( ( output ) => {
77- expect ( output . code ) . toEqual ( 0 ) ;
78- expect ( output . stdout ) . toContain ( 'Project is running at' ) ;
79- done ( ) ;
80- } )
81- . catch ( done ) ;
67+ ) ;
68+ expect ( exitCode ) . toEqual ( 0 ) ;
69+ expect ( stdout . includes ( 'Project is running at' ) ) . toBe ( true ) ;
8270 } ) ;
8371
8472 it ( '--sockPath' , async ( ) => {
@@ -108,8 +96,8 @@ describe('CLI', () => {
10896 // The Unix socket to listen to (instead of a host).
10997 it ( '--socket' , async ( ) => {
11098 const socketPath = join ( '.' , 'webpack.sock' ) ;
111- const { code , stdout } = await testBin ( `--socket ${ socketPath } ` ) ;
112- expect ( code ) . toEqual ( 0 ) ;
99+ const { exitCode , stdout } = await testBin ( `--socket ${ socketPath } ` ) ;
100+ expect ( exitCode ) . toEqual ( 0 ) ;
113101
114102 if ( process . platform !== 'win32' ) {
115103 expect ( stdout . includes ( socketPath ) ) . toBe ( true ) ;
@@ -131,20 +119,16 @@ describe('CLI', () => {
131119 . catch ( done ) ;
132120 } ) ;
133121
134- it ( 'should accept the promise function of webpack.config.js' , ( done ) => {
135- testBin (
136- false ,
137- resolve ( __dirname , '../fixtures/promise-config/webpack.config.js' )
138- )
139- . then ( ( output ) => {
140- expect ( output . code ) . toEqual ( 0 ) ;
141- done ( ) ;
142- } )
143- . catch ( ( err ) => {
144- // for windows
145- expect ( err . stdout ) . toContain ( 'Compiled successfully.' ) ;
146- done ( ) ;
147- } ) ;
122+ it ( 'should accept the promise function of webpack.config.js' , async ( ) => {
123+ try {
124+ const { exitCode } = await testBin (
125+ false ,
126+ resolve ( __dirname , '../fixtures/promise-config/webpack.config.js' )
127+ ) ;
128+ expect ( exitCode ) . toEqual ( 0 ) ;
129+ } catch ( err ) {
130+ expect ( err . stdout . includes ( 'Compiled successfully.' ) ) . toBe ( true ) ;
131+ }
148132 } ) ;
149133
150134 // TODO: hiroppy
0 commit comments