2024-03-16 10:18:53 +00:00
|
|
|
import { expect, tap } from '@push.rocks/tapbundle';
|
2017-02-12 12:13:08 +00:00
|
|
|
|
2023-06-22 09:51:44 +00:00
|
|
|
import * as smartshell from '../ts/index.js';
|
2024-03-16 10:18:53 +00:00
|
|
|
import * as smartpromise from '@push.rocks/smartpromise';
|
2017-03-08 15:51:02 +00:00
|
|
|
|
2018-07-18 18:58:12 +00:00
|
|
|
let testSmartshell: smartshell.Smartshell;
|
2017-03-10 21:08:04 +00:00
|
|
|
|
2018-07-30 14:03:48 +00:00
|
|
|
tap.test('smartshell should create a Smartshell instance', async () => {
|
|
|
|
testSmartshell = new smartshell.Smartshell({
|
|
|
|
executor: 'bash',
|
2021-07-26 19:24:13 +00:00
|
|
|
sourceFilePaths: [],
|
2018-07-30 14:03:48 +00:00
|
|
|
});
|
2023-06-22 09:51:44 +00:00
|
|
|
expect(testSmartshell).toBeInstanceOf(smartshell.Smartshell);
|
2018-07-30 14:03:48 +00:00
|
|
|
});
|
|
|
|
|
2017-06-22 16:17:45 +00:00
|
|
|
tap.test('smartshell should run async', async () => {
|
2018-07-30 14:03:48 +00:00
|
|
|
let execResult = await testSmartshell.exec('npm -v');
|
2023-06-22 11:54:39 +00:00
|
|
|
expect(execResult.stdout).toMatch(/[0-9\.]*/);
|
2018-07-18 18:58:12 +00:00
|
|
|
});
|
2017-06-27 08:28:11 +00:00
|
|
|
|
2017-06-22 16:17:45 +00:00
|
|
|
tap.test('smartshell should run async and silent', async () => {
|
2018-07-30 14:03:48 +00:00
|
|
|
let execResult = await testSmartshell.execSilent('npm -v');
|
2023-06-22 11:54:39 +00:00
|
|
|
expect(execResult.stdout).toMatch(/[0-9\.]*/);
|
2018-07-18 18:58:12 +00:00
|
|
|
});
|
2017-06-27 08:28:11 +00:00
|
|
|
|
2017-06-22 16:17:45 +00:00
|
|
|
tap.test('smartshell should stream a shell execution', async () => {
|
2018-07-18 18:58:12 +00:00
|
|
|
let done = smartpromise.defer();
|
2018-07-30 14:03:48 +00:00
|
|
|
let execStreamingResponse = await testSmartshell.execStreaming('npm -v');
|
2021-07-26 19:24:13 +00:00
|
|
|
execStreamingResponse.childProcess.stdout.on('data', (data) => {
|
2018-07-18 18:58:12 +00:00
|
|
|
done.resolve(data);
|
|
|
|
});
|
|
|
|
let data = await done.promise;
|
2023-06-22 11:54:39 +00:00
|
|
|
expect(data).toMatch(/[0-9\.]*/);
|
2018-07-18 18:58:12 +00:00
|
|
|
await execStreamingResponse.finalPromise;
|
|
|
|
});
|
2017-06-27 08:28:11 +00:00
|
|
|
|
|
|
|
tap.test('it should execute and wait for a line in the output', async () => {
|
2018-07-30 14:03:48 +00:00
|
|
|
await testSmartshell.execAndWaitForLine('echo "5.0.4"', /5.0.4/);
|
2018-07-18 18:58:12 +00:00
|
|
|
});
|
2017-03-11 00:58:09 +00:00
|
|
|
|
2017-06-22 16:17:45 +00:00
|
|
|
tap.test('smartshell should run async', async () => {
|
2021-07-26 19:24:13 +00:00
|
|
|
return testSmartshell.execSilent('sleep 1 && npm -v').then(async (execResult) => {
|
2018-07-18 18:58:12 +00:00
|
|
|
console.log(execResult.stdout);
|
|
|
|
});
|
|
|
|
});
|
2017-06-22 16:17:45 +00:00
|
|
|
|
2018-07-30 14:06:43 +00:00
|
|
|
tap.test('should be able to find git', async () => {
|
2019-05-28 08:43:54 +00:00
|
|
|
await testSmartshell.exec('git --version');
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should spawn an interactive cli', async () => {
|
2023-06-22 11:54:39 +00:00
|
|
|
await testSmartshell.execInteractive('echo "hi"');
|
2018-07-30 14:08:14 +00:00
|
|
|
});
|
2018-07-30 14:06:43 +00:00
|
|
|
|
2017-07-16 14:19:48 +00:00
|
|
|
tap.start({
|
2021-07-26 19:24:13 +00:00
|
|
|
throwOnError: true,
|
2018-07-18 18:58:12 +00:00
|
|
|
});
|