revert(core): call ready to prevent breaking changes (#5413)

This commit is contained in:
Pooya Parsa 2019-03-30 23:23:56 +04:30 committed by GitHub
parent 66b956a1ba
commit 001ba775fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 22 deletions

View File

@ -100,11 +100,10 @@ Or you can start by using one of our starter templates:
const { Nuxt, Builder } = require('nuxt')
// Import and set nuxt.js options
let config = require('./nuxt.config.js')
const config = require('./nuxt.config.js')
config.dev = (process.env.NODE_ENV !== 'production')
let nuxt = new Nuxt(config)
nuxt.ready().catch(console.error)
const nuxt = new Nuxt(config)
// Start build process (only in development)
if (config.dev) {

View File

@ -38,6 +38,13 @@ export default class Nuxt extends Hookable {
if (this.options.server !== false) {
this._initServer()
}
// Call ready
if (this.options._ready !== false) {
this.ready().catch((err) => {
consola.fatal(err)
})
}
}
static get version() {
@ -46,9 +53,7 @@ export default class Nuxt extends Hookable {
ready() {
if (!this._ready) {
this._ready = this._init().catch((err) => {
consola.fatal(err)
})
this._ready = this._init()
}
return this._ready
}

View File

@ -1,4 +1,3 @@
import consola from 'consola'
import { defineAlias } from '@nuxt/utils'
import { getNuxtConfig } from '@nuxt/config'
import { Server } from '@nuxt/server'
@ -14,7 +13,9 @@ jest.mock('@nuxt/utils')
jest.mock('@nuxt/server')
jest.mock('@nuxt/config', () => ({
getNuxtConfig: jest.fn(() => ({}))
getNuxtConfig: jest.fn(() => ({
_ready: false
}))
}))
describe('core: nuxt', () => {
@ -67,10 +68,7 @@ describe('core: nuxt', () => {
const err = new Error('nuxt ready failed')
const nuxt = new Nuxt()
nuxt._init = () => Promise.reject(err)
await nuxt.ready()
expect(consola.fatal).toBeCalledTimes(1)
expect(consola.fatal).toBeCalledWith(err)
await expect(nuxt.ready()).rejects.toThrow(err)
})
test('should return nuxt version from package.json', () => {
@ -113,7 +111,7 @@ describe('core: nuxt', () => {
test('should add object hooks', async () => {
const hooks = {}
getNuxtConfig.mockReturnValueOnce({ hooks })
getNuxtConfig.mockReturnValueOnce({ hooks, _ready: false })
const nuxt = new Nuxt()
nuxt.addHooks = jest.fn()

View File

@ -16,9 +16,8 @@ describe('renderer', () => {
dev: false,
buildDir: '/path/to/404'
})
await nuxt.ready()
await expect(nuxt.renderer.renderer.isReady).toBe(false)
expect(consola.fatal).toHaveBeenCalledWith(expect.objectContaining({
await expect(nuxt.ready()).rejects.toThrow(expect.objectContaining({
message: expect.stringMatching(NO_BUILD_MSG)
}))
})
@ -30,9 +29,8 @@ describe('renderer', () => {
dev: false,
buildDir: '/path/to/404'
})
await nuxt.ready()
await expect(nuxt.renderer.renderer.isReady).toBe(false)
expect(consola.fatal).toHaveBeenCalledWith(expect.objectContaining({
await expect(nuxt.ready()).rejects.toThrow(expect.objectContaining({
message: expect.stringMatching(NO_BUILD_MSG)
}))
})
@ -44,9 +42,8 @@ describe('renderer', () => {
dev: false,
buildDir: '/path/to/404'
})
await nuxt.ready()
await expect(nuxt.renderer.renderer.isModernReady).toBe(false)
expect(consola.fatal).toHaveBeenCalledWith(expect.objectContaining({
await expect(nuxt.ready()).rejects.toThrow(expect.objectContaining({
message: expect.stringMatching(NO_MODERN_BUILD_MSG)
}))
})