Skip to content

Commit

Permalink
chore: use more private (#7882)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 13, 2019
1 parent f27d1c1 commit 0cf47c4
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 84 deletions.
24 changes: 12 additions & 12 deletions packages/jest-haste-map/src/index.ts
Expand Up @@ -219,14 +219,14 @@ const getWhiteList = (list: Array<string> | undefined): RegExp | null => {
*
*/
class HasteMap extends EventEmitter {
_buildPromise: Promise<HasteMapObject> | null;
_cachePath: Config.Path;
_changeInterval?: NodeJS.Timeout;
_console: Console;
_options: InternalOptions;
_watchers: Array<Watcher>;
_whitelist: RegExp | null;
_worker: WorkerInterface | null;
private _buildPromise: Promise<HasteMapObject> | null;
private _cachePath: Config.Path;
private _changeInterval?: NodeJS.Timeout;
private _console: Console;
private _options: InternalOptions;
private _watchers: Array<Watcher>;
private _whitelist: RegExp | null;
private _worker: WorkerInterface | null;

constructor(options: Options) {
super();
Expand Down Expand Up @@ -381,7 +381,7 @@ class HasteMap extends EventEmitter {
/**
* 2. crawl the file system.
*/
_buildFileMap(): Promise<{
private _buildFileMap(): Promise<{
deprecatedFiles: Array<{moduleName: string; path: string}>;
hasteMap: InternalHasteMap;
}> {
Expand All @@ -408,7 +408,7 @@ class HasteMap extends EventEmitter {
/**
* 3. parse and extract metadata from changed files.
*/
_processFile(
private _processFile(
hasteMap: InternalHasteMap,
map: ModuleMapData,
mocks: MockData,
Expand Down Expand Up @@ -604,7 +604,7 @@ class HasteMap extends EventEmitter {
.then(workerReply, workerError);
}

_buildHasteMap(data: {
private _buildHasteMap(data: {
deprecatedFiles: Array<{moduleName: string; path: string}>;
hasteMap: InternalHasteMap;
}): Promise<InternalHasteMap> {
Expand Down Expand Up @@ -643,7 +643,7 @@ class HasteMap extends EventEmitter {
});
}

_cleanup() {
private _cleanup() {
const worker = this._worker;

// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-mock/src/index.ts
Expand Up @@ -73,7 +73,7 @@ interface Mock<T, Y extends unknown[] = unknown[]>
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;
Expand Down
56 changes: 30 additions & 26 deletions packages/jest-util/src/FakeTimers.ts
Expand Up @@ -51,21 +51,21 @@ type TimerConfig<Ref> = {
const MS_IN_A_YEAR = 31536000000;

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!: {[key: string]: boolean};
private _cancelledTicks!: {[key: string]: boolean};
private _config: StackTraceConfig;
private _disposed?: boolean;
private _fakeTimerAPIs!: TimerAPI;
private _global: NodeJS.Global;
private _immediates!: Array<Tick>;
private _maxLoops: number;
private _moduleMocker: ModuleMocker;
private _now!: number;
private _ticks!: Array<Tick>;
private _timerAPIs: TimerAPI;
private _timers!: {[key: string]: Timer};
private _uuidCounter: number;
private _timerConfig: TimerConfig<TimerRef>;

constructor({
global,
Expand Down Expand Up @@ -176,7 +176,7 @@ export default class FakeTimers<TimerRef> {
}
}

_runImmediate(immediate: Tick) {
private _runImmediate(immediate: Tick) {
if (!this._cancelledImmediates.hasOwnProperty(immediate.uuid)) {
// Callback may throw, so update the map prior calling.
this._cancelledImmediates[immediate.uuid] = true;
Expand Down Expand Up @@ -334,7 +334,7 @@ export default class FakeTimers<TimerRef> {
return Object.keys(this._timers).length;
}

_checkFakeTimers() {
private _checkFakeTimers() {
if (this._global.setTimeout !== this._fakeTimerAPIs.setTimeout) {
this._global.console.warn(
`A function to advance timers was called but the timers API is not ` +
Expand All @@ -352,7 +352,7 @@ export default class FakeTimers<TimerRef> {
}
}

_createMocks() {
private _createMocks() {
const fn = (impl: Function) =>
// @ts-ignore TODO: figure out better typings here
this._moduleMocker.fn().mockImplementation(impl);
Expand All @@ -369,19 +369,19 @@ export default class FakeTimers<TimerRef> {
};
}

_fakeClearTimer(timerRef: TimerRef) {
private _fakeClearTimer(timerRef: TimerRef) {
const uuid = this._timerConfig.refToId(timerRef);

if (uuid && this._timers.hasOwnProperty(uuid)) {
delete this._timers[String(uuid)];
}
}

_fakeClearImmediate(uuid: TimerID) {
private _fakeClearImmediate(uuid: TimerID) {
this._cancelledImmediates[uuid] = true;
}

_fakeNextTick(callback: Callback, ...args: Array<any>) {
private _fakeNextTick(callback: Callback, ...args: Array<any>) {
if (this._disposed) {
return;
}
Expand All @@ -403,7 +403,7 @@ export default class FakeTimers<TimerRef> {
});
}

_fakeSetImmediate(callback: Callback, ...args: Array<any>) {
private _fakeSetImmediate(callback: Callback, ...args: Array<any>) {
if (this._disposed) {
return null;
}
Expand All @@ -427,7 +427,7 @@ export default class FakeTimers<TimerRef> {
return uuid;
}

_fakeSetInterval(
private _fakeSetInterval(
callback: Callback,
intervalDelay?: number,
...args: Array<any>
Expand All @@ -452,7 +452,11 @@ export default class FakeTimers<TimerRef> {
return this._timerConfig.idToRef(uuid);
}

_fakeSetTimeout(callback: Callback, delay?: number, ...args: Array<any>) {
private _fakeSetTimeout(
callback: Callback,
delay?: number,
...args: Array<any>
) {
if (this._disposed) {
return null;
}
Expand All @@ -472,7 +476,7 @@ export default class FakeTimers<TimerRef> {
return this._timerConfig.idToRef(uuid);
}

_getNextTimerHandle() {
private _getNextTimerHandle() {
let nextTimerHandle = null;
let uuid;
let soonestTime = MS_IN_A_YEAR;
Expand All @@ -488,7 +492,7 @@ export default class FakeTimers<TimerRef> {
return nextTimerHandle;
}

_runTimerHandle(timerHandle: TimerID) {
private _runTimerHandle(timerHandle: TimerID) {
const timer = this._timers[timerHandle];

if (!timer) {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-watcher/src/BaseWatchPlugin.ts
Expand Up @@ -8,8 +8,8 @@
import {WatchPlugin} from './types';

class BaseWatchPlugin implements WatchPlugin {
_stdin: NodeJS.ReadableStream;
_stdout: NodeJS.WritableStream;
protected _stdin: NodeJS.ReadableStream;
protected _stdout: NodeJS.WritableStream;

constructor({
stdin,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-watcher/src/JestHooks.ts
Expand Up @@ -19,7 +19,7 @@ type AvailableHooks =
| 'shouldRunTestSuite';

class JestHooks {
_listeners: {
private _listeners: {
onFileChange: Array<FileChange>;
onTestRunComplete: Array<TestRunComplete>;
shouldRunTestSuite: Array<ShouldRunTestSuite>;
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-watcher/src/PatternPrompt.ts
Expand Up @@ -22,10 +22,10 @@ const usage = (entity: string) =>
const usageRows = usage('').split('\n').length;

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) {
// TODO: Should come in the constructor
Expand Down
16 changes: 8 additions & 8 deletions packages/jest-watcher/src/lib/Prompt.ts
Expand Up @@ -9,14 +9,14 @@ import {ScrollOptions} from '../types';
import {KEYS} from '../constants';

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: boolean;
private _value: string;
private _onChange: () => void;
private _onSuccess: (value?: string) => void;
private _onCancel: (value?: string) => void;
private _offset: number;
private _promptLength: number;
private _selection: string | null;

constructor() {
// Copied from `enter` to satisfy TS
Expand Down
24 changes: 12 additions & 12 deletions packages/jest-worker/src/Farm.ts
Expand Up @@ -16,14 +16,14 @@ import {
} 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: FarmOptions['computeWorkerKey'];
private _cacheKeys: {[key: string]: WorkerInterface};
private _callback: Function;
private _last: Array<QueueChildMessage>;
private _locks: Array<boolean>;
private _numOfWorkers: number;
private _offset: number;
private _queue: Array<QueueChildMessage | null>;

constructor(
numOfWorkers: number,
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class Farm {
});
}

_getNextJob(workerId: number): QueueChildMessage | null {
private _getNextJob(workerId: number): QueueChildMessage | null {
let queueHead = this._queue[workerId];

while (queueHead && queueHead.request[1]) {
Expand All @@ -90,7 +90,7 @@ export default class Farm {
return queueHead;
}

_process(workerId: number): Farm {
private _process(workerId: number): Farm {
if (this.isLocked(workerId)) {
return this;
}
Expand All @@ -116,7 +116,7 @@ export default class Farm {
return this;
}

_enqueue(task: QueueChildMessage, workerId: number): Farm {
private _enqueue(task: QueueChildMessage, workerId: number): Farm {
if (task.request[1]) {
return this;
}
Expand All @@ -133,7 +133,7 @@ export default class Farm {
return this;
}

_push(task: QueueChildMessage): Farm {
private _push(task: QueueChildMessage): Farm {
for (let i = 0; i < this._numOfWorkers; i++) {
const workerIdx = (this._offset + i) % this._numOfWorkers;
this._enqueue(task, workerIdx);
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-worker/src/base/BaseWorkerPool.ts
Expand Up @@ -19,10 +19,10 @@ import {
const emptyMethod = () => {};

export default class BaseWorkerPool {
_stderr: NodeJS.ReadableStream;
_stdout: NodeJS.ReadableStream;
_options: WorkerPoolOptions;
_workers: Array<WorkerInterface>;
private readonly _stderr: NodeJS.ReadableStream;
private readonly _stdout: NodeJS.ReadableStream;
protected readonly _options: WorkerPoolOptions;
private readonly _workers: Array<WorkerInterface>;

constructor(workerPath: string, options: WorkerPoolOptions) {
this._options = options;
Expand Down
18 changes: 12 additions & 6 deletions packages/jest-worker/src/index.ts
Expand Up @@ -59,10 +59,10 @@ function getExposedMethods(
* caching results.
*/
export default class JestWorker {
_ending: boolean;
_farm: Farm;
_options: FarmOptions;
_workerPool: WorkerPoolInterface;
private _ending: boolean;
private _farm: Farm;
private _options: FarmOptions;
private _workerPool: WorkerPoolInterface;

constructor(workerPath: string, options?: FarmOptions) {
this._options = {...options};
Expand Down Expand Up @@ -95,7 +95,10 @@ export default class JestWorker {
this._bindExposedWorkerMethods(workerPath, this._options);
}

_bindExposedWorkerMethods(workerPath: string, options: FarmOptions): void {
private _bindExposedWorkerMethods(
workerPath: string,
options: FarmOptions,
): void {
getExposedMethods(workerPath, options).forEach(name => {
if (name.startsWith('_')) {
return;
Expand All @@ -110,7 +113,10 @@ export default class JestWorker {
});
}

_callFunctionWithArgs(method: string, ...args: Array<any>): Promise<any> {
private _callFunctionWithArgs(
method: string,
...args: Array<any>
): Promise<any> {
if (this._ending) {
throw new Error('Farm is ended, no more calls can be done to it');
}
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-worker/src/workers/ChildProcessWorker.ts
Expand Up @@ -40,10 +40,10 @@ import {
* same call skip it.
*/
export default class ChildProcessWorker implements WorkerInterface {
_child!: ChildProcess;
_options: WorkerOptions;
_onProcessEnd!: OnEnd;
_retries!: number;
private _child!: ChildProcess;
private _options: WorkerOptions;
private _onProcessEnd!: OnEnd;
private _retries!: number;

constructor(options: WorkerOptions) {
this._options = options;
Expand Down

0 comments on commit 0cf47c4

Please sign in to comment.