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

fix(test): fix Operation not supported on socket #157

Merged
merged 1 commit into from
Oct 3, 2023
Merged
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
29 changes: 4 additions & 25 deletions packages/commands/test/src/executeAsync.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import { spawn } from "child_process";
import { Logger } from "@perf-profiler/logger";

// Running with `script` ensures we display to the terminal exactly what the original script does
// For instance, maestro clears the screen multiple times which wouldn't work without calling `script`
/**
* Running with `script` ensures we display to the terminal exactly what the original script does
* For instance, maestro clears the screen multiple times which wouldn't work without calling `script`
*
* on macOS you would run `script -q /dev/null echo "Running command"`,
* but on Linux, you would run `script -q /dev/null -c "echo \"Running command\""`
*/
const spawnProcess = (command: string) => {
const parts = command.split(" ");

switch (process.platform) {
case "darwin":
return spawn("script", ["-q", "/dev/null", ...parts]);
case "win32":
return spawn(parts[0], parts.slice(1));
default:
return spawn("script", ["-q", "/dev/null", ...["-e", "-c", command]]);
}
};

export const executeAsync = (command: string) => {
const child = spawnProcess(command);
const child = spawn(command, { shell: true });

return new Promise((resolve, reject) => {
child.stdout.on("data", (data: ReadableStream<string>) => {
console.log(data.toString());
});

child.stderr.on("data", (data: ReadableStream<string>) => {
Logger.error(`Error when running "${command}": ${"\n"}${data.toString()}`);
// Commands can choose to log diagnostic data on stderr, not necessarily errors
// Let's just log them and not pollute with a noisy Logger.error
console.log(data.toString());
});

child.on("close", (code: number | null) => {
Expand Down
Loading