From 85d74ae49e6134f9c841f86532eb1e32a7aa06dc Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Sat, 4 Jul 2020 16:42:38 +0000 Subject: [PATCH] [wip] Jest globals --- src/configure.js | 6 ++++ src/lib/jest-globals.js | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/lib/jest-globals.js diff --git a/src/configure.js b/src/configure.js index 9beb63b..297beed 100644 --- a/src/configure.js +++ b/src/configure.js @@ -270,6 +270,12 @@ export default function configure(options) { included: true, served: true, }, + { + pattern: path.resolve(__dirname, './lib/jest-globals.js'), + watched: false, + included: true, + served: true, + }, ].concat( ...files.map((pattern) => { // Expand '**/xx' patterns but exempt node_modules and gitignored directories diff --git a/src/lib/jest-globals.js b/src/lib/jest-globals.js new file mode 100644 index 0000000..efe9ef7 --- /dev/null +++ b/src/lib/jest-globals.js @@ -0,0 +1,74 @@ +function notImplemented() { + throw Error(`Not Implemented`); +} + +// @todo expect.extend() et al + +global.jest = { + addMatchers(matchers) { + jasmine.addMatchers(matchers); + }, + advanceTimersByTime(msToRun) { + // _getFakeTimers().advanceTimersByTime(msToRun); + notImplemented(); + }, + advanceTimersToNextTimer(steps) { + // _getFakeTimers().advanceTimersToNextTimer(steps); + notImplemented(); + }, + autoMockOff: notImplemented, + autoMockOn: notImplemented, + clearAllMocks: notImplemented, + clearAllTimers() { + // _getFakeTimers().clearAllTimers(); + notImplemented(); + }, + createMockFromModule(moduleName) { + // return this._generateMock(from, moduleName); + notImplemented(); + }, + deepUnmock: notImplemented, + disableAutomock: notImplemented, + doMock: notImplemented, + dontMock: notImplemented, + enableAutomock: notImplemented, + fn: jasmine.createSpy, + genMockFromModule(moduleName) { + // return this._generateMock(from, moduleName); + notImplemented(); + }, + getRealSystemTime: notImplemented, + getTimerCount() { + // return _getFakeTimers().getTimerCount(); + notImplemented(); + }, + isMockFunction(fn) { + // check if spy/mock + notImplemented(); + }, + isolateModules: notImplemented, + mock: jasmine.createSpy, // @todo check + requireActual: require, + requireMock: notImplemented, + resetAllMocks: notImplemented, + resetModuleRegistry: notImplemented, + resetModules: notImplemented, + restoreAllMocks: notImplemented, + retryTimes: notImplemented, + runAllImmediates() { + notImplemented(); + }, + runAllTicks: notImplemented, + runAllTimers: notImplemented, + runOnlyPendingTimers: notImplemented, + runTimersToTime: notImplemented, + setMock: notImplemented, + setSystemTime(now) { + notImplemented(); + }, + setTimeout, + spyOn: jasmine.createSpy, // @todo check + unmock: (mock) => mock.restore(), // @todo check + useFakeTimers: notImplemented, + useRealTimers: notImplemented, +};