-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Upgrade
jest
dependency to latest 27.0.3
- avoids using `afterEach` to reset auto-mocks
- Loading branch information
Showing
12 changed files
with
1,046 additions
and
2,015 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
export function like<T> (what: T) { | ||
export function like<T> (what: Partial<T>) { | ||
return expect.objectContaining(what); | ||
} |
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,55 @@ | ||
jest.mock('debug', () => { | ||
|
||
function logger (name: string, logs: any) { | ||
logs[name] = logs[name] || []; | ||
|
||
return Object.assign((_: string, ...messages: Array<string | unknown>) => { | ||
logs[name].push(messages.filter(m => typeof m === 'string' || Buffer.isBuffer(m)).join(' ')); | ||
}, { | ||
extend (suffix: string) { | ||
return debug(`${name}:${suffix}`); | ||
}, | ||
get logs () { | ||
return logs; | ||
} | ||
}) | ||
} | ||
|
||
const debug: any = Object.assign( | ||
jest.fn((name) => { | ||
|
||
if (debug.mock.results[0].type === 'return') { | ||
return logger(name, debug.mock.results[0].value.logs); | ||
} | ||
|
||
return logger(name, {}) | ||
}), | ||
{ | ||
formatters: { | ||
H: 'hello-world', | ||
}, | ||
}); | ||
|
||
return debug; | ||
}); | ||
|
||
function logs (): Record<string, string[]> { | ||
return (require('debug') as jest.Mock).mock.results[0].value.logs; | ||
} | ||
|
||
export function $logNames(...matching: RegExp[]) { | ||
return Object.keys(logs()).filter(matches); | ||
|
||
function matches(namespace: string) { | ||
return !matching.length || matching.some(regex => regex.test(namespace)); | ||
} | ||
} | ||
|
||
export function $logMessagesFor(name: string) { | ||
const log = logs()[name]; | ||
|
||
expect(Array.isArray(log)).toBe(true); | ||
|
||
return log.join('\n'); | ||
} | ||
|
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,13 @@ | ||
import { exists } from '@kwsites/file-exists'; | ||
|
||
jest.mock('@kwsites/file-exists', () => ({ | ||
exists: jest.fn().mockReturnValue(true), | ||
})); | ||
|
||
export function isInvalidDirectory() { | ||
(exists as jest.Mock).mockReturnValue(false); | ||
} | ||
|
||
export function isValidDirectory() { | ||
(exists as jest.Mock).mockReturnValue(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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.