Skip to content

Commit 2ad057a

Browse files
authored
login-shell child process should return command exit code (#92)
1 parent c10afc5 commit 2ad057a

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-editor-support",
3-
"version": "30.2.0",
3+
"version": "30.2.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/jest-community/jest-editor-support"

src/Process.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
3131
const env = {...process.env, ...(workspace.nodeEnv ?? {})};
3232
const cmd = runtimeExecutable.join(' ');
3333

34-
const spawnShell = () => {
34+
const spawnCommandLine = () => {
3535
const spawnOptions = {
3636
cwd: workspace.rootPath,
3737
env,
@@ -50,7 +50,7 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
5050
return spawn(cmd, [], spawnOptions);
5151
};
5252

53-
const spawnLoginShell = (tShell: LoginShell) => {
53+
const spawnLoginShell = (shell: LoginShell) => {
5454
const spawnOptions = {
5555
cwd: workspace.rootPath,
5656
env,
@@ -60,14 +60,14 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
6060
if (workspace.debug) {
6161
// eslint-disable-next-line no-console
6262
console.log(
63-
`spawning login-shell "${tShell.path} ${tShell.args.join(' ')}" for command=${cmd}`,
63+
`spawning login-shell "${shell.path} ${shell.args.join(' ')}" for command=${cmd}`,
6464
'options:',
6565
spawnOptions
6666
);
6767
}
6868

69-
const child = spawn(tShell.path, tShell.args, spawnOptions);
70-
child.stdin.write(`${cmd} \n exit\n`);
69+
const child = spawn(shell.path, shell.args, spawnOptions);
70+
child.stdin.write(`${cmd} \nexit $?\n`);
7171
return child;
7272
};
7373

@@ -78,5 +78,5 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
7878
return spawnLoginShell(workspace.shell);
7979
}
8080
}
81-
return spawnShell();
81+
return spawnCommandLine();
8282
};

src/__tests__/process.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
23
/* eslint-disable @typescript-eslint/no-unsafe-call */
34
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
@@ -99,10 +100,7 @@ describe('createProcess', () => {
99100
${'powerShell.exe'} | ${'powerShell.exe'}
100101
${'/bin/bash'} | ${'/bin/bash'}
101102
`('allow customize shell: $shell', ({shell, expected}) => {
102-
const workspace: any = {
103-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
104-
shell,
105-
};
103+
const workspace: any = {shell};
106104
createProcess(workspace, []);
107105

108106
expect(mockSpawn.mock.calls[0][2].shell).toEqual(expected);
@@ -188,7 +186,7 @@ describe('createProcess', () => {
188186
expect(mockSpawn.mock.calls[0][0]).toEqual(expect.stringContaining(workspace.shell.path));
189187
expect(mockSpawn.mock.calls[0][2].shell).not.toBe(true);
190188
expect(mockWrite).toBeCalledWith(expect.stringContaining(jestCommandLine));
191-
expect(mockWrite).toBeCalledWith(expect.stringContaining('exit'));
189+
expect(mockWrite).toBeCalledWith(expect.stringContaining('exit $?'));
192190

193191
expect(mockConsoleLog).not.toHaveBeenCalled();
194192
} else {

0 commit comments

Comments
 (0)