Skip to content

Commit

Permalink
chore: add lib/run.js unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruyadorno committed Dec 19, 2024
1 parent 1356262 commit 3afe24f
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/unit/run.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';

import {
forceRunAsync,
runAsync,
runSync
} from '../../lib/run.js';

describe('runSync', () => {
it('echo test', () => {
const test = runSync('echo', ['test']).trim();
assert.strictEqual(
test,
'test',
'should run a sync cmd and return stdout'
);
});
it('missing cmd', () => {
assert.throws(
() => { runSync('./not-a-cmd'); },
/ENOENT/,
'should throw an error'
);
});
});

describe('runAsync', () => {
it('echo test', async() => {
const test =
(await runAsync('echo', ['test'], { captureStdout: true })).trim();
assert.strictEqual(
test,
'test',
'should run an async cmd and return stdout'
);
});
});

describe('forceRunAsync', () => {
it('echo test', async() => {
const test =
await forceRunAsync('echo', ['test'], { captureStdout: true });
assert.strictEqual(
test.trim(),
'test',
'should run an async cmd and return stdout'
);
});
it('missing cmd', async() => {
assert.rejects(
forceRunAsync('./not-a-cmd'),
/ENOENT/,
'should throw an error'
);
});
});

0 comments on commit 3afe24f

Please sign in to comment.