/
test.js
98 lines (95 loc) · 3.14 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* online-branch-exist <https://github.com/tunnckoCore/online-branch-exist>
*
* Copyright (c) 2014-2015 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/
'use strict';
var test = require('assertit');
var onlineExist = require('./index');
test('online-branch-exist:', function() {
test('should throw', function() {
test('TypeError if `callback` is not a function', function(done) {
function fixture() {
onlineExist();
}
test.throws(fixture, TypeError);
test.throws(fixture, /expect `callback` to be function/);
done();
});
test('TypeError if `pattern` is not a string', function(done) {
function fixture() {
onlineExist({some: true}, function() {});
}
test.throws(fixture, TypeError);
test.throws(fixture, /expect `pattern` to be string/);
done();
});
test('TypeError if `opts` is not an object', function(done) {
function fixture() {
onlineExist('foo/bar#baz', 'qux', function() {});
}
test.throws(fixture, TypeError);
test.throws(fixture, /expect `opts` to be object/);
done();
});
test('Error if not valid `pattern` given', function(done) {
function fixture() {
onlineExist('foobar', function() {});
}
test.throws(fixture, Error);
test.throws(fixture, /expect `pattern` to be `user\/repo\#branch`/);
done();
});
test('Error if valid `pattern`, but no branch/tag given', function(done) {
function fixture() {
onlineExist('foo/bar', function() {});
}
test.throws(fixture, Error);
test.throws(fixture, /should give a branch or tag in `pattern`/);
done();
});
});
test('should onlineExist(pattern, cb) check if `branch` exist then `tag`', function() {
test('should return `true` if branch exist', function(done) {
onlineExist('tunnckoCore/koa-better-body#master', function(err, res) {
test.equal(err, null);
test.equal(res, true);
done();
});
});
test('should return `true` if tag exist', function(done) {
onlineExist('tunnckoCore/koa-better-body#v1.0.16', function(err, res) {
test.equal(err, null);
test.equal(res, true);
done();
});
});
test('should return `false` if branch or tag not exists', function(done) {
onlineExist('tunnckoCore/koa-better-body#asfsdfdsf', function(err, res) {
test.equal(err, null);
test.equal(res, false);
done();
});
});
});
// test('should have `opts.token` option for Github Access Token api', function(done) {
// // atm
// });
test('should have `.tag` and `.branch` methods', function() {
test('should have `.tag` method', function(done) {
onlineExist.tag('tunnckoCore/koa-better-body#v1.0.16', function(err, res) {
test.equal(err, null);
test.equal(res, true);
done();
});
});
test('should have `.branch` method', function(done) {
onlineExist.branch('tunnckoCore/koa-better-body#master', function(err, res) {
test.equal(err, null);
test.equal(res, true);
done();
});
});
});
});