How to use the tap.mochaGlobals 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 / v8-to-istanbul / test / v8-to-istanbul.js View on Github external
/* global describe, it */

const { readdirSync, lstatSync, writeFileSync, readFileSync } = require('fs')
const path = require('path')
const runFixture = require('./utils/run-fixture')
const V8ToIstanbul = require('../lib/v8-to-istanbul')
const crypto = require('crypto')
const os = require('os')
const sourcemap = require('source-map')

require('tap').mochaGlobals()
require('should')

describe('V8ToIstanbul', async () => {
  describe('constructor', () => {
    it('creates line instance for each line in V8ToIstanbul', async () => {
      const v8ToIstanbul = new V8ToIstanbul(
        require.resolve('./fixtures/scripts/functions.js')
      )
      await v8ToIstanbul.load()
      v8ToIstanbul.source.lines.length.should.equal(48)
      v8ToIstanbul.wrapperLength.should.equal(0) // common-js header.
    })

    it('handles ESM style paths', async () => {
      const v8ToIstanbul = new V8ToIstanbul(
        `file://${require.resolve('./fixtures/scripts/functions.js')}`,
github istanbuljs / nyc / test / nyc-integration.js View on Github external
const path = require('path')
const bin = path.resolve(__dirname, '../self-coverage/bin/nyc')
const fixturesCLI = path.resolve(__dirname, './fixtures/cli')
const fixturesHooks = path.resolve(__dirname, './fixtures/hooks')
const fixturesSourceMaps = path.resolve(__dirname, './fixtures/source-maps')
const fakebin = path.resolve(fixturesCLI, 'fakebin')
const fs = require('fs')
const glob = require('glob')
const isWindows = require('is-windows')()
const rimraf = require('rimraf')
const makeDir = require('make-dir')
const spawn = require('child_process').spawn
const si = require('strip-indent')

require('chai').should()
require('tap').mochaGlobals()

// beforeEach
rimraf.sync(path.resolve(fakebin, 'node'))
rimraf.sync(path.resolve(fakebin, 'npm'))
rimraf.sync(path.resolve(fixturesCLI, 'subdir', 'output-dir'))

describe('the nyc cli', function () {
  var env = { PATH: process.env.PATH }

  describe('--include', function () {
    it('can be used to limit bin to instrumenting specific files', function (done) {
      var args = [bin, '--all', '--include', 'half-covered.js', process.execPath, './half-covered.js']

      var proc = spawn(process.execPath, args, {
        cwd: fixturesCLI,
        env: env
github istanbuljs / nyc / test / nyc-index.js View on Github external
const configUtil = require('../self-coverage/lib/config-util')
const NYC = require('../self-coverage')
// we test exit handlers in nyc-integration.js.
NYC.prototype._wrapExit = () => {}

const path = require('path')
const rimraf = require('rimraf')
const isWindows = require('is-windows')()
const spawn = require('child_process').spawn
const fixtures = path.resolve(__dirname, './fixtures')
const bin = path.resolve(__dirname, '../self-coverage/bin/nyc')
const resetState = require('./helpers/reset-state')

require('chai').should()
require('tap').mochaGlobals()

const transpileHook = path.resolve(process.cwd(), './test/fixtures/transpile-hook')

describe('nyc', function () {
  beforeEach(resetState)

  describe('cwd', function () {
    it('sets cwd to process.cwd() if no environment variable is set', function () {
      var nyc = new NYC(configUtil.buildYargs().parse())

      nyc.cwd.should.eql(process.cwd())
    })

    it('uses NYC_CWD environment variable for cwd if it is set', function () {
      process.env.NYC_CWD = path.resolve(__dirname, './fixtures')
      var nyc = new NYC(configUtil.buildYargs().parse())
github istanbuljs / nyc / test / src / nyc-tap.js View on Github external
var glob = require('glob')
var rimraf = require('rimraf')
var isWindows = require('is-windows')()
var spawn = require('child_process').spawn
var fixtures = path.resolve(__dirname, '../fixtures')
var bin = path.resolve(__dirname, '../../self-coverage/bin/nyc')

// beforeEach
glob.sync('**/*/{.nyc_output,.cache}').forEach(function (path) {
  rimraf.sync(path)
})

delete process.env.NYC_CWD

require('chai').should()
require('tap').mochaGlobals()

const transpileHook = path.resolve(process.cwd(), './test/fixtures/transpile-hook')

describe('nyc', function () {
  describe('cwd', function () {
    it('sets cwd to process.cwd() if no environment variable is set', function () {
      var nyc = new NYC(configUtil.buildYargs().parse())

      nyc.cwd.should.eql(process.cwd())
    })

    it('uses NYC_CWD environment variable for cwd if it is set', function () {
      process.env.NYC_CWD = path.resolve(__dirname, '../fixtures')
      var nyc = new NYC(configUtil.buildYargs().parse())

      nyc.cwd.should.equal(path.resolve(__dirname, '../fixtures'))
github istanbuljs / nyc / test / nyc-integration-old.js View on Github external
/* global describe, it, beforeEach, afterEach */

// TODO: finish migrating these tests to use snapshots
const path = require('path')
const bin = path.resolve(__dirname, '../self-coverage/bin/nyc')
const fixturesCLI = path.resolve(__dirname, './fixtures/cli')
const fakebin = path.resolve(fixturesCLI, 'fakebin')
const fs = require('fs')
const isWindows = require('is-windows')()
const cpFile = require('cp-file')
const rimraf = require('rimraf')
const makeDir = require('make-dir')
const { spawn } = require('child_process')

require('chai').should()
require('tap').mochaGlobals()

// beforeEach
rimraf.sync(path.resolve(fakebin, 'node'))
rimraf.sync(path.resolve(fakebin, 'npm'))
rimraf.sync(path.resolve(fixturesCLI, 'subdir', 'output-dir'))

describe('the nyc cli', function () {
  var env = { PATH: process.env.PATH }

  // https://github.com/bcoe/nyc/issues/190
  describe('running "npm test"', function () {
    function writeFakeNPM (shebang) {
      var targetPath = path.resolve(fakebin, 'npm')
      var source = fs.readFileSync(path.resolve(fakebin, 'npm-template.js'))
      fs.writeFileSync(targetPath, '#!' + shebang + '\n' + source)
      fs.chmodSync(targetPath, 493) // 0o755
github hoodiehq / hoodie / test / unit / app.js View on Github external
var _ = require('lodash')
var expect = require('expect.js')

var app = require('../../lib/index')

require('tap').mochaGlobals()
describe('Application', function () {
  it('should expose n number of properties', function () {
    expect(_.size(app)).to.eql(3)
  })

  it('should have a init property', function () {
    expect(app).to.have.property('init')
  })

  it('should have a start property', function () {
    expect(app).to.have.property('start')
  })

  it('should have a configureServer property', function () {
    expect(app).to.have.property('configureServer')
  })
github json5 / json5 / test / errors.js View on Github external
const assert = require('assert')
const JSON5 = require('../lib')

require('tap').mochaGlobals()

describe('JSON5', () => {
    describe('#parse()', () => {
        describe('errors', () => {
            it('throws on empty documents', () => {
                assert.throws(() => {
                    JSON5.parse('')
                },
                err => (
                    err instanceof SyntaxError &&
                    /^JSON5: invalid end of input/.test(err.message) &&
                    err.lineNumber === 1 &&
                    err.columnNumber === 1
                ))
            })
github hoodiehq / hoodie / test / unit / environment.js View on Github external
var expect = require('expect.js')

var config = require('../../lib/core/config')

require('tap').mochaGlobals()
describe('environment', function () {
  it('should expose config function', function () {
    expect(config).to.be.a(Function)
  })
})
github hoodiehq / hoodie / test / unit / utils.js View on Github external
var _ = require('lodash')
var expect = require('expect.js')

var utils = require('../../lib/utils')

require('tap').mochaGlobals()
describe('utils', function () {
  it('should expose n number of properties', function () {
    expect(_.size(utils)).to.eql(5)
  })

  it('should have a generatePassword property', function () {
    expect(utils).to.have.property('generatePassword')
  })

  it('should have a ensureDir property', function () {
    expect(utils).to.have.property('ensureDir')
  })

  it('should have a ensurePaths property', function () {
    expect(utils).to.have.property('ensurePaths')
  })
github json5 / json5 / test / stringify.js View on Github external
const assert = require('assert')
const JSON5 = require('../lib')

require('tap').mochaGlobals()

describe('JSON5', () => {
    describe('#stringify', () => {
        describe('objects', () => {
            it('stringifies empty objects', () => {
                assert.strictEqual(JSON5.stringify({}), '{}')
            })

            it('stringifies unquoted property names', () => {
                assert.strictEqual(JSON5.stringify({a: 1}), '{a:1}')
            })

            it('stringifies single quoted string property names', () => {
                assert.strictEqual(JSON5.stringify({'a-b': 1}), "{'a-b':1}")
            })