forked from sindresorhus/npm-keyword
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
78 lines (57 loc) · 2.32 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
import test from 'ava';
import npmKeyword from '.';
test('npmKeyword()', async t => {
const packages = await npmKeyword('gulpplugin');
t.is(packages.length, 250);
t.true(packages[0].name.length > 0);
t.true(packages[0].description.length > 0);
});
test('npmKeyword() using the size option', async t => {
const packages = await npmKeyword('gulpplugin', {size: 10});
t.is(packages.length, 10);
});
test('npmKeyword() using invalid options', async t => {
const packages = await npmKeyword('gulpplugin', {foo: 'bar'});
t.is(packages.length, 250);
});
test('npmKeyword() size < 1', async t => {
const error = await t.throwsAsync(npmKeyword('gulpplugin', {size: 0}));
t.is(error.message, 'Size option must be between 1 and 250');
});
test('npmKeyword() size > 250', async t => {
const error = await t.throwsAsync(npmKeyword('gulpplugin', {size: 255}));
t.is(error.message, 'Size option must be between 1 and 250');
});
test('npmKeyword.names()', async t => {
const packageNames = await npmKeyword.names('gulpplugin');
t.is(packageNames.length, 250);
t.is(typeof packageNames[0], 'string');
t.true(packageNames[0].length > 0);
});
test('npmKeyword.names() using the size option', async t => {
const packageNames = await npmKeyword.names('gulpplugin', {size: 10});
t.is(packageNames.length, 10);
});
test('npmKeyword.names() using invalid options', async t => {
const packageNames = await npmKeyword.names('gulpplugin', {foo: 'bar'});
t.is(packageNames.length, 250);
});
test('npmKeyword.count()', async t => {
const packagesWithValidKeyword = await npmKeyword.count('gulpplugin');
const packagesWithInvalidKeyword = await npmKeyword.count('äąâ');
t.true(packagesWithValidKeyword > 0);
t.is(typeof packagesWithValidKeyword, 'number');
t.is(packagesWithInvalidKeyword, 0);
});
test('npmKeyword.count() using an array of keywords', async t => {
const packagesWithOneKeyword = await npmKeyword.count('gulpplugin');
const packagesWithMultipleKeywords = await npmKeyword.count(['gulpplugin', 'sass', 'css']);
t.true(packagesWithMultipleKeywords > 0);
t.true(packagesWithMultipleKeywords < packagesWithOneKeyword);
});
test('npmKeyword.count() using wrong type for keywords parameter', async t => {
await t.throwsAsync(
npmKeyword.count({keyword: 'gulpplugin'}),
'Keyword must be either a string or an array of strings'
);
});