Skip to content

Commit 6bfbcad

Browse files
ricardogobbosouzapi0
authored andcommitted
fix(module): use logger (#40)
1 parent 297c034 commit 6bfbcad

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/logger.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const consola = require('consola')
2+
3+
module.exports = consola.withScope('nuxt:proxy')

lib/module.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
const Proxy = require('http-proxy-middleware')
2-
const consola = require('consola')
3-
4-
const logger = consola.withScope('nuxt:proxy')
2+
const logger = require('./logger')
53

64
// Redirect info ~> debug
75
logger.info = logger.debug
86

97
function proxyModule(options) {
108
if (!this.options.proxy) {
119
// No proxy defined
10+
logger.warn('No proxy defined on top level.')
1211
return
1312
}
1413

1514
if (this.options.mode !== 'spa') {
1615
this.nuxt.hook('generate:before', () => {
17-
consola.warn('The module `@nuxtjs/proxy` does not work in generated mode.')
16+
logger.warn('The module `@nuxtjs/proxy` does not work in generated mode.')
1817
})
1918
}
2019

test/module.test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ jest.setTimeout(60000)
22

33
const { Nuxt, Generator, Builder } = require('nuxt-edge')
44
const request = require('request-promise-native')
5-
const consola = require('consola')
5+
const logger = require('@/logger')
66

77
const config = require('./fixture/nuxt.config')
88
config.dev = false
99

1010
let nuxt
1111

12-
consola.mockTypes(() => jest.fn())
12+
logger.mockTypes(() => jest.fn())
1313

1414
const url = path => `http://localhost:3000${path}`
1515
const get = path => request(url(path))
@@ -23,7 +23,7 @@ const setupNuxt = async (config) => {
2323

2424
describe('module', () => {
2525
beforeEach(() => {
26-
consola.warn.mockClear()
26+
logger.warn.mockClear()
2727
})
2828

2929
afterEach(async () => {
@@ -54,7 +54,7 @@ describe('module', () => {
5454
await generator.initiate()
5555
await generator.initRoutes()
5656

57-
expect(consola.warn).toHaveBeenNthCalledWith(1, 'The module `@nuxtjs/proxy` does not work in generated mode.')
57+
expect(logger.warn).toHaveBeenCalledWith('The module `@nuxtjs/proxy` does not work in generated mode.')
5858
})
5959

6060
test('generate spa mode', async () => {
@@ -70,7 +70,7 @@ describe('module', () => {
7070
await generator.initiate()
7171
await generator.initRoutes()
7272

73-
expect(consola.warn).not.toHaveBeenCalled()
73+
expect(logger.warn).not.toHaveBeenCalled()
7474
})
7575

7676
test('object mode', async () => {
@@ -107,6 +107,8 @@ describe('module', () => {
107107
proxy: false
108108
})
109109

110+
expect(logger.warn).toHaveBeenCalledWith('No proxy defined on top level.')
111+
110112
await expect(await get('/proxy/aaa')).toBe('url:/proxy/aaa')
111113
})
112114
})

0 commit comments

Comments
 (0)