@@ -64,25 +64,23 @@ We add our test file `test/index.test.js`:
6464
6565``` js
6666import test from ' ava'
67- import Nuxt from ' nuxt'
67+ import { Nuxt , Builder } from ' nuxt'
6868import { resolve } from ' path'
6969
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
7272let nuxt = null
73- let server = null
7473
75- // Init Nuxt.js and create a server listening on localhost:4000
74+ // Init Nuxt.js and start listening on localhost:4000
7675test .before (' Init Nuxt.js' , async t => {
7776 const rootDir = resolve (__dirname , ' ..' )
7877 let config = {}
7978 try { config = require (resolve (rootDir, ' nuxt.config.js' )) } catch (e) {}
8079 config .rootDir = rootDir // project folder
8180 config .dev = false // production build
8281 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' )
8684})
8785
8886// Example of testing only generated html
@@ -102,9 +100,8 @@ test('Route / exits and render HTML with CSS applied', async t => {
102100 t .is (window .getComputedStyle (element).color , ' red' )
103101})
104102
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 => {
108105 nuxt .close ()
109106})
110107```
0 commit comments