-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate jest-runtime to TypeScript
- Loading branch information
Showing
25 changed files
with
499 additions
and
268 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
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,3 @@ | ||
**/__mocks__/** | ||
**/__tests__/** | ||
src |
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,22 @@ | ||
{ | ||
"name": "@jest/environment", | ||
"version": "24.1.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/facebook/jest.git", | ||
"directory": "packages/jest-environment" | ||
}, | ||
"license": "MIT", | ||
"main": "build/index.js", | ||
"types": "build/index.d.ts", | ||
"dependencies": { | ||
"@jest/transform": "^24.1.0", | ||
"@jest/types": "^24.1.0", | ||
"@types/node": "*", | ||
"jest-mock": "^24.0.0" | ||
}, | ||
"engines": { | ||
"node": ">= 6" | ||
}, | ||
"gitHead": "b16789230fd45056a7f2fa199bae06c7a1780deb" | ||
} |
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,96 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {Script} from 'vm'; | ||
import {Config} from '@jest/types'; | ||
import moduleMocker from 'jest-mock'; | ||
import {ScriptTransformer} from '@jest/transform'; | ||
|
||
export type EnvironmentContext = { | ||
console?: Console; | ||
testPath?: Config.Path; | ||
}; | ||
|
||
// TODO: Get rid of this at some point | ||
type JasmineType = {_DEFAULT_TIMEOUT_INTERVAL?: number; addMatchers: Function}; | ||
|
||
// TODO: type this better: https://nodejs.org/api/modules.html#modules_the_module_wrapper | ||
type ModuleWrapper = (...args: Array<unknown>) => unknown; | ||
|
||
export interface JestEnvironment { | ||
new ( | ||
config: Config.ProjectConfig, | ||
context?: EnvironmentContext, | ||
): JestEnvironment; | ||
runScript( | ||
script: Script, | ||
): {[ScriptTransformer.EVAL_RESULT_VARIABLE]: ModuleWrapper} | null; | ||
// TODO: Maybe add `| Window` in the future? | ||
global: NodeJS.Global & {__coverage__: any; jasmine: JasmineType}; | ||
// TODO: When `jest-util` is ESM, this can just be `fakeTimers: import('jest-util').FakeTimers` | ||
fakeTimers: { | ||
clearAllTimers(): void; | ||
runAllImmediates(): void; | ||
runAllTicks(): void; | ||
runAllTimers(): void; | ||
advanceTimersByTime(msToRun: number): void; | ||
runOnlyPendingTimers(): void; | ||
runWithRealTimers(callback: any): void; | ||
getTimerCount(): number; | ||
useFakeTimers(): void; | ||
useRealTimers(): void; | ||
}; | ||
testFilePath: Config.Path; | ||
moduleMocker: typeof moduleMocker; | ||
setup(): Promise<void>; | ||
teardown(): Promise<void>; | ||
} | ||
|
||
export type Module = typeof module; | ||
|
||
export type LocalModuleRequire = typeof require & { | ||
requireActual: (moduleName: string) => unknown; | ||
requireMock: (moduleName: string) => unknown; | ||
}; | ||
|
||
export type Jest = { | ||
addMatchers(matchers: Object): void; | ||
autoMockOff(): Jest; | ||
autoMockOn(): Jest; | ||
clearAllMocks(): Jest; | ||
clearAllTimers(): void; | ||
deepUnmock(moduleName: string): Jest; | ||
disableAutomock(): Jest; | ||
doMock(moduleName: string, moduleFactory?: any): Jest; | ||
dontMock(moduleName: string): Jest; | ||
enableAutomock(): Jest; | ||
fn: typeof moduleMocker.fn; | ||
genMockFromModule(moduleName: string): any; | ||
isMockFunction(fn: Function): boolean; | ||
mock(moduleName: string, moduleFactory?: any, options?: Object): Jest; | ||
requireActual: LocalModuleRequire['requireActual']; | ||
requireMock: LocalModuleRequire['requireMock']; | ||
resetAllMocks(): Jest; | ||
resetModuleRegistry(): Jest; | ||
resetModules(): Jest; | ||
restoreAllMocks(): Jest; | ||
retryTimes(numRetries: number): Jest; | ||
runAllImmediates(): void; | ||
runAllTicks(): void; | ||
runAllTimers(): void; | ||
runOnlyPendingTimers(): void; | ||
advanceTimersByTime(msToRun: number): void; | ||
runTimersToTime(msToRun: number): void; | ||
getTimerCount(): number; | ||
setMock(moduleName: string, moduleExports: any): Jest; | ||
setTimeout(timeout: number): Jest; | ||
spyOn: typeof moduleMocker.spyOn; | ||
unmock(moduleName: string): Jest; | ||
useFakeTimers(): Jest; | ||
useRealTimers(): Jest; | ||
isolateModules(fn: () => void): Jest; | ||
}; |
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,12 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "build" | ||
}, | ||
"references": [ | ||
{"path": "../jest-transform"}, | ||
{"path": "../jest-types"}, | ||
{"path": "../jest-util"} | ||
] | ||
} |
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
9 changes: 3 additions & 6 deletions
9
packages/jest-runtime/src/helpers.js → packages/jest-runtime/src/helpers.ts
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.