-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.mjs
More file actions
64 lines (55 loc) · 2.1 KB
/
test.mjs
File metadata and controls
64 lines (55 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import test from 'node:test';
import * as chai from 'chai';
import {
command,
fileInfo,
hasALineContaining,
nextStreamDataContainsALineWith,
nextStreamData
} from '../src/index.mjs';
const should = chai.should();
const defaultAppOptions = {
"name":"my-app"
};
const loopbackBin = './test/bins/loopback.mjs';
const helpBin = './test/bins/help.mjs';
const interactiveBin = './test/bins/interactive.mjs';
const opts = ()=> JSON.stringify(defaultAppOptions);
(async ()=>{
await test('command-test self test',async (t) => {
await t.test('loopback test', async (t) => {
const child = await command(`${loopbackBin}`);
const str = child.out.toString();
str.trim().should.equal('{}');
const data = JSON.parse(str);
should.exist(data);
});
await t.test('help test', async (t) => {
try{
const result = await command(`${helpBin}`);
const lines = result.out.toString().split('\n');
hasALineContaining('--help', lines).should.equal(true);
hasALineContaining('--foo', lines).should.equal(false);
hasALineContaining('--profile', lines).should.equal(true);
hasALineContaining('--verbose', lines).should.equal(true);
hasALineContaining('--version', lines).should.equal(true);
}catch(ex){
//console.log(ex);
//should.not.exist(ex);
throw ex;
}
});
await t.test('interactive test', async (t) => {
const cmd = command(`${interactiveBin}`);
const name = 'foo';
const stream = await (cmd.stream);
await nextStreamDataContainsALineWith(stream, 'What\'s your name?');
const futureData = nextStreamData(stream);
stream.stdin.write(`${name}\n`);
const data = JSON.parse(await futureData);
should.exist(data);
data.name.should.equal(name);
stream.stdin.end();
});
});
})();