Skip to content

Commit

Permalink
Add watchAll flag to jest-editor-support (#5523)
Browse files Browse the repository at this point in the history
* Add watchAll flag to jest-editor-support

* Add changelog
  • Loading branch information
k15a authored and orta committed Feb 11, 2018
1 parent af19110 commit e9bf143
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
`groupEnd`, `time`, `timeEnd`
([#5514](https://github.com/facebook/jest/pull/5514))
* `[docs]` Add documentation for interactive snapshot mode ([#5291](https://github.com/facebook/jest/pull/5291))
* `[jest-editor-support]` Add watchAll flag ([#5523](https://github.com/facebook/jest/pull/5523))

## jest 22.2.2

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-editor-support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export interface Options {
export class Runner extends EventEmitter {
constructor(workspace: ProjectWorkspace, options?: Options);
watchMode: boolean;
start(watchMode?: boolean): void;
watchAll: boolean;
start(watchMode?: boolean, watchAll?: boolean): void;
closeProcess(): void;
runJestWithUpdateForSnapshots(completion: any): void;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-editor-support/src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default class Runner extends EventEmitter {
options?: SpawnOptions,
) => ChildProcess;
watchMode: boolean;
watchAll: boolean;
options: Options;
prevMessageTypes: MessageType[];

Expand All @@ -43,20 +44,21 @@ export default class Runner extends EventEmitter {
this.prevMessageTypes = [];
}

start(watchMode: boolean = true) {
start(watchMode: boolean = true, watchAll: boolean = false) {
if (this.debugprocess) {
return;
}

this.watchMode = watchMode;
this.watchAll = watchAll;

// Handle the arg change on v18
const belowEighteen = this.workspace.localJestMajorVersion < 18;
const outputArg = belowEighteen ? '--jsonOutputFile' : '--outputFile';

const args = ['--json', '--useStderr', outputArg, this.outputPath];
if (this.watchMode) {
args.push('--watch');
args.push(this.watchAll ? '--watchAll' : '--watch');
}
if (this.options.testNamePattern) {
args.push('--testNamePattern', this.options.testNamePattern);
Expand Down
19 changes: 19 additions & 0 deletions packages/jest-editor-support/src/__tests__/runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ describe('Runner', () => {
expect(sut.watchMode).not.toBeDefined();
});

it('does not set watchAll', () => {
const workspace: any = {};
const sut = new Runner(workspace);

expect(sut.watchAll).not.toBeDefined();
});

it('sets the output filepath', () => {
tmpdir.mockReturnValueOnce('tmpdir');

Expand Down Expand Up @@ -107,6 +114,18 @@ describe('Runner', () => {
expect(sut.watchMode).toBe(expected);
});

it('sets watchAll', () => {
const watchMode = true;
const watchAll = true;

const workspace: any = {};
const sut = new Runner(workspace);
sut.start(watchMode, watchAll);

expect(sut.watchMode).toBe(watchMode);
expect(sut.watchAll).toBe(watchAll);
});

it('calls createProcess', () => {
const workspace: any = {};
const sut = new Runner(workspace);
Expand Down

0 comments on commit e9bf143

Please sign in to comment.