-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chore/reuse-resolver-config
- Loading branch information
Showing
18 changed files
with
296 additions
and
67 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
coverage/ | ||
dist/ | ||
packages/cli/lib/ | ||
packages/core/lib/ | ||
*snapshot.js |
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,53 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import * as colorette from 'colorette'; | ||
import { logger, colorize } from '../logger'; | ||
|
||
describe('Logger in Browser', () => { | ||
it('should call "console.error"', () => { | ||
const error = jest.spyOn(console, 'error').mockImplementation(); | ||
|
||
logger.error('error'); | ||
|
||
expect(error).toBeCalledTimes(1); | ||
expect(error).toBeCalledWith('error'); | ||
|
||
error.mockRestore(); | ||
}); | ||
|
||
it('should call "console.log"', () => { | ||
const log = jest.spyOn(console, 'log').mockImplementation(); | ||
|
||
logger.info('info'); | ||
|
||
expect(log).toBeCalledTimes(1); | ||
expect(log).toBeCalledWith('info'); | ||
|
||
log.mockRestore(); | ||
}); | ||
|
||
it('should call "console.warn"', () => { | ||
const warn = jest.spyOn(console, 'warn').mockImplementation(); | ||
|
||
logger.warn('warn'); | ||
|
||
expect(warn).toBeCalledTimes(1); | ||
expect(warn).toBeCalledWith('warn'); | ||
|
||
warn.mockRestore(); | ||
}); | ||
}); | ||
|
||
describe('colorize in Browser', () => { | ||
it('should not call original colorette lib', () => { | ||
const color = 'cyan'; | ||
const spyingCyan = jest.spyOn(colorette, color); | ||
|
||
const colorized = colorize.cyan(color); | ||
|
||
expect(spyingCyan).not.toBeCalled(); | ||
expect(colorized).toEqual(color); | ||
}); | ||
}); |
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,47 @@ | ||
import * as colorette from 'colorette'; | ||
import { logger, colorize } from '../logger'; | ||
|
||
describe('Logger in nodejs', () => { | ||
let spyingStderr: jest.SpyInstance; | ||
|
||
beforeEach(() => { | ||
spyingStderr = jest.spyOn(process.stderr, 'write').mockImplementation(); | ||
}); | ||
|
||
afterEach(() => { | ||
spyingStderr.mockRestore(); | ||
}); | ||
|
||
it('should call "process.stderr.write" for error severity', () => { | ||
logger.error('error'); | ||
|
||
expect(spyingStderr).toBeCalledTimes(1); | ||
expect(spyingStderr).toBeCalledWith(colorette.red('error')); | ||
}); | ||
|
||
it('should call "process.stderr.write" for warn severity', () => { | ||
logger.warn('warn'); | ||
|
||
expect(spyingStderr).toBeCalledTimes(1); | ||
expect(spyingStderr).toBeCalledWith(colorette.yellow('warn')); | ||
}); | ||
|
||
it('should call "process.stderr.write" for info severity', () => { | ||
logger.info('info'); | ||
|
||
expect(spyingStderr).toBeCalledTimes(1); | ||
expect(spyingStderr).toBeCalledWith('info'); | ||
}); | ||
}); | ||
|
||
describe('colorize in nodejs', () => { | ||
it('should call original colorette lib', () => { | ||
const color = 'cyan'; | ||
const spyingCyan = jest.spyOn(colorette, color); | ||
|
||
const colorized = colorize.cyan(color); | ||
|
||
expect(spyingCyan).toBeCalledWith(color); | ||
expect(colorized).toEqual(colorette[color](color)); | ||
}); | ||
}); |
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,18 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { output } from '../output'; | ||
|
||
describe('output', () => { | ||
it('should ignore all parsable data in browser', () => { | ||
const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation(); | ||
const data = '{ "errors" : [] }'; | ||
|
||
output.write(data); | ||
|
||
expect(spyingStdout).not.toBeCalled(); | ||
|
||
spyingStdout.mockRestore(); | ||
}); | ||
}); |
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,15 @@ | ||
import { output } from '../output'; | ||
|
||
describe('output', () => { | ||
it('should write all parsable data to stdout', () => { | ||
const spyingStdout = jest.spyOn(process.stdout, 'write').mockImplementation(); | ||
const data = '{ "errors" : [] }'; | ||
|
||
output.write(data); | ||
|
||
expect(spyingStdout).toBeCalledTimes(1); | ||
expect(spyingStdout).toBeCalledWith(data); | ||
|
||
spyingStdout.mockRestore(); | ||
}); | ||
}); |
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,11 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { isBrowser } from '../env'; | ||
|
||
describe('isBrowser', () => { | ||
it('should be browser', () => { | ||
expect(isBrowser).toBe(true); | ||
}); | ||
}); |
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
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
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,5 @@ | ||
export const isBrowser = | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
typeof window !== 'undefined' || typeof self !== 'undefined' || typeof process === 'undefined'; // main and worker thread | ||
export const env = isBrowser ? {} : process.env || {}; |
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
Oops, something went wrong.