@@ -64,25 +64,23 @@ We add our test file `test/index.test.js`:
64
64
65
65
``` js
66
66
import test from ' ava'
67
- import Nuxt from ' nuxt'
67
+ import { Nuxt , Builder } from ' nuxt'
68
68
import { resolve } from ' path'
69
69
70
- // We keep the nuxt and server instance
71
- // So we can close them at the end of the test
70
+ // We keep a reference to nuxt so we can close
71
+ // the server at the end of the test
72
72
let nuxt = null
73
- let server = null
74
73
75
- // Init Nuxt.js and create a server listening on localhost:4000
74
+ // Init Nuxt.js and start listening on localhost:4000
76
75
test .before (' Init Nuxt.js' , async t => {
77
76
const rootDir = resolve (__dirname , ' ..' )
78
77
let config = {}
79
78
try { config = require (resolve (rootDir, ' nuxt.config.js' )) } catch (e) {}
80
79
config .rootDir = rootDir // project folder
81
80
config .dev = false // production build
82
81
nuxt = new Nuxt (config)
83
- await nuxt .build ()
84
- server = new nuxt.Server (nuxt)
85
- server .listen (4000 , ' localhost' )
82
+ await new Builder (nuxt).build ()
83
+ nuxt .listen (4000 , ' localhost' )
86
84
})
87
85
88
86
// Example of testing only generated html
@@ -102,9 +100,8 @@ test('Route / exits and render HTML with CSS applied', async t => {
102
100
t .is (window .getComputedStyle (element).color , ' red' )
103
101
})
104
102
105
- // Close server and ask nuxt to stop listening to file changes
106
- test .after (' Closing server and nuxt.js' , t => {
107
- server .close ()
103
+ // Close the nuxt server
104
+ test .after (' Closing server' , t => {
108
105
nuxt .close ()
109
106
})
110
107
```
0 commit comments