-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
73 lines (46 loc) · 1.58 KB
/
test.js
File metadata and controls
73 lines (46 loc) · 1.58 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
65
66
67
68
69
70
71
72
73
import test from 'tape'
import execa from 'execa'
test('cuid output length', async assert => {
const child = execa('./cli.js')
child.stdin.end()
const {stdout} = await child
const message = 'slug should be more than 10 characters long'
const actual = stdout.length
const expected = 10
assert.true(actual > expected, message)
assert.end()
})
test('cuid output content', async assert => {
const {stdout} = await execa('./cli.js', [4])
const set = new Set(stdout.split('\n'))
const message = 'cuid should contain unique values only'
const actual = [...set].length
const expected = 4
assert.equal(actual, expected, message)
assert.end()
})
test('cuid slug length', async assert => {
const {stdout} = await execa('./cli.js', [1, '--slug'])
const message = 'slug should be up to 10 characters long'
const actual = stdout.length
const expected = 10
assert.true(actual <= expected, message)
assert.end()
})
test('using stdin', async assert => {
const {stdout} = await execa('./cli.js', [], {input: '1'})
const set = new Set(stdout.split('\n'))
const message = 'cuid should work with stdin and stdout should contain 1 entry'
const actual = [...set].length
const expected = 1
assert.equal(actual, expected, message)
assert.end()
})
test('using stdin slug', async assert => {
const {stdout} = await execa('./cli.js', ['--slug'], {input: '1'})
const message = 'cuid should work with stdin and stdout should contain a slug entry'
const actual = stdout.length
const expected = 10
assert.true(actual <= expected, message)
assert.end()
})