How to use the tap.tearDown function in tap

To help you get started, we’ve selected a few tap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jkyberneees / fast-proxy / test / http2-https.js View on Github external
const got = require('got')
const fs = require('fs')
const path = require('path')
const certs = {
  allowHTTP1: true, // fallback support for HTTP1
  key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
  cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
}

const instance = Fastify({
  http2: true,
  https: certs
})

t.plan(4)
t.tearDown(instance.close.bind(instance))

const target = Fastify({
  https: certs
})

target.get('/', (request, reply) => {
  t.pass('request proxied')
  reply.code(404).header('x-my-header', 'hello!').send({
    hello: 'world'
  })
})

instance.get('/', (request, reply) => {
  reply.from()
})
github mcollina / fastify-secure-session / test / delete.js View on Github external
maxAge: 86400
  }
})

fastify.post('/', (request, reply) => {
  request.session.set('some', request.body.some)
  request.session.set('some2', request.body.some2)
  reply.send('hello world')
})

fastify.post('/delete', (request, reply) => {
  request.session.delete()
  reply.send('hello world')
})

t.tearDown(fastify.close.bind(fastify))
t.plan(14)

fastify.get('/', (request, reply) => {
  const some = request.session.get('some')
  const some2 = request.session.get('some2')
  if (!some || !some2) {
    reply.code(404).send()
    return
  }
  reply.send({ some: some, some2: some2 })
})

fastify.inject({
  method: 'POST',
  url: '/',
  payload: {
github npm / pacote / test / util / test-dir.js View on Github external
function testDir (filename) {
  const base = path.basename(filename, '.js')
  const dir = path.join(cacheDir, base)
  tap.beforeEach(function () {
    return reset(dir)
  })
  if (!process.env.KEEPCACHE) {
    tap.tearDown(function () {
      process.chdir(__dirname)
      try {
        rimraf.sync(dir)
      } catch (e) {
        if (process.platform !== 'win32') {
          throw e
        }
      }
    })
  }
  return dir
}
github npm / make-fetch-happen / test / util / test-dir.js View on Github external
function testDir (filename) {
  const base = path.basename(filename, '.js')
  const dir = path.join(cacheDir, base)
  tap.beforeEach(function () {
    return reset(dir)
  })
  if (!process.env.KEEPCACHE) {
    tap.tearDown(function () {
      process.chdir(__dirname)
      try {
        rimraf.sync(dir)
      } catch (e) {
        if (process.platform !== 'win32') {
          throw e
        }
      }
    })
  }
  return dir
}
github mcollina / fastify-secure-session / test / key.js View on Github external
const fastify = require('fastify')({ logger: false })
const sodium = require('sodium-native')
const key = Buffer.alloc(sodium.crypto_secretbox_KEYBYTES)

sodium.randombytes_buf(key)

fastify.register(require('../'), {
  key
})

fastify.post('/', (request, reply) => {
  request.session.set('data', request.body)
  reply.send('hello world')
})

t.tearDown(fastify.close.bind(fastify))
t.plan(5)

fastify.get('/', (request, reply) => {
  const data = request.session.get('data')
  if (!data) {
    reply.code(404).send()
    return
  }
  reply.send(data)
})

fastify.inject({
  method: 'POST',
  url: '/',
  payload: {
    some: 'data'
github jkyberneees / fast-proxy / test / http2 / http2-http2.js View on Github external
const t = require('tap')
const Fastify = require('fastify')
const From = require('../..')
const fs = require('fs')
const path = require('path')
const certs = {
  key: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'fastify.key')),
  cert: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'fastify.cert'))
}

const instance = Fastify({
  http2: true,
  https: certs
})

t.tearDown(instance.close.bind(instance))

const target = Fastify({
  http2: true
})

target.get('/', (request, reply) => {
  t.pass('request proxied')
  reply.code(404).header('x-my-header', 'hello!').send({
    hello: 'world'
  })
})

instance.get('/', (request, reply) => {
  reply.from()
})
github jkyberneees / fast-proxy / test / base-path.js View on Github external
const Fastify = require('fastify')
const From = require('..')
const get = require('simple-get').concat
const nock = require('nock')

const instance = Fastify()

nock('http://httpbin.org')
  .get('/ip')
  .reply(function (uri, requestBody) {
    t.is(this.req.headers.host, 'httpbin.org')
    return { origin: '127.0.0.1' }
  })

t.plan(6)
t.tearDown(instance.close.bind(instance))

instance.get('/', (request, reply) => {
  reply.from('http://httpbin.org/ip')
})

instance.register(From)

instance.listen(0, (err) => {
  t.error(err)

  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
    t.error(err)
    t.strictEqual(res.statusCode, 200)
    t.strictEqual(res.headers['content-type'], 'application/json')
    t.strictEqual(typeof JSON.parse(data).origin, 'string')
  })
github jkyberneees / fast-proxy / test / host-header.js View on Github external
const Fastify = require('fastify')
const From = require('..')
const get = require('simple-get').concat
const nock = require('nock')

const instance = Fastify()

nock('http://httpbin.org')
  .get('/ip')
  .reply(function (uri, requestBody) {
    t.is(this.req.headers.host, 'httpbin.org')
    return { origin: '127.0.0.1' }
  })

t.plan(6)
t.tearDown(instance.close.bind(instance))

instance.get('*', (request, reply) => {
  reply.from()
})

instance.register(From, {
  base: 'http://httpbin.org'
})

instance.listen(0, (err) => {
  t.error(err)

  get(`http://localhost:${instance.server.address().port}/ip`, (err, res, data) => {
    t.error(err)
    t.strictEqual(res.statusCode, 200)
    t.strictEqual(res.headers['content-type'], 'application/json')
github npm / npm-registry-fetch / test / util / test-dir.js View on Github external
function testDir (filename) {
  const base = path.basename(filename, '.js')
  const dir = path.join(cacheDir, base)
  tap.beforeEach(function () {
    return reset(dir)
  })
  if (!process.env.KEEPCACHE) {
    tap.tearDown(function () {
      process.chdir(__dirname)
      try {
        rimraf.sync(dir)
      } catch (e) {
        if (process.platform !== 'win32') {
          throw e
        }
      }
    })
  }
  return dir
}
github jkyberneees / fast-proxy / test / transform-body.js View on Github external
'use strict'

const t = require('tap')
const Fastify = require('fastify')
const From = require('..')
const http = require('http')
const get = require('simple-get').concat
const Transform = require('stream').Transform

const instance = Fastify()
instance.register(From)

t.plan(9)
t.tearDown(instance.close.bind(instance))

const target = http.createServer((req, res) => {
  t.pass('request proxied')
  t.equal(req.method, 'GET')
  res.statusCode = 205
  res.setHeader('Content-Type', 'text/plain')
  res.setHeader('x-my-header', 'hello!')
  res.end('hello world')
})

instance.get('/', (request, reply) => {
  reply.from(`http://localhost:${target.address().port}`, {
    onResponse: (request, reply, res) => {
      reply.send(
        res.pipe(
          new Transform({