1- import { exec , spawn } from 'child_process'
1+ import { spawn } from 'child_process'
22import { resolve } from 'path'
3- import { promisify } from 'util'
4- import { Utils , rp } from '../utils'
5-
6- const execify = promisify ( exec )
7- const rootDir = resolve ( __dirname , '..' , 'fixtures/basic' )
3+ import { getPort , Utils , rp } from '../utils'
84
95let port
6+ const rootDir = resolve ( __dirname , '..' , 'fixtures/cli' )
7+
108const url = route => 'http://localhost:' + port + route
119
1210const nuxtBin = resolve ( __dirname , '..' , '..' , 'bin' , 'nuxt' )
1311
14- describe . skip ( 'cli' , ( ) => {
15- test ( 'nuxt build' , async ( ) => {
16- const { stdout } = await execify ( `node ${ nuxtBin } build ${ rootDir } ` )
17-
18- expect ( stdout . includes ( 'Compiled successfully' ) ) . toBe ( true )
19- } )
20-
21- test ( 'nuxt build -> error config' , async ( ) => {
22- await expect ( execify ( `node ${ nuxtBin } build ${ rootDir } -c config.js` ) ) . rejects . toMatchObject ( {
23- stderr : expect . stringContaining ( 'Could not load config file' )
24- } )
25- } )
26-
12+ describe ( 'cli' , ( ) => {
2713 test ( 'nuxt start' , async ( ) => {
2814 let stdout = ''
29- // let stderr = ''
3015 let error
3116 let exitCode
3217
3318 const env = process . env
34- env . PORT = port
19+ env . PORT = port = await getPort ( )
3520
36- const nuxtStart = spawn ( 'node' , [ nuxtBin , 'start' , rootDir ] , { env : env } )
21+ const nuxtStart = spawn ( 'node' , [ nuxtBin , 'start' , rootDir ] , { env } )
3722
3823 nuxtStart . stdout . on ( 'data' , data => {
3924 stdout += data
4025 } )
4126
42- nuxtStart . stderr . on ( 'data' , data => {
43- // stderr += data
44- } )
45-
4627 nuxtStart . on ( 'error' , err => {
4728 error = err
4829 } )
@@ -51,48 +32,32 @@ describe.skip('cli', () => {
5132 exitCode = code
5233 } )
5334
54- // Give the process max 20s to start
55- let iterator = 0
56- while ( ! stdout . includes ( 'OPEN' ) && iterator < 80 ) {
57- await Utils . waitFor ( 250 )
58- iterator ++
59- }
35+ // Wait max 20s for the starting
36+ let timeout = await Utils . waitUntil ( ( ) => stdout . includes ( 'Listening on' ) )
6037
61- if ( iterator === 80 ) {
62- test . log ( 'WARN: server failed to start successfully in 20 seconds')
38+ if ( timeout === true ) {
39+ error = ' server failed to start successfully in 20 seconds'
6340 }
6441
6542 expect ( error ) . toBe ( undefined )
66- expect ( stdout . includes ( 'OPEN ' ) ) . toBe ( true )
43+ expect ( stdout . includes ( 'Listening on ' ) ) . toBe ( true )
6744
68- const html = await rp ( url ( '/users/1 ' ) )
69- expect ( html . includes ( '<h1>User: 1</h1 >') ) . toBe ( true )
45+ const html = await rp ( url ( '/' ) )
46+ expect ( html ) . toMatch ( ( '<div>CLI Test</div >') )
7047
7148 nuxtStart . kill ( )
7249
7350 // Wait max 10s for the process to be killed
74- iterator = 0
75- // eslint-disable-next-line no-unmodified-loop-condition
76- while ( exitCode === undefined && iterator < 40 ) {
77- await Utils . waitFor ( 250 )
78- iterator ++
79- }
51+ timeout = await Utils . waitUntil ( ( ) => exitCode !== undefined , 10 )
8052
81- if ( iterator >= 40 ) {
82- // eslint-disable-line no-console
83- test . log (
84- `WARN: we were unable to automatically kill the child process with pid: ${
53+ if ( timeout === true ) {
54+ console . warn ( // eslint-disable-line no-console
55+ `we were unable to automatically kill the child process with pid: ${
8556 nuxtStart . pid
8657 } `
8758 )
8859 }
8960
9061 expect ( exitCode ) . toBe ( null )
9162 } )
92-
93- test ( 'nuxt generate' , async ( ) => {
94- const { stdout } = await execify ( `node ${ nuxtBin } generate ${ rootDir } ` )
95-
96- expect ( stdout . includes ( 'vue-ssr-client-manifest.json' ) ) . toBe ( true )
97- } )
9863} )
0 commit comments