-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if (global.consola) { | ||
module.exports = global.consola | ||
} else { | ||
const consola = require('./dist/consola.cjs.js') | ||
module.exports = consola | ||
global.consola = consola | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
describe('custom consola', () => { | ||
afterEach(() => { | ||
delete global.consola | ||
jest.resetModules() | ||
}) | ||
|
||
test('require twice has same consola', () => { | ||
const consola1 = require('consola') | ||
jest.resetModules() | ||
const consola2 = require('consola') | ||
|
||
expect(consola1 === consola2).toBe(true) | ||
}) | ||
|
||
test('custom consola fails without delete cache', async () => { | ||
require('consola') | ||
const consola1 = 'my-consola' | ||
global.consola = consola1 | ||
|
||
const consola2 = require('consola') | ||
|
||
expect(consola1 === consola2).toBe(false) | ||
expect(global.consola === consola2).toBe(false) | ||
}) | ||
|
||
test('require consola used global.consola by default', () => { | ||
const consola1 = 'my-consola' | ||
global.consola = consola1 | ||
|
||
const consola2 = require('consola') | ||
expect(consola1 === consola2).toBe(true) | ||
expect(global.consola === consola2).toBe(true) | ||
}) | ||
|
||
test('custom consola works when imported but deleted', () => { | ||
const consola0 = require('consola') | ||
expect(consola0).not.toBe(undefined) | ||
|
||
const consola1 = 'my-consola2' | ||
global.consola = consola1 | ||
|
||
jest.resetModules() // jest equivalent to delete require.cache | ||
|
||
const consola2 = require('consola') | ||
expect(consola1 === consola2).toBe(true) | ||
expect(global.consola === consola2).toBe(true) | ||
}) | ||
}) |