smartcli/test/test.ts

43 lines
1.3 KiB
TypeScript
Raw Normal View History

import { tap, expect } from '@pushrocks/tapbundle';
import { Subject } from 'rxjs';
2016-06-10 00:27:04 +00:00
2022-08-03 15:00:36 +00:00
import * as smartcli from '../ts/index.js';
2017-04-22 19:03:28 +00:00
tap.test('should create a new Smartcli', async () => {
2022-08-03 16:47:35 +00:00
const smartCliTestObject = new smartcli.Smartcli();
2022-08-03 15:00:36 +00:00
expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
});
2017-04-22 19:03:28 +00:00
2022-08-03 16:47:35 +00:00
tap.test('should add an command', async (toolsArg) => {
const done = toolsArg.defer();
const smartCliTestObject = new smartcli.Smartcli();
const awesomeCommandSubject = smartCliTestObject.addCommand('awesome')
expect(awesomeCommandSubject).toBeInstanceOf(Subject);
awesomeCommandSubject.subscribe(() => {
done.resolve();
});
console.log(process.argv);
process.argv.splice(2, 0, 'awesome');
console.log(process.argv);
smartCliTestObject.startParse();
await done.promise;
});
2017-04-22 19:03:28 +00:00
tap.test('should start parsing a standardTask', async () => {
2022-08-03 16:47:35 +00:00
const smartCliTestObject = new smartcli.Smartcli();
2022-08-03 15:00:36 +00:00
expect(smartCliTestObject.standardCommand()).toBeInstanceOf(Subject);
});
2017-04-22 19:03:28 +00:00
let hasExecuted: boolean = false;
2017-04-22 19:03:28 +00:00
tap.test('should accept a command', async () => {
2022-08-03 16:47:35 +00:00
const smartCliTestObject = new smartcli.Smartcli();
2022-08-03 15:00:36 +00:00
smartCliTestObject.addCommand('triggerme').subscribe(() => {
hasExecuted = true;
});
2022-08-03 15:00:36 +00:00
smartCliTestObject.triggerCommand('triggerme', {});
expect(hasExecuted).toBeTrue();
});
2017-04-22 19:03:28 +00:00
tap.start();