-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
69 lines (54 loc) · 1.75 KB
/
index.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
//
var tape = require('tape')
var test = require('../')(tape)
var request = require('request')
test('hello world', function (t) {
request.get('http://registry.npmjs.org', process)
function process (err, resp) {
t.error(err, 'no error')
t.ok(resp)
t.end()
}
})
test('get clockmoji - live', function (t) {
request.get('http://registry.npmjs.org/clockmoji', process)
function process (err, resp) {
t.error(err, 'no error')
t.equals(JSON.parse(resp.body).name, 'clockmoji', 'name is correct')
t.end()
}
})
test('duplicate test name throws', function (t) {
t.throws(function () {
test('get clockmoji - live', function () {})
}, 'should throw')
t.end()
})
test('get clockmoji - fixture with modified name', function (t) {
request.get('http://registry.npmjs.org/clockmoji', process)
function process (err, resp) {
t.error(err, 'no error')
t.equals(JSON.parse(resp.body).name, 'IMPOSTER!', 'name is correct')
t.end()
}
})
var after = function (scope) {
scope.filteringPath(/secrets=[^&]*/g, 'secrets=shh')
}
test('pass through opts to nockback', { after: after }, function (t) {
request.get('http://registry.npmjs.com?secrets=omg-secrets', function (err, resp) {
t.error(err)
t.equals(JSON.parse(resp.body).haha, 'no secrets for you', 'secrets are protected')
t.end()
})
})
test('able to get a copy of nock from test.nock and use it', function (t) {
var nock = test.nock
nock('http://registry.npmjs.org').get('/clockmoji').reply(200, { 'yep': 'it works' })
request.get('http://registry.npmjs.org/clockmoji', process)
function process (err, resp) {
t.error(err, 'no error')
t.equals(JSON.parse(resp.body).yep, 'it works', 'able to mock directly with nock instance')
t.end()
}
})