-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
60 lines (52 loc) · 1.44 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
const test = require('ava');
const addPrefix = require('.');
test('throws with invalid params', t => {
t.throws(() => addPrefix({}, 'string'));
t.throws(() => addPrefix('string', null));
t.throws(() => addPrefix([], 5));
});
function doIt(t, opts) {
t.is(addPrefix(opts.prefix, opts.in), opts.out);
}
test('simple', doIt, {
prefix: 'prefix',
in: 'package',
out: 'prefix-package'
});
test('empty package name', doIt, { prefix: 'prefix', in: '', out: 'prefix-' });
test('empty prefix', doIt, { prefix: '', in: 'package', out: 'package' });
test('scope', doIt, {
prefix: 'prefix',
in: '@scope/package',
out: '@scope/prefix-package'
});
test('spaces', doIt, {
prefix: 'hello world',
in: 'more\tspaces\nand things',
out: 'hello-world-more-spaces-and-things'
});
test('existing prefix', doIt, {
prefix: 'prefix',
in: 'prefix-package',
out: 'prefix-package'
});
test('existing prefix + scope', doIt, {
prefix: 'prefix',
in: '@scope/prefix-package',
out: '@scope/prefix-package'
});
test("slashes that aren't real scopes", doIt, {
prefix: 'prefix',
in: 'not_a_scope/package',
out: 'prefix-not_a_scope/package'
});
test("lots of slashes that aren't real scopes", doIt, {
prefix: 'prefix',
in: 'thing/again/not_a_scope/package',
out: 'prefix-thing/again/not_a_scope/package'
});
test('scopes with extra slashes', doIt, {
prefix: 'prefix',
in: '@scope/not_a_scope/package',
out: '@scope/prefix-not_a_scope/package'
});