-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtest.js
37 lines (31 loc) · 1.07 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
import test from 'ava';
import uniqueString from 'unique-string';
import npmName from '.';
test('returns true when package name is available', async t => {
t.true(await npmName(uniqueString()));
});
test('returns false when package name is taken', async t => {
t.false(await npmName('chalk'));
t.false(await npmName('recursive-readdir'));
});
test('returns a map of multiple package names', async t => {
const name1 = 'chalk';
const name2 = uniqueString();
const res = await npmName.many([name1, name2]);
t.false(res.get(name1));
t.true(res.get(name2));
});
test('returns true when scoped package name is not taken', async t => {
t.true(await npmName(`@${uniqueString()}/${uniqueString()}`));
});
test('returns false when scoped package name is taken', async t => {
t.false(await npmName('@sindresorhus/is'));
});
test('throws when package name is invalid', async t => {
await t.throwsAsync(npmName('_ABC'), {
instanceOf: npmName.InvalidNameError,
message: `Invalid package name: _ABC
- name can no longer contain capital letters
- name cannot start with an underscore`
});
});