Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. /// <reference types="node" />
  8. import type { Context } from 'vm';
  9. import type { LegacyFakeTimers, ModernFakeTimers } from '@jest/fake-timers';
  10. import type { Circus, Config, Global } from '@jest/types';
  11. import type { fn as JestMockFn, spyOn as JestMockSpyOn, ModuleMocker } from 'jest-mock';
  12. export declare type EnvironmentContext = {
  13. console: Console;
  14. docblockPragmas: Record<string, string | Array<string>>;
  15. testPath: Config.Path;
  16. };
  17. export declare type ModuleWrapper = (this: Module['exports'], module: Module, exports: Module['exports'], require: Module['require'], __dirname: string, __filename: Module['filename'], jest?: Jest, ...extraGlobals: Array<Global.Global[keyof Global.Global]>) => unknown;
  18. export declare class JestEnvironment<Timer = unknown> {
  19. constructor(config: Config.ProjectConfig, context?: EnvironmentContext);
  20. global: Global.Global;
  21. fakeTimers: LegacyFakeTimers<Timer> | null;
  22. fakeTimersModern: ModernFakeTimers | null;
  23. moduleMocker: ModuleMocker | null;
  24. getVmContext(): Context | null;
  25. setup(): Promise<void>;
  26. teardown(): Promise<void>;
  27. handleTestEvent?: Circus.EventHandler;
  28. exportConditions?: () => Array<string>;
  29. }
  30. export declare type Module = NodeModule;
  31. export interface Jest {
  32. /**
  33. * Advances all timers by the needed milliseconds so that only the next timeouts/intervals will run.
  34. * Optionally, you can provide steps, so it will run steps amount of next timeouts/intervals.
  35. */
  36. advanceTimersToNextTimer(steps?: number): void;
  37. /**
  38. * Disables automatic mocking in the module loader.
  39. */
  40. autoMockOff(): Jest;
  41. /**
  42. * Enables automatic mocking in the module loader.
  43. */
  44. autoMockOn(): Jest;
  45. /**
  46. * Clears the mock.calls and mock.instances properties of all mocks.
  47. * Equivalent to calling .mockClear() on every mocked function.
  48. */
  49. clearAllMocks(): Jest;
  50. /**
  51. * Removes any pending timers from the timer system. If any timers have been
  52. * scheduled, they will be cleared and will never have the opportunity to
  53. * execute in the future.
  54. */
  55. clearAllTimers(): void;
  56. /**
  57. * Indicates that the module system should never return a mocked version
  58. * of the specified module, including all of the specified module's
  59. * dependencies.
  60. */
  61. deepUnmock(moduleName: string): Jest;
  62. /**
  63. * Disables automatic mocking in the module loader.
  64. *
  65. * After this method is called, all `require()`s will return the real
  66. * versions of each module (rather than a mocked version).
  67. */
  68. disableAutomock(): Jest;
  69. /**
  70. * When using `babel-jest`, calls to mock will automatically be hoisted to
  71. * the top of the code block. Use this method if you want to explicitly avoid
  72. * this behavior.
  73. */
  74. doMock(moduleName: string, moduleFactory?: () => unknown): Jest;
  75. /**
  76. * Indicates that the module system should never return a mocked version
  77. * of the specified module from require() (e.g. that it should always return
  78. * the real module).
  79. */
  80. dontMock(moduleName: string): Jest;
  81. /**
  82. * Enables automatic mocking in the module loader.
  83. */
  84. enableAutomock(): Jest;
  85. /**
  86. * Creates a mock function. Optionally takes a mock implementation.
  87. */
  88. fn: typeof JestMockFn;
  89. /**
  90. * Given the name of a module, use the automatic mocking system to generate a
  91. * mocked version of the module for you.
  92. *
  93. * This is useful when you want to create a manual mock that extends the
  94. * automatic mock's behavior.
  95. *
  96. * @deprecated Use `jest.createMockFromModule()` instead
  97. */
  98. genMockFromModule(moduleName: string): unknown;
  99. /**
  100. * Given the name of a module, use the automatic mocking system to generate a
  101. * mocked version of the module for you.
  102. *
  103. * This is useful when you want to create a manual mock that extends the
  104. * automatic mock's behavior.
  105. */
  106. createMockFromModule(moduleName: string): unknown;
  107. /**
  108. * Determines if the given function is a mocked function.
  109. */
  110. isMockFunction(fn: (...args: Array<any>) => unknown): fn is ReturnType<typeof JestMockFn>;
  111. /**
  112. * Mocks a module with an auto-mocked version when it is being required.
  113. */
  114. mock(moduleName: string, moduleFactory?: () => unknown, options?: {
  115. virtual?: boolean;
  116. }): Jest;
  117. /**
  118. * Mocks a module with the provided module factory when it is being imported.
  119. */
  120. unstable_mockModule<T = unknown>(moduleName: string, moduleFactory: () => Promise<T> | T, options?: {
  121. virtual?: boolean;
  122. }): Jest;
  123. /**
  124. * Returns the actual module instead of a mock, bypassing all checks on
  125. * whether the module should receive a mock implementation or not.
  126. *
  127. * @example
  128. ```
  129. jest.mock('../myModule', () => {
  130. // Require the original module to not be mocked...
  131. const originalModule = jest.requireActual(moduleName);
  132. return {
  133. __esModule: true, // Use it when dealing with esModules
  134. ...originalModule,
  135. getRandom: jest.fn().mockReturnValue(10),
  136. };
  137. });
  138. const getRandom = require('../myModule').getRandom;
  139. getRandom(); // Always returns 10
  140. ```
  141. */
  142. requireActual: (moduleName: string) => unknown;
  143. /**
  144. * Returns a mock module instead of the actual module, bypassing all checks
  145. * on whether the module should be required normally or not.
  146. */
  147. requireMock: (moduleName: string) => unknown;
  148. /**
  149. * Resets the state of all mocks.
  150. * Equivalent to calling .mockReset() on every mocked function.
  151. */
  152. resetAllMocks(): Jest;
  153. /**
  154. * Resets the module registry - the cache of all required modules. This is
  155. * useful to isolate modules where local state might conflict between tests.
  156. */
  157. resetModules(): Jest;
  158. /**
  159. * Restores all mocks back to their original value. Equivalent to calling
  160. * `.mockRestore` on every mocked function.
  161. *
  162. * Beware that jest.restoreAllMocks() only works when the mock was created with
  163. * jest.spyOn; other mocks will require you to manually restore them.
  164. */
  165. restoreAllMocks(): Jest;
  166. /**
  167. * Runs failed tests n-times until they pass or until the max number of
  168. * retries is exhausted. This only works with `jest-circus`!
  169. */
  170. retryTimes(numRetries: number): Jest;
  171. /**
  172. * Exhausts tasks queued by setImmediate().
  173. *
  174. * > Note: This function is not available when using Lolex as fake timers implementation
  175. */
  176. runAllImmediates(): void;
  177. /**
  178. * Exhausts the micro-task queue (usually interfaced in node via
  179. * process.nextTick).
  180. */
  181. runAllTicks(): void;
  182. /**
  183. * Exhausts the macro-task queue (i.e., all tasks queued by setTimeout()
  184. * and setInterval()).
  185. */
  186. runAllTimers(): void;
  187. /**
  188. * Executes only the macro-tasks that are currently pending (i.e., only the
  189. * tasks that have been queued by setTimeout() or setInterval() up to this
  190. * point). If any of the currently pending macro-tasks schedule new
  191. * macro-tasks, those new tasks will not be executed by this call.
  192. */
  193. runOnlyPendingTimers(): void;
  194. /**
  195. * Advances all timers by msToRun milliseconds. All pending "macro-tasks"
  196. * that have been queued via setTimeout() or setInterval(), and would be
  197. * executed within this timeframe will be executed.
  198. */
  199. advanceTimersByTime(msToRun: number): void;
  200. /**
  201. * Returns the number of fake timers still left to run.
  202. */
  203. getTimerCount(): number;
  204. /**
  205. * Explicitly supplies the mock object that the module system should return
  206. * for the specified module.
  207. *
  208. * Note It is recommended to use `jest.mock()` instead. The `jest.mock`
  209. * API's second argument is a module factory instead of the expected
  210. * exported module object.
  211. */
  212. setMock(moduleName: string, moduleExports: unknown): Jest;
  213. /**
  214. * Set the default timeout interval for tests and before/after hooks in
  215. * milliseconds.
  216. *
  217. * Note: The default timeout interval is 5 seconds if this method is not
  218. * called.
  219. */
  220. setTimeout(timeout: number): Jest;
  221. /**
  222. * Creates a mock function similar to `jest.fn` but also tracks calls to
  223. * `object[methodName]`.
  224. *
  225. * Note: By default, jest.spyOn also calls the spied method. This is
  226. * different behavior from most other test libraries.
  227. */
  228. spyOn: typeof JestMockSpyOn;
  229. /**
  230. * Indicates that the module system should never return a mocked version of
  231. * the specified module from require() (e.g. that it should always return the
  232. * real module).
  233. */
  234. unmock(moduleName: string): Jest;
  235. /**
  236. * Instructs Jest to use fake versions of the standard timer functions.
  237. */
  238. useFakeTimers(implementation?: 'modern' | 'legacy'): Jest;
  239. /**
  240. * Instructs Jest to use the real versions of the standard timer functions.
  241. */
  242. useRealTimers(): Jest;
  243. /**
  244. * `jest.isolateModules(fn)` goes a step further than `jest.resetModules()`
  245. * and creates a sandbox registry for the modules that are loaded inside
  246. * the callback function. This is useful to isolate specific modules for
  247. * every test so that local module state doesn't conflict between tests.
  248. */
  249. isolateModules(fn: () => void): Jest;
  250. /**
  251. * When mocking time, `Date.now()` will also be mocked. If you for some reason need access to the real current time, you can invoke this function.
  252. *
  253. * > Note: This function is only available when using Lolex as fake timers implementation
  254. */
  255. getRealSystemTime(): number;
  256. /**
  257. * Set the current system time used by fake timers. Simulates a user changing the system clock while your program is running. It affects the current time but it does not in itself cause e.g. timers to fire; they will fire exactly as they would have done without the call to `jest.setSystemTime()`.
  258. *
  259. * > Note: This function is only available when using Lolex as fake timers implementation
  260. */
  261. setSystemTime(now?: number | Date): void;
  262. }