-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
224 additions
and
96 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
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,32 @@ | ||
export interface Styles { | ||
componentCSS?: string | ||
changeCSS?: string | ||
subValueCSS?: string | ||
} | ||
|
||
export interface UseLog { | ||
styles?: Styles | ||
environments?: string[] | ||
} | ||
|
||
export type Log = UseLog | ||
|
||
export interface UseLogReturn { | ||
log: <T>(value: T, props?: Log) => void | ||
} | ||
|
||
export interface PrintProps<T> { | ||
value: T | ||
prevValue?: T | ||
label: string | ||
group?: string | ||
type?: PrintTypes | ||
styles?: Styles | ||
componentName: string | ||
} | ||
|
||
export enum PrintTypes { | ||
Mount = 'Mount', | ||
Unmount = 'Unmount', | ||
Change = 'Change', | ||
} |
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,73 @@ | ||
import { getGroupLabel, getComponentName, print } from './utils' | ||
import { PrintProps, PrintTypes } from './types' | ||
|
||
describe('utils', () => { | ||
describe('getGroupLabel', () => { | ||
it('renders', () => { | ||
expect(getGroupLabel(PrintTypes.Change)).toEqual( | ||
`Change %c%c@ ${new Date().toLocaleTimeString()}`, | ||
) | ||
}) | ||
|
||
it('renders with component name', () => { | ||
expect(getGroupLabel(PrintTypes.Mount, 'TestComponent')).toEqual( | ||
`Mount in %c<TestComponent /> %c@ ${new Date().toLocaleTimeString()}`, | ||
) | ||
}) | ||
}) | ||
|
||
describe('getComponentName', () => { | ||
it('gets component name', () => { | ||
expect(getComponentName()).toEqual('_callCircusTest') | ||
}) | ||
}) | ||
|
||
describe('print', () => { | ||
const consoleLog = jest.spyOn(console, 'log').mockImplementation(() => null) | ||
const consoleGroup = jest | ||
.spyOn(console, 'group') | ||
.mockImplementation(() => null) | ||
const consoleGroupEnd = jest | ||
.spyOn(console, 'groupEnd') | ||
.mockImplementation(() => null) | ||
|
||
const printProps: PrintProps<string> = { | ||
value: 'Test Value', | ||
label: 'A Label', | ||
componentName: 'SomeComponentName', | ||
} | ||
|
||
it('prints', () => { | ||
print(printProps) | ||
|
||
expect(consoleGroup).toHaveBeenCalledWith( | ||
`Change in %c<SomeComponentName /> %c@ ${new Date().toLocaleTimeString()}`, | ||
undefined, | ||
undefined, | ||
) | ||
expect(consoleLog).toHaveBeenCalledWith(' A Label: Test Value') | ||
expect(consoleLog).toHaveBeenCalledTimes(1) | ||
expect(consoleGroupEnd).toHaveBeenCalled() | ||
}) | ||
|
||
it('prints previous value', () => { | ||
print({ ...printProps, prevValue: 'Some Previous value' }) | ||
|
||
expect(consoleGroup).toHaveBeenCalledWith( | ||
`Change in %c<SomeComponentName /> %c@ ${new Date().toLocaleTimeString()}`, | ||
undefined, | ||
undefined, | ||
) | ||
expect(consoleLog).toHaveBeenCalledWith( | ||
'Previous value: %cSome Previous value', | ||
undefined, | ||
) | ||
expect(consoleLog).toHaveBeenCalledWith( | ||
' Current value: %cTest Value', | ||
undefined, | ||
) | ||
expect(consoleLog).toHaveBeenCalledTimes(2) | ||
expect(consoleGroupEnd).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.