Skip to content

Commit

Permalink
login-shell child process should return command exit code (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz authored Nov 11, 2022
1 parent c10afc5 commit 2ad057a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-editor-support",
"version": "30.2.0",
"version": "30.2.1",
"repository": {
"type": "git",
"url": "https://github.com/jest-community/jest-editor-support"
Expand Down
12 changes: 6 additions & 6 deletions src/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
const env = {...process.env, ...(workspace.nodeEnv ?? {})};
const cmd = runtimeExecutable.join(' ');

const spawnShell = () => {
const spawnCommandLine = () => {
const spawnOptions = {
cwd: workspace.rootPath,
env,
Expand All @@ -50,7 +50,7 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
return spawn(cmd, [], spawnOptions);
};

const spawnLoginShell = (tShell: LoginShell) => {
const spawnLoginShell = (shell: LoginShell) => {
const spawnOptions = {
cwd: workspace.rootPath,
env,
Expand All @@ -60,14 +60,14 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
if (workspace.debug) {
// eslint-disable-next-line no-console
console.log(
`spawning login-shell "${tShell.path} ${tShell.args.join(' ')}" for command=${cmd}`,
`spawning login-shell "${shell.path} ${shell.args.join(' ')}" for command=${cmd}`,
'options:',
spawnOptions
);
}

const child = spawn(tShell.path, tShell.args, spawnOptions);
child.stdin.write(`${cmd} \n exit\n`);
const child = spawn(shell.path, shell.args, spawnOptions);
child.stdin.write(`${cmd} \nexit $?\n`);
return child;
};

Expand All @@ -78,5 +78,5 @@ export const createProcess = (workspace: ProjectWorkspace, args: string[]): Chil
return spawnLoginShell(workspace.shell);
}
}
return spawnShell();
return spawnCommandLine();
};
8 changes: 3 additions & 5 deletions src/__tests__/process.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
Expand Down Expand Up @@ -99,10 +100,7 @@ describe('createProcess', () => {
${'powerShell.exe'} | ${'powerShell.exe'}
${'/bin/bash'} | ${'/bin/bash'}
`('allow customize shell: $shell', ({shell, expected}) => {
const workspace: any = {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
shell,
};
const workspace: any = {shell};
createProcess(workspace, []);

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

expect(mockConsoleLog).not.toHaveBeenCalled();
} else {
Expand Down

0 comments on commit 2ad057a

Please sign in to comment.