Skip to content

Commit

Permalink
feat: Implement runProcess function in test library
Browse files Browse the repository at this point in the history
Description:
- Implements the runProcess function in testLibrary.mjs using Node's spawn utility
- Removes TODO comment and placeholder implementation
  • Loading branch information
VolodymyrBg authored Jan 22, 2025
1 parent 5347b1f commit a33b833
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions tests/testLibrary.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,36 @@ function logError(error) {

async function runProcess(command, args = [], directory = projectRoot()) {
try {
throw new Exception("Not implemented yet"); // TODO
// const result = await $`cd ${directory} && ${command} ${args}`;
return result.stdout.trim();
return new Promise((resolve, reject) => {
const process = spawn(command, args, {
cwd: directory,
shell: true,
stdio: ['inherit', 'pipe', 'pipe']
});

let stdout = '';
let stderr = '';

process.stdout.on('data', (data) => {
stdout += data.toString();
});

process.stderr.on('data', (data) => {
stderr += data.toString();
});

process.on('close', (code) => {
if (code === 0) {
resolve(stdout.trim());
} else {
reject(new Error(`Command failed with code ${code}: ${stderr}`));
}
});

process.on('error', (error) => {
reject(new Error(`Failed to start command: ${error.message}`));
});
});
} catch (error) {
throw new Error(`Command failed: ${error.message}`);
}
Expand Down

0 comments on commit a33b833

Please sign in to comment.