UNPKG

3.26 kBJavaScriptView Raw
1/* global describe, it */
2require('lazy-ass');
3var check = require('check-more-types');
4
5describe('utils', function () {
6 var utils = require('./utils');
7
8 describe('first line', function () {
9 var firstLine = utils.firstLine;
10
11 it('returns the only line', function () {
12 var line = 'hi there';
13 var first = firstLine(line);
14 la(first === line, 'line has not changed', first);
15 });
16
17 it('returns the first line from multiline', function () {
18 var text = 'hi there\nsecond line';
19 var first = firstLine(text);
20 la(first === 'hi there', 'only the first line', first, 'from', text);
21 });
22 });
23
24 describe('trimming tags and versions', function () {
25 var trim = utils.trimVersion;
26
27 it('passes semver', function () {
28 var tag = '3.0.0';
29 var trimmed = trim(tag);
30 la(trimmed === tag, 'unchanged semver', trimmed, 'from', tag);
31 });
32
33 it('removes leading v', function () {
34 var tag = 'v3.0.0';
35 var trimmed = trim(tag);
36 la(trimmed === '3.0.0', 'removed leading v from', trimmed, 'from', tag);
37 });
38 });
39
40 describe('is github user / repo pair', function () {
41 var isGithubName = utils.isGithubName;
42
43 it('rejects simple word', function () {
44 la(!isGithubName('foo'));
45 });
46
47 it('rejects multiple words', function () {
48 la(!isGithubName('foo/bar/baz'));
49 });
50
51 it('detects user / repo', function () {
52 la(isGithubName('foo/bar'));
53 });
54
55 it('detects user / repo with dashes', function () {
56 la(isGithubName('foo-bar/baz'));
57 });
58
59 it('detects user / repo with dashes and digits', function () {
60 la(isGithubName('foo-bar/baz-21'));
61 });
62 });
63
64 describe('parsing github user/repo pair', function () {
65 var parseGithubName = utils.parseGithubName;
66
67 it('detects user / repo', function () {
68 var result = parseGithubName('foo/bar');
69 la(result.user === 'foo', 'username', result);
70 la(result.repo === 'bar', 'reponame', result);
71 });
72
73 it('detects user / repo with dashes', function () {
74 var result = parseGithubName('foo-21/bar-baz');
75 la(result.user === 'foo-21', 'username', result);
76 la(result.repo === 'bar-baz', 'reponame', result);
77 });
78 });
79
80 describe('parse github url', function () {
81 var parse = utils.parseGithubUrl;
82
83 it('parses example .git', function () {
84 var url = 'https://github.com/bahmutov/next-update.git';
85 var info = parse(url);
86 la(check.object(info), 'not an object', info);
87 la(check.has(info, 'user'), 'missing user', info);
88 la(check.has(info, 'repo'), 'missing repo', info);
89
90 la(info.user === 'bahmutov', 'wrong user', info);
91 la(info.repo === 'next-update', 'wrong repo', info);
92 });
93
94 it('parses example without .git', function () {
95 var url = 'https://github.com/chalk/chalk';
96 var info = parse(url);
97 la(info.user === 'chalk', 'wrong user', info);
98 la(info.repo === 'chalk', 'wrong repo', info);
99 });
100
101 it('parses git@ urls', function () {
102 var url = 'git@github.com:kensho/ng-describe.git';
103 var info = parse(url);
104 la(info.user === 'kensho', 'wrong user', info);
105 la(info.repo === 'ng-describe', 'wrong repo', info);
106 });
107
108 });
109});