mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
revert(core): call ready to prevent breaking changes (#5413)
This commit is contained in:
parent
66b956a1ba
commit
001ba775fa
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user