How to use the tap.beforeEach 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 istanbuljs / nyc / test / wrap.js View on Github external
const fs = require('fs')
const path = require('path')

const t = require('tap')

const NYC = require('../self-coverage')

const { parseArgv, resetState } = require('./helpers')

// we test exit handlers in nyc-integration.js.
NYC.prototype._wrapExit = () => {}

const fixtures = path.resolve(__dirname, 'fixtures')
const configMultExt = path.resolve(fixtures, 'conf-multiple-extensions')

t.beforeEach(resetState)

t.test('wraps modules with coverage counters when they are required', async t => {
  const nyc = new NYC(await parseArgv())
  await nyc.reset()
  nyc.wrap()

  const check = require('./fixtures/check-instrumented')
  t.strictEqual(check(), true)
})

t.test('wraps modules with coverage counters when the custom require hook compiles them', async t => {
  let required = false
  const hook = function (module, filename) {
    if (filename.indexOf('check-instrumented.js') !== -1) {
      required = true
    }
github npm / cacache / 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((cb) => {
    reset(dir, (err) => {
      if (err) {
        throw err
      }
      cb()
    })
  })
  if (!process.env.KEEPCACHE) {
    tap.tearDown(() => {
      process.chdir(__dirname)
      // This is ok cause this is the last
      // thing to run in the process
      rimraf(dir, () => {})
    })
  }
  return dir
github istanbuljs / nyc / test / add-all-files.js View on Github external
'use strict'

const fs = require('../lib/fs-promises')
const path = require('path')

const t = require('tap')
const ap = require('any-path')

const NYC = require('../self-coverage')

const { parseArgv, resetState } = require('./helpers')

const fixtures = path.resolve(__dirname, 'fixtures')
const transpileHook = path.resolve(__dirname, 'fixtures/transpile-hook')

t.beforeEach(resetState)

t.test('outputs an empty coverage report for all files that are not excluded', async t => {
  const nyc = new NYC(await parseArgv(fixtures))
  await nyc.reset()
  await nyc.addAllFiles()

  const notLoadedPath = path.join(fixtures, './not-loaded.js')
  const reports = (await nyc.coverageData()).filter(report => ap(report)[notLoadedPath])
  const report = reports[0][notLoadedPath]

  t.strictEqual(reports.length, 1)
  t.strictEqual(report.s['0'], 0)
  t.strictEqual(report.s['1'], 0)
})

t.test('outputs an empty coverage report for multiple configured extensions', async t => {
github mongaku / mongaku / tests / init.js View on Github external
},
            "testData": testFiles,
            "public": publicFiles,
            "views": Object.assign({
                "types": {
                    "filter": typeFilterFiles,
                    "view": typeViewFiles,
                },
            }, viewFiles),
        });

        done();
    });
};

tap.beforeEach(init);

tap.afterEach((done) => {
    app.close();
    sandbox.restore();
    mockfs.restore();
    done();
});

module.exports = {
    getBatch: () => batch,
    getBatches: () => batches,
    getRecordBatch: () => recordBatch,
    getImage: () => image,
    getSource: () => source,
    getRecord: () => primaryRecord,
    getRecords: () => records,
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 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 istanbuljs / nyc / test / cache.js View on Github external
'use strict'

const path = require('path')
const { promisify } = require('util')

const t = require('tap')
const rimraf = promisify(require('rimraf'))

const NYC = require('../self-coverage')

const { parseArgv, resetState, runNYC } = require('./helpers')

const fixtures = path.resolve(__dirname, './fixtures')

t.beforeEach(resetState)

async function cacheTest (t, script) {
  const nyc = new NYC(await parseArgv(fixtures))
  await rimraf(nyc.cacheDirectory)

  const { status } = await runNYC({
    args: [
      process.execPath,
      script
    ],
    cwd: fixtures,
    env: {}
  })

  t.strictEqual(status, 0)
}
github jeresig / pharos-images / tests / init.js View on Github external
},
            "testData": testFiles,
            "public": publicFiles,
            "views": Object.assign({
                "types": {
                    "filter": typeFilterFiles,
                    "view": typeViewFiles,
                },
            }, viewFiles),
        });

        done();
    });
};

tap.beforeEach(init);

tap.afterEach((done) => {
    app.close();
    sandbox.restore();
    mockfs.restore();
    done();
});

module.exports = {
    getBatch: () => batch,
    getBatches: () => batches,
    getArtworkBatch: () => artworkBatch,
    getImage: () => image,
    getSource: () => source,
    getArtwork: () => artwork,
    getArtworks: () => artworks,
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 istanbuljs / nyc / test / report.js View on Github external
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')

const t = require('tap')
const isWindows = require('is-windows')()
const rimraf = promisify(require('rimraf'))

const NYC = require('../self-coverage')

const { parseArgv, runNYC, resetState } = require('./helpers')

const fixtures = path.resolve(__dirname, 'fixtures')

t.beforeEach(resetState)

async function testSignal (t, signal) {
  if (isWindows) {
    t.end()

    return
  }

  const nyc = new NYC(await parseArgv(fixtures))
  await runNYC({
    args: [`./${signal}.js`],
    cwd: fixtures
  })

  const checkFile = path.join(fixtures, `${signal}.js`)
  const reports = (await nyc.coverageData()).filter(report => report[checkFile])