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') const { Nuxt, Builder } = require('nuxt')
// Import and set nuxt.js options // 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') config.dev = (process.env.NODE_ENV !== 'production')
let nuxt = new Nuxt(config) const nuxt = new Nuxt(config)
nuxt.ready().catch(console.error)
// Start build process (only in development) // Start build process (only in development)
if (config.dev) { if (config.dev) {

View File

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

View File

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

View File

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