Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update jest-editor-support Settings to use spawn in shell option #5658

Merged
merged 5 commits into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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