Skip to content

Commit

Permalink
Merge 34d4a29 into 7f6bbe6
Browse files Browse the repository at this point in the history
  • Loading branch information
markis authored Feb 20, 2018
2 parents 7f6bbe6 + 34d4a29 commit 37ce721
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, watch } from 'fs';
import parser from 'yargs-parser';

import { getLastError } from './errors';
import {
Expand All @@ -12,18 +13,22 @@ import {
findCoverageSummaryPath,
findJestConfigPath,
} from './locations';
import { noop } from './noop';
import { ratchetCoverage } from './ratchet';

export default class JestRatchet {
public getLastError: () => void;
public onRunComplete: () => void;
public getLastError: () => void = noop;
public onRunComplete: () => void = noop;

constructor(
globalConfig: Config,
options: RatchetOptions = {},
) {
this.onRunComplete = onRunComplete.bind(this, globalConfig, options);
this.getLastError = getLastError.bind(this, globalConfig);
const args = parser(process.argv.slice(2));
if (!args.disableRatchet) {
this.onRunComplete = onRunComplete.bind(this, globalConfig, options);
this.getLastError = getLastError.bind(this, globalConfig);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function noop() {
// do nothing
}
12 changes: 12 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ jest.mock('fs');
import _fs from 'fs';
import { resolve } from 'path';
import JestRatchet from './index';
import { noop } from './noop';

const fs = _fs as typeof _fs & {
__addMockFile: (name: RegExp, value: string) => void;
Expand All @@ -14,11 +15,14 @@ const mockConfig = {
coverageReporters: ['json-summary'],
};

const originalArgv = process.argv;

describe('jest-ratchet', () => {
beforeEach(() => {
jest.resetAllMocks();
fs.__resetMockFiles();
process.cwd = jest.fn().mockReturnValue(resolve('./example'));
process.argv = originalArgv;
});

it('will initialize without error', () => {
Expand Down Expand Up @@ -50,6 +54,14 @@ describe('jest-ratchet', () => {
jestRatchet.onRunComplete();
});

it('will do nothing when ratchet is disabled', () => {
process.argv = ['', '', '--disable-ratchet'];

const jestRatchet = new JestRatchet(mockConfig);

expect(jestRatchet.onRunComplete).toBe(noop);
});

it('will ratchet percentages', () => {
const threshold = {
coverageThreshold: {
Expand Down

0 comments on commit 37ce721

Please sign in to comment.