Skip to content

Commit

Permalink
refactor: drop I prefix for interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Apr 21, 2019
1 parent 357a0f2 commit e2b8ff7
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 101 deletions.
8 changes: 4 additions & 4 deletions src/benchmark/index.ts
Expand Up @@ -3,14 +3,14 @@ import rimraf = require('rimraf');

import * as fixtures from './fixtures';
import * as logger from './logger';
import Runner, { IRunnerOptions } from './runner';
import Runner, { RunnerOptions } from './runner';
import * as utils from './utils';

interface IArgv extends IRunnerOptions {
interface Arguments extends RunnerOptions {
basedir: string;
}

const defaultArgv: IArgv = {
const defaultArgv: Arguments = {
basedir: '.benchmark',
type: 'async',
depth: utils.getEnvAsInteger('BENCHMARK_DEPTH') || 1,
Expand All @@ -19,7 +19,7 @@ const defaultArgv: IArgv = {
retries: utils.getEnvAsInteger('BENCHMARK_RETRIES') || 5
};

const argv = minimist<IArgv>(process.argv.slice(2), {
const argv = minimist<Arguments>(process.argv.slice(2), {
default: defaultArgv
});

Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/reporter.spec.ts
@@ -1,10 +1,10 @@
import * as assert from 'assert';

import Reporter from './reporter';
import { ISuitePackResult } from './runner';
import { SuitePackResult } from './runner';

describe('Benchmark → Reporter', () => {
const results: ISuitePackResult = {
const results: SuitePackResult = {
name: 'name',
errors: 0,
retries: 1,
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/reporter.ts
@@ -1,7 +1,7 @@
import { ISuitePackResult } from './runner';
import { SuitePackResult } from './runner';

export default class Reporter {
constructor(private readonly results: ISuitePackResult) { }
constructor(private readonly results: SuitePackResult) { }

public toString(): string {
return this.header + '\n' + this.measures + ' | ' + this.meta;
Expand Down
18 changes: 9 additions & 9 deletions src/benchmark/runner.spec.ts
@@ -1,6 +1,6 @@
import * as assert from 'assert';

import Runner, { IRunnerOptions, ISuiteMeasures, ISuitePackResult } from './runner';
import Runner, { RunnerOptions, SuiteMeasures, SuitePackResult } from './runner';

class RunnerFakeProcess extends Runner {
public execNodeProcess(): string {
Expand All @@ -15,9 +15,9 @@ class RunnerFakeProcessError extends Runner {
}

class RunnerFakeReport extends RunnerFakeProcess {
public results: ISuitePackResult[] = [];
public results: SuitePackResult[] = [];

public report(results: ISuitePackResult): void {
public report(results: SuitePackResult): void {
this.results.push(results);
}

Expand All @@ -27,7 +27,7 @@ class RunnerFakeReport extends RunnerFakeProcess {
}

describe('Benchmark → Runner', () => {
const runnerOptions: IRunnerOptions = {
const runnerOptions: RunnerOptions = {
type: 'async',
depth: 1,
launches: 3,
Expand All @@ -37,9 +37,9 @@ describe('Benchmark → Runner', () => {

describe('.suite', () => {
it('should returns measures', () => {
const runner = new RunnerFakeProcess('basedir', {} as IRunnerOptions);
const runner = new RunnerFakeProcess('basedir', {} as RunnerOptions);

const expected: ISuiteMeasures = {
const expected: SuiteMeasures = {
matches: 1,
time: 1,
memory: 1
Expand All @@ -51,7 +51,7 @@ describe('Benchmark → Runner', () => {
});

it('should throw error', () => {
const runner = new RunnerFakeProcessError('basedir', {} as IRunnerOptions);
const runner = new RunnerFakeProcessError('basedir', {} as RunnerOptions);

assert.throws(() => runner.suite('suitePath'), /Ops! Broken suite run\./);
});
Expand All @@ -61,7 +61,7 @@ describe('Benchmark → Runner', () => {
it('should returns pack measures', () => {
const runner = new RunnerFakeProcess('basedir', runnerOptions);

const expected: ISuitePackResult = {
const expected: SuitePackResult = {
name: 'suitePath',
errors: 0,
retries: 1,
Expand All @@ -80,7 +80,7 @@ describe('Benchmark → Runner', () => {
it('should returns pack measures with errors', () => {
const runner = new RunnerFakeProcessError('basedir', runnerOptions);

const expected: ISuitePackResult = {
const expected: SuitePackResult = {
name: 'suitePath',
errors: 3,
retries: 1,
Expand Down
32 changes: 16 additions & 16 deletions src/benchmark/runner.ts
Expand Up @@ -6,7 +6,7 @@ import execa = require('execa');
import Reporter from './reporter';
import * as utils from './utils';

export interface IRunnerOptions {
export interface RunnerOptions {
/**
* The directory from which you want to take suites.
*/
Expand All @@ -29,34 +29,34 @@ export interface IRunnerOptions {
retries: number;
}

export interface ISuiteMeasures {
export interface SuiteMeasures {
matches: number;
time: number;
memory: number;
}

export interface IMeasure {
export interface Measure {
units: string;
raw: number[];
average: number;
stdev: number;
}

export interface ISuitePackMeasures extends Record<string, IMeasure> {
time: IMeasure;
memory: IMeasure;
export interface SuitePackMeasures extends Record<string, Measure> {
time: Measure;
memory: Measure;
}

export interface ISuitePackResult {
export interface SuitePackResult {
name: string;
errors: number;
entries: number;
retries: number;
measures: ISuitePackMeasures;
measures: SuitePackMeasures;
}

export default class Runner {
constructor(private readonly basedir: string, private readonly options: IRunnerOptions) { }
constructor(private readonly basedir: string, private readonly options: RunnerOptions) { }

/**
* Runs child process.
Expand All @@ -68,7 +68,7 @@ export default class Runner {
/**
* Runs a single suite in the child process and returns the measurements of his work.
*/
public suite(suitePath: string): ISuiteMeasures {
public suite(suitePath: string): SuiteMeasures {
const env: Record<string, string> = {
NODE_ENV: 'production',
BENCHMARK_CWD: this.basedir
Expand All @@ -77,7 +77,7 @@ export default class Runner {
const stdout = this.execNodeProcess([suitePath], { env, extendEnv: true });

try {
return JSON.parse(stdout) as ISuiteMeasures;
return JSON.parse(stdout) as SuiteMeasures;
} catch {
throw new TypeError('Ops! Broken suite run.');
}
Expand All @@ -86,8 +86,8 @@ export default class Runner {
/**
* Runs a pack of suites.
*/
public suitePack(suitePath: string, retries: number): ISuitePackResult {
const results: ISuitePackResult = {
public suitePack(suitePath: string, retries: number): SuitePackResult {
const results: SuitePackResult = {
name: path.basename(suitePath),
errors: 0,
entries: 0,
Expand Down Expand Up @@ -119,7 +119,7 @@ export default class Runner {
return results;
}

public report(result: ISuitePackResult): void {
public report(result: SuitePackResult): void {
const reporter = new Reporter(result);

const report = reporter.toString();
Expand Down Expand Up @@ -148,7 +148,7 @@ export default class Runner {
return fs.readdirSync(suitesPath).filter((suite) => suite.endsWith('.js'));
}

private getMeasures(raw: number[], units: string): IMeasure {
private getMeasures(raw: number[], units: string): Measure {
return {
units,
raw,
Expand All @@ -157,7 +157,7 @@ export default class Runner {
};
}

private getSuitePackMeasures(): ISuitePackMeasures {
private getSuitePackMeasures(): SuitePackMeasures {
return {
time: this.getMeasures([], 'ms'),
memory: this.getMeasures([], 'MB')
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/utils.ts
@@ -1,6 +1,6 @@
import stdev = require('compute-stdev');

import { ISuiteMeasures } from './runner';
import { SuiteMeasures } from './runner';

export function convertHrtimeToMilliseconds(hrtime: [number, number]): number {
const nanoseconds = (hrtime[0] * 1e9) + hrtime[1];
Expand All @@ -27,7 +27,7 @@ export function getMemory(): number {
}

export function getMeasures(matches: number, time: number, memory: number): string {
return JSON.stringify({ matches, time, memory } as ISuiteMeasures);
return JSON.stringify({ matches, time, memory } as SuiteMeasures);
}

export function getAverageValue(raw: number[]): number {
Expand Down
6 changes: 3 additions & 3 deletions src/index.spec.ts
@@ -1,7 +1,7 @@
import * as assert from 'assert';

import * as pkg from './index';
import { ITask } from './managers/tasks';
import { Task } from './managers/tasks';
import { EntryItem } from './types/entries';

describe('Package', () => {
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('Package', () => {
});

it('should return tasks', () => {
const expected: ITask[] = [{
const expected: Task[] = [{
base: '.',
dynamic: true,
patterns: ['*'],
Expand All @@ -169,7 +169,7 @@ describe('Package', () => {
});

it('should return tasks with negative patterns', () => {
const expected: ITask[] = [{
const expected: Task[] = [{
base: '.',
dynamic: true,
patterns: ['*', '!*.txt', '!*.md'],
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -9,7 +9,7 @@ import { Pattern } from './types/patterns';
import * as arrayUtils from './utils/array';
import * as streamUtils from './utils/stream';

type Task = taskManager.ITask;
type Task = taskManager.Task;

/**
* Synchronous API.
Expand Down
22 changes: 11 additions & 11 deletions src/managers/tasks.spec.ts
Expand Up @@ -3,14 +3,14 @@ import * as assert from 'assert';
import Settings from '../settings';
import { PatternsGroup } from '../types/patterns';
import * as manager from './tasks';
import { ITask } from './tasks';
import { Task } from './tasks';

describe('Managers → Task', () => {
describe('.generate', () => {
it('should return task with windows-like patterns', () => {
const settings = new Settings();

const expected: ITask[] = [{
const expected: Task[] = [{
base: 'a',
dynamic: true,
patterns: ['a/*'],
Expand All @@ -26,7 +26,7 @@ describe('Managers → Task', () => {
it('should return task with negative patterns from «ignore» option', () => {
const settings = new Settings({ ignore: ['*.txt'] });

const expected: ITask[] = [{
const expected: Task[] = [{
base: 'a',
dynamic: true,
patterns: ['a/*', '!*.md', '!*.txt'],
Expand All @@ -42,7 +42,7 @@ describe('Managers → Task', () => {
it('should return static and dynamic tasks', () => {
const settings = new Settings({ ignore: ['*.txt'] });

const expected: ITask[] = [
const expected: Task[] = [
{
base: 'a',
dynamic: false,
Expand All @@ -67,7 +67,7 @@ describe('Managers → Task', () => {

describe('.convertPatternsToTasks', () => {
it('should return global task when positive patterns have a global pattern', () => {
const expected: ITask[] = [{
const expected: Task[] = [{
base: '.',
dynamic: true,
patterns: ['*', '!*.md'],
Expand All @@ -81,7 +81,7 @@ describe('Managers → Task', () => {
});

it('should return global task with negative patterns from «ignore» patterns', () => {
const expected: ITask[] = [{
const expected: Task[] = [{
base: '.',
dynamic: true,
patterns: ['*', '!*.md'],
Expand All @@ -95,7 +95,7 @@ describe('Managers → Task', () => {
});

it('should return two tasks', () => {
const expected: ITask[] = [
const expected: Task[] = [
{
base: 'a',
dynamic: true,
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('Managers → Task', () => {

describe('.convertPatternGroupToTask', () => {
it('should return created dynamic task', () => {
const expected: ITask = {
const expected: Task = {
base: '.',
dynamic: true,
patterns: ['*', '!*.md'],
Expand All @@ -183,7 +183,7 @@ describe('Managers → Task', () => {
});

it('should return created static task', () => {
const expected: ITask = {
const expected: Task = {
base: '.',
dynamic: false,
patterns: ['file', '!file.md'],
Expand All @@ -199,7 +199,7 @@ describe('Managers → Task', () => {

describe('.convertPatternGroupsToTasks', () => {
it('should return one task without negative patterns', () => {
const expected: ITask[] = [{
const expected: Task[] = [{
base: 'a',
dynamic: true,
patterns: ['a/*'],
Expand All @@ -213,7 +213,7 @@ describe('Managers → Task', () => {
});

it('should return two tasks with negative patterns', () => {
const expected: ITask[] = [
const expected: Task[] = [
{
base: 'a',
dynamic: true,
Expand Down

0 comments on commit e2b8ff7

Please sign in to comment.