diff --git a/test/fixtures/with-config/with-config.test.js b/test/fixtures/with-config/with-config.test.js index 5edaa02493..6d6ebce414 100644 --- a/test/fixtures/with-config/with-config.test.js +++ b/test/fixtures/with-config/with-config.test.js @@ -2,9 +2,6 @@ const consola = require('consola') const { buildFixture } = require('../../utils/build') describe('with-config', () => { - beforeAll(() => { - consola.warn = jest.fn() - }) buildFixture('with-config', () => { expect(consola.warn).toHaveBeenCalledTimes(1) expect(consola.warn.mock.calls[0]).toMatchObject([{ diff --git a/test/unit/basic.config.defaults.test.js b/test/unit/basic.config.defaults.test.js index fff80e7b08..4dc17c84d2 100644 --- a/test/unit/basic.config.defaults.test.js +++ b/test/unit/basic.config.defaults.test.js @@ -15,14 +15,10 @@ describe('basic config defaults', () => { }) test('vendor has been deprecated', () => { - jest.spyOn(consola, 'warn') - const options = Options.from({ build: { vendor: 'vue' } }) expect(options.build.vendor).toBeUndefined() expect(consola.warn).toHaveBeenCalledWith('vendor has been deprecated due to webpack4 optimization') - - consola.warn.mockRestore() }) }) diff --git a/test/unit/basic.ssr.test.js b/test/unit/basic.ssr.test.js index 6079e9731a..47da9e7045 100644 --- a/test/unit/basic.ssr.test.js +++ b/test/unit/basic.ssr.test.js @@ -57,8 +57,6 @@ describe('basic ssr', () => { }) test('/head', async () => { - jest.spyOn(consola, 'log') - const window = await nuxt.renderAndGetWindow(url('/head')) expect(window.document.title).toBe('My title - Nuxt.js') @@ -71,8 +69,6 @@ describe('basic ssr', () => { const metas = window.document.getElementsByTagName('meta') expect(metas[0].getAttribute('content')).toBe('my meta') expect(consola.log).toHaveBeenCalledWith('Body script!') - - consola.log.mockRestore() }) test('/async-data', async () => { diff --git a/test/unit/error.test.js b/test/unit/error.test.js index d9c5147a89..1d325bd6f5 100644 --- a/test/unit/error.test.js +++ b/test/unit/error.test.js @@ -39,9 +39,10 @@ describe('error', () => { }) test('Error: callHook()', async () => { + consola.error.mockClear() + const errorHook = jest.fn() const error = new Error('test hook error') - jest.spyOn(consola, 'error') nuxt.hook('error', errorHook) nuxt.hook('test:error', () => { throw error }) @@ -51,8 +52,6 @@ describe('error', () => { expect(errorHook).toHaveBeenCalledWith(error) expect(consola.error).toHaveBeenCalledTimes(1) expect(consola.error).toHaveBeenCalledWith(error) - - consola.error.mockRestore() }) // Close server and ask nuxt to stop listening to file changes diff --git a/test/unit/module.test.js b/test/unit/module.test.js index 92bf6fd050..7f4722916c 100644 --- a/test/unit/module.test.js +++ b/test/unit/module.test.js @@ -60,12 +60,8 @@ describe('module', () => { }) test('AddVendor - deprecated', () => { - jest.spyOn(consola, 'warn') - nuxt.moduleContainer.addVendor('nuxt-test') expect(consola.warn).toHaveBeenCalledWith('addVendor has been deprecated due to webpack4 optimization') - - consola.warn.mockRestore() }) // Close server and ask nuxt to stop listening to file changes diff --git a/test/unit/spa.test.js b/test/unit/spa.test.js index e07470030f..71c0fce7fe 100644 --- a/test/unit/spa.test.js +++ b/test/unit/spa.test.js @@ -1,10 +1,7 @@ import consola from 'consola' -import mockLog from '../utils/mock-log' import { loadFixture, getPort, Nuxt } from '../utils' -let nuxt = null - -let port +let nuxt, port const url = route => 'http://localhost:' + port + route const renderRoute = async (_url) => { @@ -15,8 +12,6 @@ const renderRoute = async (_url) => { } describe('spa', () => { - mockLog(['log'], consola) - beforeAll(async () => { const config = loadFixture('spa') nuxt = new Nuxt(config) @@ -29,6 +24,7 @@ describe('spa', () => { expect(html).toMatch('Hello SPA!') expect(consola.log).not.toHaveBeenCalledWith('created') expect(consola.log).toHaveBeenCalledWith('mounted') + consola.log.mockClear() }) test('/custom (custom layout)', async () => { @@ -36,6 +32,7 @@ describe('spa', () => { expect(html).toMatch('Custom layout') expect(consola.log).toHaveBeenCalledWith('created') expect(consola.log).toHaveBeenCalledWith('mounted') + consola.log.mockClear() }) test('/mounted', async () => { diff --git a/test/utils/mock-log.js b/test/utils/mock-log.js deleted file mode 100644 index 32f8d367ab..0000000000 --- a/test/utils/mock-log.js +++ /dev/null @@ -1,24 +0,0 @@ -/* eslint-disable no-console */ -export default function mockLog(levels = 'all', logger = console) { - if (levels === 'all') { - levels = ['trace', 'debug', 'log', 'info', 'warn', 'error'] - } else if (typeof levels === 'string') { - levels = [levels] - } - beforeAll(() => { - for (const level of levels) { - jest.spyOn(logger, level).mockImplementation(() => {}) - } - }) - beforeEach(() => { - for (const level of levels) { - logger[level].mockClear() - } - }) - afterAll(() => { - for (const level of levels) { - logger[level].mockRestore() - } - }) - return logger -} diff --git a/test/utils/setup.js b/test/utils/setup.js index addfbac4cd..560b14846e 100644 --- a/test/utils/setup.js +++ b/test/utils/setup.js @@ -1,10 +1,16 @@ -// eslint-disable -require('consola').clear().add({ - log: jest.fn() -}) - -jasmine.DEFAULT_TIMEOUT_INTERVAL = 60 * 1000 const isAppveyor = !!process.env.APPVEYOR describe.skip.appveyor = isAppveyor ? describe.skip : describe test.skip.appveyor = isAppveyor ? test.skip : test + +jest.setTimeout(60000) +jest.mock('consola', () => { + const consola = {} + for (const level of [ + 'fatal', 'error', 'warn', 'log', 'info', + 'start', 'success', 'ready', 'debug', 'trace' + ]) { + consola[level] = jest.fn() + } + return consola +})