From 36b9f3b9685e12390eab7585bc77d65c16b82b96 Mon Sep 17 00:00:00 2001 From: Andrew M Date: Thu, 7 Feb 2019 14:14:40 +0300 Subject: [PATCH] Migrate jest-leak-detector to TypeScript (#7825) --- CHANGELOG.md | 1 + packages/jest-leak-detector/package.json | 1 + .../{index.test.js.snap => index.test.ts.snap} | 0 .../src/__tests__/{index.test.js => index.test.ts} | 4 ++-- .../jest-leak-detector/src/{index.js => index.ts} | 14 +++++--------- packages/jest-leak-detector/tsconfig.json | 10 ++++++++++ 6 files changed, 19 insertions(+), 11 deletions(-) rename packages/jest-leak-detector/src/__tests__/__snapshots__/{index.test.js.snap => index.test.ts.snap} (100%) rename packages/jest-leak-detector/src/__tests__/{index.test.js => index.test.ts} (98%) rename packages/jest-leak-detector/src/{index.js => index.ts} (91%) create mode 100644 packages/jest-leak-detector/tsconfig.json diff --git a/CHANGELOG.md b/CHANGELOG.md index eed385502916..cef9079de837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - `[jest-get-type]`: Migrate to TypeScript ([#7818](https://github.com/facebook/jest/pull/7818)) - `[jest-regex-util]`: Migrate to TypeScript ([#7822](https://github.com/facebook/jest/pull/7822)) - `[jest-diff]`: Migrate to TypeScript ([#7824](https://github.com/facebook/jest/pull/7824)) +- `[jest-leak-detector]`: Migrate to TypeScript ([#7825](https://github.com/facebook/jest/pull/7825)) ### Performance diff --git a/packages/jest-leak-detector/package.json b/packages/jest-leak-detector/package.json index 434f904dcf62..eaeb90409094 100644 --- a/packages/jest-leak-detector/package.json +++ b/packages/jest-leak-detector/package.json @@ -8,6 +8,7 @@ }, "license": "MIT", "main": "build/index.js", + "types": "build/index.d.ts", "dependencies": { "pretty-format": "^24.0.0" }, diff --git a/packages/jest-leak-detector/src/__tests__/__snapshots__/index.test.js.snap b/packages/jest-leak-detector/src/__tests__/__snapshots__/index.test.ts.snap similarity index 100% rename from packages/jest-leak-detector/src/__tests__/__snapshots__/index.test.js.snap rename to packages/jest-leak-detector/src/__tests__/__snapshots__/index.test.ts.snap diff --git a/packages/jest-leak-detector/src/__tests__/index.test.js b/packages/jest-leak-detector/src/__tests__/index.test.ts similarity index 98% rename from packages/jest-leak-detector/src/__tests__/index.test.js rename to packages/jest-leak-detector/src/__tests__/index.test.ts index b4499ec20d2e..188aaf4cf920 100644 --- a/packages/jest-leak-detector/src/__tests__/index.test.js +++ b/packages/jest-leak-detector/src/__tests__/index.test.ts @@ -73,8 +73,8 @@ it('tests different objects', () => { }); it('correctly checks more complex leaks', () => { - let ref1 = {}; - let ref2 = {}; + let ref1: any = {}; + let ref2: any = {}; // Create a circular dependency between ref1 and ref2. ref1.ref2 = ref2; diff --git a/packages/jest-leak-detector/src/index.js b/packages/jest-leak-detector/src/index.ts similarity index 91% rename from packages/jest-leak-detector/src/index.js rename to packages/jest-leak-detector/src/index.ts index d9e97788a406..007b907fad6e 100644 --- a/packages/jest-leak-detector/src/index.js +++ b/packages/jest-leak-detector/src/index.ts @@ -3,20 +3,16 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -'use strict'; - -import prettyFormat from 'pretty-format'; import v8 from 'v8'; import vm from 'vm'; +import prettyFormat from 'pretty-format'; export default class { - _isReferenceBeingHeld: boolean; + private _isReferenceBeingHeld: boolean; - constructor(value: ?Object) { + constructor(value: unknown) { if (this._isPrimitive(value)) { throw new TypeError( [ @@ -55,7 +51,7 @@ export default class { return this._isReferenceBeingHeld; } - _runGarbageCollector() { + private _runGarbageCollector() { const isGarbageCollectorHidden = !global.gc; // GC is usually hidden, so we have to expose it before running. @@ -68,7 +64,7 @@ export default class { } } - _isPrimitive(value: any): boolean { + private _isPrimitive(value: unknown): boolean { return value !== Object(value); } } diff --git a/packages/jest-leak-detector/tsconfig.json b/packages/jest-leak-detector/tsconfig.json new file mode 100644 index 000000000000..3e70b10372b1 --- /dev/null +++ b/packages/jest-leak-detector/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../pretty-format"} + ] +}