smartshell/test/test.ts

54 lines
1.6 KiB
TypeScript
Raw Normal View History

import { expect, tap } from '@pushrocks/tapbundle';
2017-02-12 12:13:08 +00:00
import * as smartshell from '../ts';
import * as smartpromise from '@pushrocks/smartpromise';
2017-03-08 15:51:02 +00:00
let testSmartshell: smartshell.Smartshell;
2017-03-10 21:08:04 +00:00
tap.test('smartshell should create a Smartshell instance', async () => {
testSmartshell = new smartshell.Smartshell({
executor: 'bash',
sourceFilePaths: []
});
expect(testSmartshell).to.be.instanceof(smartshell.Smartshell);
});
2017-06-22 16:17:45 +00:00
tap.test('smartshell should run async', async () => {
let execResult = await testSmartshell.exec('npm -v');
expect(execResult.stdout).to.match(/[0-9\.]*/);
});
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 () => {
let execResult = await testSmartshell.execSilent('npm -v');
expect(execResult.stdout).to.match(/[0-9\.]*/);
});
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 () => {
let done = smartpromise.defer();
let execStreamingResponse = await testSmartshell.execStreaming('npm -v');
2017-06-27 08:28:11 +00:00
execStreamingResponse.childProcess.stdout.on('data', data => {
done.resolve(data);
});
let data = await done.promise;
expect(data).to.match(/[0-9\.]*/);
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 () => {
await testSmartshell.execAndWaitForLine('echo "5.0.4"', /5.0.4/);
});
2017-03-11 00:58:09 +00:00
2017-06-22 16:17:45 +00:00
tap.test('smartshell should run async', async () => {
return testSmartshell.execSilent('sleep 1 && npm -v').then(async execResult => {
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 () => {
testSmartshell.exec('git --version');
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({
throwOnError: true
});