Skip to content

Commit 96d5453

Browse files
seanpoulterorta
authored andcommitted
Update jest-editor-support Settings to use spawn in shell option (#5658)
* Fix TypeScript error; Spawn using shell option * Add to CHANGELOG * Fix Flow types * Fix prettylint * Fix "Unexpected token ..."
1 parent 457776b commit 96d5453

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

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

1315
## 22.4.2
1416

packages/jest-editor-support/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export interface SnapshotMetadata {
170170
exists: boolean;
171171
name: string;
172172
node: {
173-
loc: editor.Node
173+
loc: Node
174174
};
175175
content?: string;
176176
}

packages/jest-editor-support/src/Settings.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Options} from './types';
10+
import type {Options, SpawnOptions} from './types';
1111

1212
import {ChildProcess} from 'child_process';
1313
import EventEmitter from 'events';
@@ -40,15 +40,18 @@ export default class Settings extends EventEmitter {
4040
_createProcess: (
4141
workspace: ProjectWorkspace,
4242
args: Array<string>,
43+
options: SpawnOptions,
4344
) => ChildProcess;
4445
configs: ConfigRepresentations;
4546
settings: ConfigRepresentation;
4647
workspace: ProjectWorkspace;
48+
spawnOptions: SpawnOptions;
4749

4850
constructor(workspace: ProjectWorkspace, options?: Options) {
4951
super();
5052
this.workspace = workspace;
5153
this._createProcess = (options && options.createProcess) || createProcess;
54+
this.spawnOptions = {shell: options && options.shell};
5255

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

6265
getConfigs(completed: any) {
63-
this.getConfigProcess = this._createProcess(this.workspace, [
64-
'--showConfig',
65-
]);
66+
this.getConfigProcess = this._createProcess(
67+
this.workspace,
68+
['--showConfig'],
69+
this.spawnOptions,
70+
);
6671

6772
this.getConfigProcess.stdout.on('data', (data: Buffer) => {
6873
const settings = JSON.parse(data.toString());

packages/jest-editor-support/src/__tests__/settings.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ describe('Settings', () => {
2121
'test',
2222
1000,
2323
);
24-
const settings = new Settings(workspace);
24+
const options = {shell: true};
25+
const settings = new Settings(workspace, options);
2526
expect(settings.workspace).toEqual(workspace);
2627
expect(settings.settings).toEqual(expect.any(Object));
28+
expect(settings.spawnOptions).toEqual(options);
2729
});
2830

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

133135
expect(completed).toHaveBeenCalled();
134136
});
137+
138+
it('passes command, args, and options to createProcess', () => {
139+
const localJestMajorVersion = 1000;
140+
const pathToConfig = 'test';
141+
const pathToJest = 'path_to_jest';
142+
const rootPath = 'root_path';
143+
144+
const workspace = new ProjectWorkspace(
145+
rootPath,
146+
pathToJest,
147+
pathToConfig,
148+
localJestMajorVersion,
149+
);
150+
const createProcess = jest.fn().mockReturnValue({
151+
on: () => {},
152+
stdout: new EventEmitter(),
153+
});
154+
const spawnOptions = {shell: true};
155+
const options: any = Object.assign({}, createProcess, spawnOptions);
156+
const settings = new Settings(workspace, options);
157+
settings.getConfig(() => {});
158+
159+
expect(createProcess).toBeCalledWith(
160+
{
161+
localJestMajorVersion,
162+
pathToConfig,
163+
pathToJest,
164+
rootPath,
165+
},
166+
['--showConfig'],
167+
spawnOptions,
168+
);
169+
});
135170
});
136171

137172
const makeBuffer = (content: string) => {

0 commit comments

Comments
 (0)