/
test.js
127 lines (113 loc) · 3.93 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* homepage <https://github.com/tunnckoCore/homepage>
*
* Copyright (c) 2014 Charlike Mike Reagent, contributors.
* Released under the MIT license.
*/
'use strict';
/**
* Module dependencies.
*/
var assert = require('assert');
var homepage = require('../index');
describe('homepage cli', function() {
describe('should open https://github.com/tunnckoCore/homepage', function() {
it('when 1st arg is object and promise:true', function (done) {
this.timeout(15000);
homepage({promise: true})
.then(function resolve(res) {
assert(typeof res === 'object' && typeof res.visit === 'string')
assert(res.visit === 'https://github.com/tunnckoCore/homepage')
done()
})
});
});
describe('should open url when', function() {
it('2nd arg `callback`', function (done) {
this.timeout(15000);
homepage('mocha', function(err, res) {
assert(err === null)
assert(typeof res === 'object' && typeof res.visit === 'string')
done()
})
});
it('2nd arg `true`, 3rd `callback`', function (done) {
this.timeout(15000);
homepage('express', true, function(err, res) {
assert(err === null)
assert(typeof res === 'object' && typeof res.visit === 'string')
done()
})
});
it('2nd arg `false`, 3rd `callback`', function (done) {
this.timeout(15000);
homepage('gulp', false, function(err, res) {
assert(err === null)
assert(typeof res === 'object' && typeof res.visit === 'string')
done()
})
});
it('2nd arg `options.promise:true`, 3rd `callback` - not used', function (done) {
this.timeout(15000);
homepage('connect', {promise: true}, function(err, res) {
console.log('not come here', err, res)
})
.then(function resolve(res) {
assert(typeof res === 'object' && typeof res.visit === 'string')
done()
})
});
it('1st arg `options`, 2nd `callback`', function (done) {
this.timeout(15000);
homepage({name: 'koa'}, function(err, res) {
assert(err === null)
assert(typeof res === 'object' && typeof res.visit === 'string')
done()
})
});
it('1st arg `options`, `promise:true`, 2nd `callback` - not used', function (done) {
this.timeout(15000);
homepage({name: 'lodash', promise: true}, function(err, res) {
console.log('not come here', err, res)
})
.then(function resolve(res) {
assert(typeof res === 'object' && typeof res.visit === 'string')
done()
})
});
it('1st arg `options`, `promise:false`, 2nd `callback` used', function (done) {
this.timeout(15000);
homepage({name: 'underscore', promise: false}, function(err, res) {
assert(err === null)
assert(typeof res === 'object' && typeof res.visit === 'string')
done()
})
});
});
describe('should throw error when', function() {
it('1st arg `string` isnt in registry, 2nd `callback` used', function (done) {
homepage('_PackageNotFoundInRegistry_', function(err, res) {
assert(err instanceof Error)
assert(err.message === 'Package not found in registry: _PackageNotFoundInRegistry_')
assert(res === undefined)
done()
})
});
it('1st arg `string` isnt in registry, 2nd `object` promise:true', function (done) {
homepage('__PromiseNotFound__', {promise:true})
.catch(function reject(err) {
assert(err instanceof Error)
assert(err.message === 'Package not found in registry: __PromiseNotFound__')
done()
})
});
it('1st arg is `object` name isnt in registry, promise:true', function (done) {
homepage({name: '__NotInRegistry__', promise:true})
.catch(function reject(err) {
assert(err instanceof Error)
assert(err.message === 'Package not found in registry: __NotInRegistry__')
done()
})
});
});
});