Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use more private #7882

Merged
merged 2 commits into from
Feb 13, 2019
Merged

chore: use more private #7882

merged 2 commits into from
Feb 13, 2019

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Feb 13, 2019

Summary

Guides consumers away from private APIs. Also makes the type definitions smaller in some cases since we don't expose as much

Built diff:

diff --git i/packages/jest-mock/build/index.d.ts w/packages/jest-mock/build/index.d.ts
index 5dfae37ba..42348609a 100644
--- i/packages/jest-mock/build/index.d.ts
+++ w/packages/jest-mock/build/index.d.ts
@@ -51,7 +51,7 @@ interface Mock<T, Y extends unknown[] = unknown[]> extends Function, MockInstanc
 interface SpyInstance<T, Y extends unknown[]> extends MockInstance<T, Y> {
 }
 interface MockInstance<T, Y extends unknown[]> {
-    _isMockFunction: boolean;
+    _isMockFunction: true;
     _protoImpl: Function;
     getMockName(): string;
     getMockImplementation(): Function | undefined;
diff --git i/packages/jest-util/build/FakeTimers.d.ts w/packages/jest-util/build/FakeTimers.d.ts
index 75850864c..324976b7d 100644
--- i/packages/jest-util/build/FakeTimers.d.ts
+++ w/packages/jest-util/build/FakeTimers.d.ts
@@ -12,52 +12,26 @@ declare type ModuleMocker = typeof mock;
  * we are disabling the flowtype/no-weak-types rule here.
  */
 declare type Callback = (...args: any) => void;
-declare type TimerID = string;
-declare type Tick = {
-    uuid: string;
-    callback: Callback;
-};
-declare type Timer = {
-    type: string;
-    callback: Callback;
-    expiry: number;
-    interval?: number;
-};
-declare type TimerAPI = {
-    clearImmediate: typeof global.clearImmediate;
-    clearInterval: typeof global.clearInterval;
-    clearTimeout: typeof global.clearTimeout;
-    nextTick: typeof process.nextTick;
-    setImmediate: typeof global.setImmediate;
-    setInterval: typeof global.setInterval;
-    setTimeout: typeof global.setTimeout;
-};
 declare type TimerConfig<Ref> = {
     idToRef: (id: number) => Ref;
     refToId: (ref: Ref) => number | void;
 };
 export default class FakeTimers<TimerRef> {
-    _cancelledImmediates: {
-        [key: string]: boolean;
-    };
-    _cancelledTicks: {
-        [key: string]: boolean;
-    };
-    _config: StackTraceConfig;
-    _disposed?: boolean;
-    _fakeTimerAPIs: TimerAPI;
-    _global: NodeJS.Global;
-    _immediates: Array<Tick>;
-    _maxLoops: number;
-    _moduleMocker: ModuleMocker;
-    _now: number;
-    _ticks: Array<Tick>;
-    _timerAPIs: TimerAPI;
-    _timers: {
-        [key: string]: Timer;
-    };
-    _uuidCounter: number;
-    _timerConfig: TimerConfig<TimerRef>;
+    private _cancelledImmediates;
+    private _cancelledTicks;
+    private _config;
+    private _disposed?;
+    private _fakeTimerAPIs;
+    private _global;
+    private _immediates;
+    private _maxLoops;
+    private _moduleMocker;
+    private _now;
+    private _ticks;
+    private _timerAPIs;
+    private _timers;
+    private _uuidCounter;
+    private _timerConfig;
     constructor({ global, moduleMocker, timerConfig, config, maxLoops, }: {
         global: NodeJS.Global;
         moduleMocker: ModuleMocker;
@@ -70,7 +44,7 @@ export default class FakeTimers<TimerRef> {
     reset(): void;
     runAllTicks(): void;
     runAllImmediates(): void;
-    _runImmediate(immediate: Tick): void;
+    private _runImmediate;
     runAllTimers(): void;
     runOnlyPendingTimers(): void;
     advanceTimersByTime(msToRun: number): void;
@@ -78,16 +52,16 @@ export default class FakeTimers<TimerRef> {
     useRealTimers(): void;
     useFakeTimers(): void;
     getTimerCount(): number;
-    _checkFakeTimers(): void;
-    _createMocks(): void;
-    _fakeClearTimer(timerRef: TimerRef): void;
-    _fakeClearImmediate(uuid: TimerID): void;
-    _fakeNextTick(callback: Callback, ...args: Array<any>): void;
-    _fakeSetImmediate(callback: Callback, ...args: Array<any>): number | null;
-    _fakeSetInterval(callback: Callback, intervalDelay?: number, ...args: Array<any>): TimerRef | null;
-    _fakeSetTimeout(callback: Callback, delay?: number, ...args: Array<any>): TimerRef | null;
-    _getNextTimerHandle(): string | null;
-    _runTimerHandle(timerHandle: TimerID): void;
+    private _checkFakeTimers;
+    private _createMocks;
+    private _fakeClearTimer;
+    private _fakeClearImmediate;
+    private _fakeNextTick;
+    private _fakeSetImmediate;
+    private _fakeSetInterval;
+    private _fakeSetTimeout;
+    private _getNextTimerHandle;
+    private _runTimerHandle;
 }
 export {};
 //# sourceMappingURL=FakeTimers.d.ts.map
\ No newline at end of file
diff --git i/packages/jest-watcher/build/BaseWatchPlugin.d.ts w/packages/jest-watcher/build/BaseWatchPlugin.d.ts
index 5a2c698cb..f15b66222 100644
--- i/packages/jest-watcher/build/BaseWatchPlugin.d.ts
+++ w/packages/jest-watcher/build/BaseWatchPlugin.d.ts
@@ -6,8 +6,8 @@
  */
 import { WatchPlugin } from './types';
 declare class BaseWatchPlugin implements WatchPlugin {
-    _stdin: NodeJS.ReadableStream;
-    _stdout: NodeJS.WritableStream;
+    protected _stdin: NodeJS.ReadableStream;
+    protected _stdout: NodeJS.WritableStream;
     constructor({ stdin, stdout, }: {
         stdin: NodeJS.ReadableStream;
         stdout: NodeJS.WritableStream;
diff --git i/packages/jest-watcher/build/JestHooks.d.ts w/packages/jest-watcher/build/JestHooks.d.ts
index e9fd7d2fd..31e82d7d1 100644
--- i/packages/jest-watcher/build/JestHooks.d.ts
+++ w/packages/jest-watcher/build/JestHooks.d.ts
@@ -4,14 +4,10 @@
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
  */
-import { JestHookSubscriber, JestHookEmitter, FileChange, ShouldRunTestSuite, TestRunComplete } from './types';
+import { JestHookSubscriber, JestHookEmitter } from './types';
 declare type AvailableHooks = 'onFileChange' | 'onTestRunComplete' | 'shouldRunTestSuite';
 declare class JestHooks {
-    _listeners: {
-        onFileChange: Array<FileChange>;
-        onTestRunComplete: Array<TestRunComplete>;
-        shouldRunTestSuite: Array<ShouldRunTestSuite>;
-    };
+    private _listeners;
     constructor();
     isUsed(hook: AvailableHooks): number;
     getSubscriber(): JestHookSubscriber;
diff --git i/packages/jest-watcher/build/PatternPrompt.d.ts w/packages/jest-watcher/build/PatternPrompt.d.ts
index 6486482d3..3ac674e71 100644
--- i/packages/jest-watcher/build/PatternPrompt.d.ts
+++ w/packages/jest-watcher/build/PatternPrompt.d.ts
@@ -6,10 +6,10 @@
  */
 import Prompt from './lib/Prompt';
 export default class PatternPrompt {
-    _pipe: NodeJS.WritableStream;
-    _prompt: Prompt;
-    _entityName: string;
-    _currentUsageRows: number;
+    protected _pipe: NodeJS.WritableStream;
+    protected _prompt: Prompt;
+    protected _entityName: string;
+    protected _currentUsageRows: number;
     constructor(pipe: NodeJS.WritableStream, prompt: Prompt);
     run(onSuccess: () => void, onCancel: () => void, options?: {
         header: string;
diff --git i/packages/jest-watcher/build/lib/Prompt.d.ts w/packages/jest-watcher/build/lib/Prompt.d.ts
index 5f94140e6..259353aa6 100644
--- i/packages/jest-watcher/build/lib/Prompt.d.ts
+++ w/packages/jest-watcher/build/lib/Prompt.d.ts
@@ -6,14 +6,14 @@
  */
 import { ScrollOptions } from '../types';
 export default class Prompt {
-    _entering: boolean;
-    _value: string;
-    _onChange: () => void;
-    _onSuccess: (value?: string) => void;
-    _onCancel: (value?: string) => void;
-    _offset: number;
-    _promptLength: number;
-    _selection: string | null;
+    private _entering;
+    private _value;
+    private _onChange;
+    private _onSuccess;
+    private _onCancel;
+    private _offset;
+    private _promptLength;
+    private _selection;
     constructor();
     private _onResize;
     enter(onChange: (pattern: string, options: ScrollOptions) => void, onSuccess: () => void, onCancel: () => void): void;
diff --git i/packages/jest-worker/build/Farm.d.ts w/packages/jest-worker/build/Farm.d.ts
index 327738cb8..69da4106d 100644
--- i/packages/jest-worker/build/Farm.d.ts
+++ w/packages/jest-worker/build/Farm.d.ts
@@ -4,24 +4,22 @@
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
  */
-import { FarmOptions, QueueChildMessage, WorkerInterface } from './types';
+import { FarmOptions } from './types';
 export default class Farm {
-    _computeWorkerKey: FarmOptions['computeWorkerKey'];
-    _cacheKeys: {
-        [key: string]: WorkerInterface;
-    };
-    _callback: Function;
-    _last: Array<QueueChildMessage>;
-    _locks: Array<boolean>;
-    _numOfWorkers: number;
-    _offset: number;
-    _queue: Array<QueueChildMessage | null>;
+    private _computeWorkerKey;
+    private _cacheKeys;
+    private _callback;
+    private _last;
+    private _locks;
+    private _numOfWorkers;
+    private _offset;
+    private _queue;
     constructor(numOfWorkers: number, callback: Function, computeWorkerKey?: FarmOptions['computeWorkerKey']);
     doWork(method: string, ...args: Array<any>): Promise<unknown>;
-    _getNextJob(workerId: number): QueueChildMessage | null;
-    _process(workerId: number): Farm;
-    _enqueue(task: QueueChildMessage, workerId: number): Farm;
-    _push(task: QueueChildMessage): Farm;
+    private _getNextJob;
+    private _process;
+    private _enqueue;
+    private _push;
     lock(workerId: number): void;
     unlock(workerId: number): void;
     isLocked(workerId: number): boolean;
diff --git i/packages/jest-worker/build/base/BaseWorkerPool.d.ts w/packages/jest-worker/build/base/BaseWorkerPool.d.ts
index 21856415b..2ec7b7c8a 100644
--- i/packages/jest-worker/build/base/BaseWorkerPool.d.ts
+++ w/packages/jest-worker/build/base/BaseWorkerPool.d.ts
@@ -6,10 +6,10 @@
  */
 import { WorkerPoolOptions, WorkerOptions, WorkerInterface } from '../types';
 export default class BaseWorkerPool {
-    _stderr: NodeJS.ReadableStream;
-    _stdout: NodeJS.ReadableStream;
-    _options: WorkerPoolOptions;
-    _workers: Array<WorkerInterface>;
+    private readonly _stderr;
+    private readonly _stdout;
+    protected readonly _options: WorkerPoolOptions;
+    private readonly _workers;
     constructor(workerPath: string, options: WorkerPoolOptions);
     getStderr(): NodeJS.ReadableStream;
     getStdout(): NodeJS.ReadableStream;
diff --git i/packages/jest-worker/build/index.d.ts w/packages/jest-worker/build/index.d.ts
index 65c27f3a5..f0537c7e6 100644
--- i/packages/jest-worker/build/index.d.ts
+++ w/packages/jest-worker/build/index.d.ts
@@ -4,8 +4,7 @@
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
  */
-import Farm from './Farm';
-import { WorkerPoolInterface, FarmOptions } from './types';
+import { FarmOptions } from './types';
 /**
  * The Jest farm (publicly called "Worker") is a class that allows you to queue
  * methods across multiple child processes, in order to parallelize work. This
@@ -32,13 +31,13 @@ import { WorkerPoolInterface, FarmOptions } from './types';
  *   caching results.
  */
 export default class JestWorker {
-    _ending: boolean;
-    _farm: Farm;
-    _options: FarmOptions;
-    _workerPool: WorkerPoolInterface;
+    private _ending;
+    private _farm;
+    private _options;
+    private _workerPool;
     constructor(workerPath: string, options?: FarmOptions);
-    _bindExposedWorkerMethods(workerPath: string, options: FarmOptions): void;
-    _callFunctionWithArgs(method: string, ...args: Array<any>): Promise<any>;
+    private _bindExposedWorkerMethods;
+    private _callFunctionWithArgs;
     getStderr(): NodeJS.ReadableStream;
     getStdout(): NodeJS.ReadableStream;
     end(): void;
diff --git i/packages/jest-worker/build/workers/ChildProcessWorker.d.ts w/packages/jest-worker/build/workers/ChildProcessWorker.d.ts
index 07d42cff6..fbc01f0f9 100644
--- i/packages/jest-worker/build/workers/ChildProcessWorker.d.ts
+++ w/packages/jest-worker/build/workers/ChildProcessWorker.d.ts
@@ -4,7 +4,6 @@
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
  */
-import { ChildProcess } from 'child_process';
 import { WorkerInterface, ChildMessage, OnEnd, OnStart, WorkerOptions, ParentMessage } from '../types';
 /**
  * This class wraps the child process and provides a nice interface to
@@ -25,10 +24,10 @@ import { WorkerInterface, ChildMessage, OnEnd, OnStart, WorkerOptions, ParentMes
  * same call skip it.
  */
 export default class ChildProcessWorker implements WorkerInterface {
-    _child: ChildProcess;
-    _options: WorkerOptions;
-    _onProcessEnd: OnEnd;
-    _retries: number;
+    private _child;
+    private _options;
+    private _onProcessEnd;
+    private _retries;
     constructor(options: WorkerOptions);
     initialize(): void;
     onMessage(response: ParentMessage): void;
diff --git i/packages/jest-worker/build/workers/NodeThreadsWorker.d.ts w/packages/jest-worker/build/workers/NodeThreadsWorker.d.ts
index d6a7631c8..71c6f158b 100644
--- i/packages/jest-worker/build/workers/NodeThreadsWorker.d.ts
+++ w/packages/jest-worker/build/workers/NodeThreadsWorker.d.ts
@@ -4,13 +4,12 @@
  * This source code is licensed under the MIT license found in the
  * LICENSE file in the root directory of this source tree.
  */
-import { Worker } from 'worker_threads';
 import { ChildMessage, OnEnd, OnStart, WorkerOptions, WorkerInterface, ParentMessage } from '../types';
 export default class ExperimentalWorker implements WorkerInterface {
-    _worker: Worker;
-    _options: WorkerOptions;
-    _onProcessEnd: OnEnd;
-    _retries: number;
+    private _worker;
+    private _options;
+    private _onProcessEnd;
+    private _retries;
     constructor(options: WorkerOptions);
     initialize(): void;
     onMessage(response: ParentMessage): void;

Test plan

Nothing really, except looking at the diff above. Build should still be green since we don't use anything now hidden

Copy link
Contributor

@mattphillips mattphillips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SimenB SimenB added this to the TypeScript Migration milestone Feb 13, 2019
@SimenB SimenB merged commit 0cf47c4 into jestjs:master Feb 13, 2019
@SimenB SimenB deleted the ts-private branch February 13, 2019 13:17
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants