2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/tests/module/esm/tests/helpers/run-command.js
T
Jay 76794ac27a chore: update module test for full check (#7510)
* chore: add additional testing to esm and cjs smoke

* test: updated test suite to include module tests

* fix: esm test smoke import

* fix: cubic feedback

* fix: failing cjs

* fix: cjs timeout
2026-03-15 21:10:52 +02:00

36 lines
894 B
JavaScript

import { spawnSync } from 'node:child_process';
const formatCommand = (command, args) => [command, ...(args || [])].join(' ');
export const runCommand = (command, args = [], options = {}) => {
const spawnOptions = { encoding: 'utf8', ...options };
const result = spawnSync(command, args, spawnOptions);
const output = {
code: result.status,
stdout: result.stdout || '',
stderr: result.stderr || '',
command: formatCommand(command, args),
cwd: spawnOptions.cwd || process.cwd(),
};
if (result.error) {
throw result.error;
}
if (output.code !== 0) {
throw new Error(
[
'Command failed:',
` command: ${output.command}`,
` cwd: ${output.cwd}`,
` exitCode: ${String(output.code)}`,
` stdout:\n${output.stdout}`,
` stderr:\n${output.stderr}`,
].join('\n')
);
}
return output;
};