Skip to content

Commit

Permalink
test: change tests to use test domain (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastermatt committed Jul 23, 2019
1 parent 4a4b8ec commit ad264cb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions tests/test_common.js
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_events.js
Expand Up @@ -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()
})

Expand Down
64 changes: 32 additions & 32 deletions tests/test_intercept.js
Expand Up @@ -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()
Expand All @@ -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,
})

Expand All @@ -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,
})

Expand All @@ -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,
})

Expand All @@ -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,
})

Expand All @@ -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,
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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('*', '*')
Expand All @@ -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',
})

Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 <subdomain>.example.com.
// We scope for www.example.test but through scope filtering we will accept
// any <subdomain>.example.test.
const scope = nock('http://example.test', {
filteringScope: scope => /^http:\/\/.*\.example/.test(scope),
})
Expand Down Expand Up @@ -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')
Expand All @@ -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('/')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_recorder.js
Expand Up @@ -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',
Expand Down
16 changes: 8 additions & 8 deletions tests/test_reply_function_async.js
Expand Up @@ -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,
})

Expand All @@ -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(
Expand All @@ -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'))
Expand All @@ -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,
},
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_reply_function_sync.js
Expand Up @@ -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()
Expand Down Expand Up @@ -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' })

Expand All @@ -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
Expand Down

0 comments on commit ad264cb

Please sign in to comment.