-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtest.js
49 lines (40 loc) · 1.63 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
import test from 'ava';
import {execa} from 'execa';
const randomName = () => `asdasfgrgafadsgaf${Math.random().toString().slice(2)}`;
test('is available', async t => {
const {stdout} = await execa('./cli.js', [randomName(), '--color']);
t.regex(stdout, /is available/);
});
test('is squatted', async t => {
const {stdout} = await execa('./cli.js', ['abc123', '--color']);
t.regex(stdout, /is squatted/);
});
test('is unavailable', async t => {
const {stdout, exitCode} = await t.throwsAsync(execa('./cli.js', ['chalk', '--color']));
t.is(exitCode, 2);
t.regex(stdout, /is unavailable/);
});
test('organization is available', async t => {
const {stdout} = await execa('./cli.js', [`@${randomName()}`, '--color']);
t.regex(stdout, /is available/);
});
test('organization is unavailable', async t => {
const {stdout, exitCode} = await t.throwsAsync(execa('./cli.js', ['@ava', '--color']));
t.is(exitCode, 2);
t.regex(stdout, /is unavailable/);
});
test('multiple packages', async t => {
const {stdout, exitCode} = await t.throwsAsync(execa('./cli.js', ['chalk', randomName(), '--color']));
t.is(exitCode, 2);
t.regex(stdout, /is unavailable(.*)is available/s);
});
test('is available in similar search', async t => {
const {stdout, exitCode} = await execa('./cli.js', [randomName(), '--color', '--similar']);
t.is(exitCode, 0);
t.regex(stdout, /is available(.*)No similar packages found/s);
});
test('is not available in similar search', async t => {
const {stdout, exitCode} = await t.throwsAsync(execa('./cli.js', ['chalk', '--color', '--similar']));
t.is(exitCode, 2);
t.regex(stdout, /is unavailable(.*)Similar names(.*)is available/s);
});