MCPcopy
hub / github.com/request/request / runTest

Function runTest

tests/test-proxy.js:37–80  ·  view source on GitHub ↗
(name, options, responseHandler)

Source from the content-addressed store, hash-verified

35// for this request, or falsy to indicate that the proxy should not be used for
36// this request.
37function runTest (name, options, responseHandler) {
38 tape(name, function (t) {
39 proxyEnvVars.forEach(function (v) {
40 delete process.env[v]
41 })
42 if (options.env) {
43 for (var v in options.env) {
44 process.env[v] = options.env[v]
45 }
46 delete options.env
47 }
48
49 var called = false
50 currResponseHandler = function (req, res) {
51 if (responseHandler) {
52 called = true
53 t.equal(req.headers.host, 'google.com')
54 if (typeof responseHandler === 'function') {
55 responseHandler(t, req, res)
56 }
57 } else {
58 t.fail('proxy response should not be called')
59 }
60 }
61
62 options.url = options.url || 'http://google.com'
63 request(options, function (err, res, body) {
64 if (responseHandler && !called) {
65 t.fail('proxy response should be called')
66 }
67 t.equal(err, null)
68 t.equal(res.statusCode, 200)
69 if (responseHandler) {
70 if (body.length > 100) {
71 body = body.substring(0, 100)
72 }
73 t.equal(body, 'ok')
74 } else {
75 t.equal(/^<!doctype html>/i.test(body), true)
76 }
77 t.end()
78 })
79 })
80}
81
82function addTests () {
83 // If the `runTest` function is changed, run the following command and make

Callers 1

addTestsFunction · 0.70

Calls 1

requestFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…