diff --git a/tests/test_common.js b/tests/test_common.js index 61df01318..6a92a34b2 100644 --- a/tests/test_common.js +++ b/tests/test_common.js @@ -141,8 +141,8 @@ test('headersFieldNamesToLowerCase throws on conflicting keys', t => { t.throws( () => common.headersFieldNamesToLowerCase({ - HoSt: 'example.com', - HOST: 'example.com', + HoSt: 'example.test', + HOST: 'example.test', }), { message: diff --git a/tests/test_events.js b/tests/test_events.js index cd57ed4de..eb17a8788 100644 --- a/tests/test_events.js +++ b/tests/test_events.js @@ -62,7 +62,7 @@ test('emits request and request body', function(t) { }) test('emits no match when no match and no mock', function(t) { - nock.emitter.once('no match', function(req) { + nock.emitter.once('no match', function() { t.end() }) diff --git a/tests/test_intercept.js b/tests/test_intercept.js index e6441564d..4c4fc8351 100644 --- a/tests/test_intercept.js +++ b/tests/test_intercept.js @@ -25,7 +25,7 @@ const acceptableGlobalKeys = new Set([ ]) test('invalid or missing method parameter throws an exception', t => { - t.throws(() => nock('https://example.com').intercept('/somepath'), { + t.throws(() => nock('https://example.test').intercept('/somepath'), { message: 'The "method" parameter is required for an intercept call.', }) t.end() @@ -37,11 +37,11 @@ test("when the path doesn't include a leading slash it raises an error", functio }) test('get gets mocked', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply(200, 'Hello World!') - const { statusCode, body } = await got('http://example.com/', { + const { statusCode, body } = await got('http://example.test/', { encoding: null, }) @@ -52,11 +52,11 @@ test('get gets mocked', async t => { }) test('get gets mocked with relative base path', async t => { - const scope = nock('http://example.com/abc') + const scope = nock('http://example.test/abc') .get('/def') .reply(200, 'Hello World!') - const { statusCode, body } = await got('http://example.com/abc/def', { + const { statusCode, body } = await got('http://example.test/abc/def', { encoding: null, }) @@ -67,11 +67,11 @@ test('get gets mocked with relative base path', async t => { }) test('post', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .post('/form') .reply(201, 'OK!') - const { statusCode, body } = await got.post('http://example.com/form', { + const { statusCode, body } = await got.post('http://example.test/form', { encoding: null, }) @@ -82,11 +82,11 @@ test('post', async t => { }) test('post with empty response body', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .post('/form') .reply(200) - const { statusCode, body } = await got.post('http://example.com/form', { + const { statusCode, body } = await got.post('http://example.test/form', { encoding: null, }) @@ -99,14 +99,14 @@ test('post with empty response body', async t => { test('post, lowercase', t => { let dataCalled = false - const scope = nock('http://example.com') + const scope = nock('http://example.test') .post('/form') .reply(200, 'OK!') // Since this is testing a lowercase `method`, it's using the `http` module. const req = http.request( { - host: 'example.com', + host: 'example.test', method: 'post', path: '/form', port: 80, @@ -132,22 +132,22 @@ test('post, lowercase', t => { test('post with regexp as spec', async t => { const input = 'key=val' - const scope = nock('http://example.com') + const scope = nock('http://example.test') .post('/echo', /key=v.?l/g) .reply(200, (uri, body) => ['OK', uri, body].join(' ')) - const { body } = await got('http://example.com/echo', { body: input }) + const { body } = await got('http://example.test/echo', { body: input }) t.equal(body, 'OK /echo key=val') scope.done() }) test('post with function as spec', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .post('/echo', body => body === 'key=val') .reply(200, (uri, body) => ['OK', uri, body].join(' ')) - const { body } = await got('http://example.com/echo', { body: 'key=val' }) + const { body } = await got('http://example.test/echo', { body: 'key=val' }) t.equal(body, 'OK /echo key=val') scope.done() @@ -156,11 +156,11 @@ test('post with function as spec', async t => { test('post with chaining on call', async t => { const input = 'key=val' - const scope = nock('http://example.com') + const scope = nock('http://example.test') .post('/echo', input) .reply(200, (uri, body) => ['OK', uri, body].join(' ')) - const { body } = await got('http://example.com/echo', { body: input }) + const { body } = await got('http://example.test/echo', { body: input }) t.equal(body, 'OK /echo key=val') scope.done() @@ -180,7 +180,7 @@ test('delete request', async t => { test('reply with callback and filtered path and body', async t => { let noPrematureExecution = false - const scope = nock('http://example.com') + const scope = nock('http://example.test') .filteringPath(/.*/, '*') .filteringRequestBody(/.*/, '*') .post('*', '*') @@ -190,7 +190,7 @@ test('reply with callback and filtered path and body', async t => { }) noPrematureExecution = true - const { body } = await got.post('http://example.com/original/path', { + const { body } = await got.post('http://example.test/original/path', { body: 'original=body', }) @@ -872,12 +872,12 @@ test('handles 500 with restify JsonClient', t => { }) test('test request timeout option', t => { - nock('http://example.com') - .get('/test') + nock('http://example.test') + .get('/path') .reply(200, JSON.stringify({ foo: 'bar' })) const options = { - url: 'http://example.com/test', + url: 'http://example.test/path', method: 'GET', timeout: 2000, } @@ -922,23 +922,23 @@ test('do not match when conditionally = false but should match after trying agai test('get correct filtering with scope and request headers filtering', t => { const responseText = 'OK!' const responseHeaders = { 'Content-Type': 'text/plain' } - const requestHeaders = { host: 'a.subdomain.of.google.com' } + const requestHeaders = { host: 'foo.example.test' } - const scope = nock('http://a.subdomain.of.google.com', { + const scope = nock('http://foo.example.test', { filteringScope: function(scope) { - return /^http:\/\/.*\.google\.com/.test(scope) + return /^http:\/\/.*\.example\.test/.test(scope) }, }) - .get('/somepath') + .get('/path') .reply(200, responseText, responseHeaders) let dataCalled = false - const host = 'some.other.subdomain.of.google.com' + const host = 'bar.example.test' const req = http.get( { host, method: 'GET', - path: '/somepath', + path: '/path', port: 80, }, function(res) { @@ -958,8 +958,8 @@ test('get correct filtering with scope and request headers filtering', t => { }) test('different subdomain with reply callback and filtering scope', async t => { - // We scope for www.example.com but through scope filtering we will accept - // any .example.com. + // We scope for www.example.test but through scope filtering we will accept + // any .example.test. const scope = nock('http://example.test', { filteringScope: scope => /^http:\/\/.*\.example/.test(scope), }) @@ -1355,7 +1355,7 @@ test('three argument form of http.request: URL, options, and callback', t => { */ test('works when headers are removed on the socket event', t => { // Set up a nock that will fail if it gets an "authorization" header. - const serviceScope = nock('http://service', { + const serviceScope = nock('http://example.test', { badheaders: ['authorization'], }) .get('/endpoint') @@ -1365,7 +1365,7 @@ test('works when headers are removed on the socket event', t => { const server = http.createServer((request, response) => { // Make a request to the nock instance with the same request that came in. const proxyReq = http.request({ - host: 'service', + host: 'example.test', // Get the path from the incoming request and pass it through path: `/${request.url .split('/') diff --git a/tests/test_recorder.js b/tests/test_recorder.js index e791bd92b..2beb3c32a 100644 --- a/tests/test_recorder.js +++ b/tests/test_recorder.js @@ -791,11 +791,11 @@ test("doesn't record request headers by default", t => { output_objects: true, }) - // TODO: replace request to www.example.com with local server http .request( { - hostname: 'www.example.com', + hostname: 'localhost', + port: server.address().port, path: '/', method: 'GET', auth: 'foo:bar', diff --git a/tests/test_reply_function_async.js b/tests/test_reply_function_async.js index e1def552a..88999c074 100644 --- a/tests/test_reply_function_async.js +++ b/tests/test_reply_function_async.js @@ -13,11 +13,11 @@ const got = require('./got_client') require('./cleanup_after_each')() test('reply can take a callback', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply(200, (path, requestBody, callback) => callback(null, 'Hello World!')) - const response = await got('http://example.com/', { + const response = await got('http://example.test/', { encoding: null, }) @@ -33,13 +33,13 @@ test('reply takes a callback for status code', async t => { 'X-Custom-Header': 'abcdef', } - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply((path, requestBody, cb) => { setTimeout(() => cb(null, [expectedStatusCode, responseBody, headers]), 1) }) - const response = await got('http://example.com/') + const response = await got('http://example.test/') t.equal(response.statusCode, expectedStatusCode, 'sends status code') t.deepEqual( @@ -54,7 +54,7 @@ test('reply takes a callback for status code', async t => { test('reply should throw on error on the callback', t => { let dataCalled = false - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply(500, (path, requestBody, callback) => callback(new Error('Database failed')) @@ -64,7 +64,7 @@ test('reply should throw on error on the callback', t => { // to match. const req = http.request( { - host: 'example.com', + host: 'example.test', path: '/', port: 80, }, @@ -110,7 +110,7 @@ test('an error passed to the callback propagates when [err, fullResponseArray] i test('subsequent calls to the reply callback are ignored', async t => { t.plan(3) - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply(201, (path, requestBody, callback) => { callback(null, 'one') @@ -119,7 +119,7 @@ test('subsequent calls to the reply callback are ignored', async t => { t.pass() }) - const { statusCode, body } = await got('http://example.com/') + const { statusCode, body } = await got('http://example.test/') scope.done() t.is(statusCode, 201) diff --git a/tests/test_reply_function_sync.js b/tests/test_reply_function_sync.js index 5b8a1151e..30d9e4d7e 100644 --- a/tests/test_reply_function_sync.js +++ b/tests/test_reply_function_sync.js @@ -12,11 +12,11 @@ const got = require('./got_client') require('./cleanup_after_each')() test('reply with status code and function returning body as string', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply(201, () => 'OK!') - const { statusCode, body } = await got('http://example.com') + const { statusCode, body } = await got('http://example.test') t.is(statusCode, 201) t.equal(body, 'OK!') scope.done() @@ -168,11 +168,11 @@ test('without content-type header, body sent to reply function is not parsed', a // just as easily accomplished with a function returning an array: // `.reply(() => [201, 'ABC', { 'X-My-Headers': 'My custom header value' }])` test('reply with status code, function returning string body, and header object', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply(201, () => 'ABC', { 'X-My-Headers': 'My custom header value' }) - const { headers } = await got('http://example.com/') + const { headers } = await got('http://example.test/') t.equivalent(headers, { 'x-my-headers': 'My custom header value' }) @@ -192,11 +192,11 @@ test('reply function returning array with only status code', async t => { }) test('reply function returning array with status code and string body', async t => { - const scope = nock('http://example.com') + const scope = nock('http://example.test') .get('/') .reply(() => [401, 'This is a body']) - await assertRejects(got('http://example.com/'), ({ statusCode, body }) => { + await assertRejects(got('http://example.test/'), ({ statusCode, body }) => { t.is(statusCode, 401) t.equal(body, 'This is a body') return true