Skip to content

Commit

Permalink
Command arguments do not work with jest, using environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
markis committed Feb 23, 2018
1 parent 71aa327 commit c722101
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, watch } from 'fs';
import parser from 'yargs-parser';

import { getLastError } from './errors';
import {
Expand All @@ -24,8 +23,7 @@ export default class JestRatchet {
globalConfig: Config,
options: RatchetOptions = {},
) {
const args = parser(process.argv.slice(2));
if (!args.disableRatchet) {
if (!process.env.DISABLE_JEST_RATCHET) {
this.onRunComplete = onRunComplete.bind(this, globalConfig, options);
this.getLastError = getLastError.bind(this, globalConfig);
}
Expand Down
5 changes: 4 additions & 1 deletion src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ const mockConfig = {
};

const originalArgv = process.argv;
const originalEnv = process.env;

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

it('will initialize without error', () => {
Expand Down Expand Up @@ -55,7 +58,7 @@ describe('jest-ratchet', () => {
});

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

const jestRatchet = new JestRatchet(mockConfig);

Expand Down

0 comments on commit c722101

Please sign in to comment.