diff --git a/test/basic.dev.test.js b/test/basic.dev.test.js index 5ee3d73025..b0639decd8 100644 --- a/test/basic.dev.test.js +++ b/test/basic.dev.test.js @@ -1,7 +1,7 @@ import test from 'ava' import { resolve } from 'path' import rp from 'request-promise-native' -import { Nuxt, Server } from '../index.js' +import { Nuxt, Server, Builder } from '../index.js' const port = 4001 const url = (route) => 'http://localhost:' + port + route @@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => { dev: true } nuxt = new Nuxt(options) - await nuxt.ready() + await new Builder(nuxt).build() server = new Server(nuxt) server.listen(port, 'localhost') }) @@ -37,8 +37,7 @@ test('/_nuxt/test.hot-update.json should returns empty html', async t => { }) // Close server and ask nuxt to stop listening to file changes -test.after('Closing server and nuxt.js', t => { +test.after('Closing server and nuxt.js', async t => { server.close() - nuxt.close(() => { - }) + await nuxt.close(() => {}) }) diff --git a/test/basic.fail.generate.test.js b/test/basic.fail.generate.test.js index 340bf4d253..4a7bed3f51 100644 --- a/test/basic.fail.generate.test.js +++ b/test/basic.fail.generate.test.js @@ -1,6 +1,6 @@ import test from 'ava' import { resolve } from 'path' -import { Nuxt } from '../index.js' +import { Nuxt, Builder, Generator } from '../index.js' test('Fail with routes() which throw an error', async t => { const options = { @@ -14,7 +14,9 @@ test('Fail with routes() which throw an error', async t => { } } const nuxt = new Nuxt(options) - return nuxt.generate() + const builder = new Builder(nuxt) + const generator = new Generator(nuxt, builder) + return generator.generate() .catch((e) => { t.true(e.message === 'Not today!') }) diff --git a/test/basic.generate.test.js b/test/basic.generate.test.js index e896360ad0..b75e71a4b2 100644 --- a/test/basic.generate.test.js +++ b/test/basic.generate.test.js @@ -4,7 +4,7 @@ import http from 'http' import serveStatic from 'serve-static' import finalhandler from 'finalhandler' import rp from 'request-promise-native' -import { Nuxt } from '../index.js' +import { Nuxt, Builder, Generator } from '../index.js' const port = 4002 const url = (route) => 'http://localhost:' + port + route @@ -20,8 +20,10 @@ test.before('Init Nuxt.js', async t => { config.dev = false config.runBuild = true nuxt = new Nuxt(config) + const builder = new Builder(nuxt) + const generator = new Generator(nuxt, builder) try { - await nuxt.generate() // throw an error (of /validate route) + await generator.generate() // throw an error (of /validate route) } catch (err) { } const serve = serveStatic(resolve(__dirname, 'fixtures/basic/dist')) diff --git a/test/basic.test.js b/test/basic.test.js index 49a86d25c4..e1fa0820eb 100755 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -2,7 +2,7 @@ import test from 'ava' import { resolve } from 'path' import rp from 'request-promise-native' import stdMocks from 'std-mocks' -import { Nuxt, Server } from '../index.js' +import { Nuxt, Server, Builder } from '../index.js' const port = 4003 const url = (route) => 'http://localhost:' + port + route @@ -18,7 +18,7 @@ test.before('Init Nuxt.js', async t => { runBuild: true } nuxt = new Nuxt(options) - await nuxt.ready() + await new Builder(nuxt).build() server = new Server(nuxt) server.listen(port, 'localhost') }) diff --git a/test/children.test.js b/test/children.test.js index 3424a5e15c..6f5629df3b 100644 --- a/test/children.test.js +++ b/test/children.test.js @@ -1,6 +1,6 @@ import test from 'ava' import { resolve } from 'path' -import { Nuxt, Server } from '../index.js' +import { Nuxt, Server, Builder } from '../index.js' const port = 4004 // const url = (route) => 'http://localhost:' + port + route @@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => { runBuild: true } nuxt = new Nuxt(options) - await nuxt.ready() + await new Builder(nuxt).build() server = new Server(nuxt) server.listen(port, 'localhost') }) diff --git a/test/dynamic-routes.test.js b/test/dynamic-routes.test.js index 79618677cd..9ac8eeda2d 100644 --- a/test/dynamic-routes.test.js +++ b/test/dynamic-routes.test.js @@ -2,7 +2,7 @@ import test from 'ava' import { resolve } from 'path' import fs from 'fs' import pify from 'pify' -import { Nuxt } from '../index.js' +import { Nuxt, Builder } from '../index.js' const readFile = pify(fs.readFile) @@ -12,7 +12,7 @@ test.before('Init Nuxt.js', async t => { dev: false, runBuild: true }) - await nuxt.ready() + await new Builder(nuxt).build() }) test('Check .nuxt/router.js', t => { diff --git a/test/error.test.js b/test/error.test.js index 6f1cc7c8e3..7ed40fa136 100644 --- a/test/error.test.js +++ b/test/error.test.js @@ -1,6 +1,6 @@ import test from 'ava' import { resolve } from 'path' -import { Nuxt, Server } from '../index.js' +import { Nuxt, Server, Builder } from '../index.js' const port = 4005 const url = (route) => 'http://localhost:' + port + route @@ -16,7 +16,7 @@ test.before('Init Nuxt.js', async t => { runBuild: true } nuxt = new Nuxt(options) - await nuxt.ready() + await new Builder(nuxt).build() server = new Server(nuxt) server.listen(port, 'localhost') }) diff --git a/test/index.test.js b/test/index.test.js index b008b1ee04..8e3fbf745e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,6 +1,6 @@ import test from 'ava' import { resolve } from 'path' -import { Nuxt } from '../index.js' +import { Nuxt, Builder } from '../index.js' test('Nuxt.js Class', t => { t.is(typeof Nuxt, 'function') @@ -12,7 +12,6 @@ test.serial('Nuxt.js Instance', async t => { }) t.is(typeof nuxt, 'object') t.is(nuxt.options.dev, true) - t.is(typeof nuxt.generate, 'function') t.is(typeof nuxt._ready.then, 'function') await nuxt.ready() t.is(nuxt.initialized, true) @@ -24,7 +23,7 @@ test.serial('Fail to build when no pages/ directory but is in the parent', t => runBuild: true, rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages') }) - return nuxt.ready().catch(err => { + return new Builder(nuxt).build().catch(err => { let s = String(err) t.true(s.includes('No `pages` directory found')) t.true(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?')) @@ -37,7 +36,7 @@ test.serial('Fail to build when no pages/ directory', t => { runBuild: true, rootDir: resolve(__dirname) }) - return nuxt.ready().catch(err => { + return new Builder(nuxt).build().catch(err => { let s = String(err) t.true(s.includes('Couldn\'t find a `pages` directory')) t.true(s.includes('Please create one under the project root')) diff --git a/test/module.test.js b/test/module.test.js index 331d42943f..6745df79a4 100755 --- a/test/module.test.js +++ b/test/module.test.js @@ -1,7 +1,7 @@ import test from 'ava' import { resolve, normalize } from 'path' import rp from 'request-promise-native' -import { Nuxt, Server } from '../index.js' +import { Nuxt, Server, Builder } from '../index.js' const port = 4006 const url = (route) => 'http://localhost:' + port + route @@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => { config.dev = false config.runBuild = true nuxt = new Nuxt(config) - await nuxt.ready() + await new Builder(nuxt).build() server = new Server(nuxt) server.listen(port, 'localhost') }) diff --git a/test/with-config.test.js b/test/with-config.test.js index ae4db48b02..1b5b3169ad 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -1,7 +1,7 @@ import test from 'ava' import { resolve } from 'path' import rp from 'request-promise-native' -import { Nuxt, Server } from '../index.js' +import { Nuxt, Server, Builder } from '../index.js' const port = 4007 const url = (route) => 'http://localhost:' + port + route @@ -17,7 +17,7 @@ test.before('Init Nuxt.js', async t => { config.dev = false config.runBuild = true nuxt = new Nuxt(config) - await nuxt.ready() + await new Builder(nuxt).build() server = new Server(nuxt) server.listen(port, 'localhost') }) @@ -104,13 +104,3 @@ test.after('Closing server and nuxt.js', t => { server.close() nuxt.close() }) - -test.after('Should be able to start Nuxt with build done', async t => { - const rootDir = resolve(__dirname, 'fixtures/with-config') - let config = require(resolve(rootDir, 'nuxt.config.js')) - config.rootDir = rootDir - config.dev = false - config.runBuild = true - nuxt = new Nuxt(config) - await nuxt.ready() -})