smartshell/test/test.ts

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-06-22 16:17:45 +00:00
import { expect, tap } from 'tapbundle'
2017-02-12 12:13:08 +00:00
2017-03-08 15:51:02 +00:00
import * as smartshell from '../dist/index'
2017-06-26 13:46:15 +00:00
import * as smartq from 'smartq'
2017-03-08 15:51:02 +00:00
2017-03-10 21:08:04 +00:00
let testSmartshell: smartshell.Smartshell
2017-06-22 16:17:45 +00:00
tap.test('smartshell should run async', async () => {
2017-06-26 13:46:15 +00:00
let execResult = await smartshell.exec('npm -v')
expect(execResult.stdout).to.match(/[0-9\.]*/)
2017-06-22 16:17:45 +00:00
})
2017-06-26 13:46:15 +00:00
2017-06-22 16:17:45 +00:00
tap.test('smartshell should run async and silent', async () => {
2017-06-26 13:46:15 +00:00
let execResult = await smartshell.execSilent('npm -v')
expect(execResult.stdout).to.match(/[0-9\.]*/)
2017-06-22 16:17:45 +00:00
})
2017-06-26 13:46:15 +00:00
2017-06-22 16:17:45 +00:00
tap.test('smartshell should stream a shell execution', async () => {
2017-06-26 13:46:15 +00:00
let done = smartq.defer()
2017-06-22 16:17:45 +00:00
let execStreamingResponse = smartshell.execStreaming('npm -v')
2017-06-26 13:46:15 +00:00
execStreamingResponse.childProcess.stdout.on('data', data => {
done.resolve(data)
2017-03-10 19:14:40 +00:00
})
2017-06-26 13:46:15 +00:00
let data = await done.promise
expect(data).to.equal('5.0.3\n')
await execStreamingResponse.finalPromise
2017-06-22 16:17:45 +00:00
})
2017-06-26 13:46:15 +00:00
tap.test('it should execute and wait for a line in the output', async () => {
await smartshell.execAndWaitForLine('npm -v', /5.0.3/)
})
// Smartshell class
2017-06-22 16:17:45 +00:00
tap.test('smartshell should create a Smartshell instance', async () => {
testSmartshell = new smartshell.Smartshell({
executor: 'bash',
sourceFilePaths: []
2017-03-10 21:08:04 +00:00
})
2017-06-22 16:17:45 +00:00
expect(testSmartshell).to.be.instanceof(smartshell.Smartshell)
})
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-03-11 00:58:09 +00:00
})
2017-03-10 19:14:40 +00:00
})
2017-06-22 16:17:45 +00:00
tap.start()