Skip to content

Commit

Permalink
Update jest-editor-support Settings to use spawn in shell option (#…
Browse files Browse the repository at this point in the history
…5658)

* Fix TypeScript error; Spawn using shell option

* Add to CHANGELOG

* Fix Flow types

* Fix prettylint

* Fix "Unexpected token ..."
  • Loading branch information
seanpoulter authored and orta committed Feb 25, 2018
1 parent 457776b commit 96d5453
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

* `[jest-resolve]` Update node module resolution algorithm to correctly handle
symlinked paths ([#5085](https://github.com/facebook/jest/pull/5085))
* `[jest-editor-support]` Update `Settings` to use spawn in shell option
([#5658](https://github.com/facebook/jest/pull/5658))

## 22.4.2

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-editor-support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export interface SnapshotMetadata {
exists: boolean;
name: string;
node: {
loc: editor.Node
loc: Node
};
content?: string;
}
Expand Down
13 changes: 9 additions & 4 deletions packages/jest-editor-support/src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {Options} from './types';
import type {Options, SpawnOptions} from './types';

import {ChildProcess} from 'child_process';
import EventEmitter from 'events';
Expand Down Expand Up @@ -40,15 +40,18 @@ export default class Settings extends EventEmitter {
_createProcess: (
workspace: ProjectWorkspace,
args: Array<string>,
options: SpawnOptions,
) => ChildProcess;
configs: ConfigRepresentations;
settings: ConfigRepresentation;
workspace: ProjectWorkspace;
spawnOptions: SpawnOptions;

constructor(workspace: ProjectWorkspace, options?: Options) {
super();
this.workspace = workspace;
this._createProcess = (options && options.createProcess) || createProcess;
this.spawnOptions = {shell: options && options.shell};

// Defaults for a Jest project
this.settings = {
Expand All @@ -60,9 +63,11 @@ export default class Settings extends EventEmitter {
}

getConfigs(completed: any) {
this.getConfigProcess = this._createProcess(this.workspace, [
'--showConfig',
]);
this.getConfigProcess = this._createProcess(
this.workspace,
['--showConfig'],
this.spawnOptions,
);

this.getConfigProcess.stdout.on('data', (data: Buffer) => {
const settings = JSON.parse(data.toString());
Expand Down
37 changes: 36 additions & 1 deletion packages/jest-editor-support/src/__tests__/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ describe('Settings', () => {
'test',
1000,
);
const settings = new Settings(workspace);
const options = {shell: true};
const settings = new Settings(workspace, options);
expect(settings.workspace).toEqual(workspace);
expect(settings.settings).toEqual(expect.any(Object));
expect(settings.spawnOptions).toEqual(options);
});

it('[jest 20] reads and parses the config', () => {
Expand Down Expand Up @@ -132,6 +134,39 @@ describe('Settings', () => {

expect(completed).toHaveBeenCalled();
});

it('passes command, args, and options to createProcess', () => {
const localJestMajorVersion = 1000;
const pathToConfig = 'test';
const pathToJest = 'path_to_jest';
const rootPath = 'root_path';

const workspace = new ProjectWorkspace(
rootPath,
pathToJest,
pathToConfig,
localJestMajorVersion,
);
const createProcess = jest.fn().mockReturnValue({
on: () => {},
stdout: new EventEmitter(),
});
const spawnOptions = {shell: true};
const options: any = Object.assign({}, createProcess, spawnOptions);
const settings = new Settings(workspace, options);
settings.getConfig(() => {});

expect(createProcess).toBeCalledWith(
{
localJestMajorVersion,
pathToConfig,
pathToJest,
rootPath,
},
['--showConfig'],
spawnOptions,
);
});
});

const makeBuffer = (content: string) => {
Expand Down

0 comments on commit 96d5453

Please sign in to comment.