-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
38 lines (32 loc) · 1.23 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
import test from 'ava'
import execa from 'execa'
import isAvailable from 'npm-name'
const path = './index.js'
test('when given no input, provides random related terms', async t => {
const result = await execa.stdout(path, [])
const lines = result.split('\n')
t.is(lines[1], 'Some available package names:')
t.true(lines.length > 3)
})
test('provides terms related to the given input', async t => {
const result = await execa.stdout(path, ['car'])
const lines = result.split('\n')
t.is(lines[1], `Available package names related to 'car':`)
t.true(lines.length > 3)
})
test('`--limit` flag limits the number of returned results', async t => {
const result = await execa.stdout(path, ['car', '--limit=5'])
const lines = result.split('\n')
const items = lines[lines.length - 1].split(/\s+/g)
t.is(lines[1], `Available package names related to 'car':`)
t.true(items.length === 5)
})
test('results are available npm package names', async t => {
const result = await execa.stdout(path, ['car'])
const lines = result.split('\n')
const names = lines[3].split(/ +/g)
const availables = await Promise.all(names.map(isAvailable))
availables.forEach((available, i) => {
t.true(available, `${names[i]} is available`)
})
})