-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
94 lines (58 loc) · 2.08 KB
/
test.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
const PATH = require('path');
const FSE = require('fs-extra');
// -----------------------------------------------------------------------------
import test from 'ava';
import execa from 'execa';
// -----------------------------------------------------------------------------
const TEST = {
cli_file : './cli.js',
directory : PATH.join('__', 'tests', 'create'),
filename : 'index.md',
title : () => `Randomness ${Math.random().toString(36).slice(2)}`,
create_args : [],
};
// -----------------------------------------------------------------------------
/**
* Test title provided
*
* This test should run before 'exists', hence using `test.serial`,
* so that we use the same created data
*/
test.serial('title provided', async t => {
TEST.create_args = [
`--title=${TEST.title()}`,
`--directory=${TEST.directory}`,
`--filename=${TEST.filename}`,
];
// ---------------------------------------------------------------------------
const ret = await execa( TEST.cli_file, TEST.create_args );
// ---------------------------------------------------------------------------
t.is( ret.code, 0 );
// ---------------------------------------------------------------------------
t.regex( ret.stdout, /successfuly created/ );
});
/**
* Test title required
*/
test('title required', async t => {
const ret = await t.throwsAsync( execa( TEST.cli_file ) );
// ---------------------------------------------------------------------------
t.is( ret.code, 1 );
// ---------------------------------------------------------------------------
t.regex( ret.stderr, /title required/ );
});
/**
* Test exists
*/
test('exists', async t => {
const ret = await t.throwsAsync( execa( TEST.cli_file, TEST.create_args ) );
// ---------------------------------------------------------------------------
t.is( ret.code, 1 );
// ---------------------------------------------------------------------------
t.regex( ret.stderr, /already exists/ );
});
/**
* Cleanup by emptying test dir
*/
test.after.always('cleanup', async t => await FSE.emptyDir( TEST.directory ) );