How to use nyc - 10 common examples

To help you get started, we’ve selected a few nyc 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 atom / github / test / runner.js View on Github external
global._nycInProcess = true;
} else if (process.env.NYC_CONFIG) {
  // Istanbul is running us from a parent process. Simulate the wrap.js call in:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/wrap.js

  const parentPid = process.env.NYC_PARENT_PID || '0';
  process.env.NYC_PARENT_PID = process.pid;

  const config = JSON.parse(process.env.NYC_CONFIG);
  config.isChildProcess = true;
  config._processInfo = {
    ppid: parentPid,
    root: process.env.NYC_ROOT_ID,
  };
  global._nyc = new NYC(config);
  global._nyc.wrap();
}

const testSuffixes = process.env.ATOM_GITHUB_TEST_SUITE === 'snapshot' ? ['snapshot.js'] : ['test.js'];

module.exports = createRunner({
  htmlTitle: `GitHub Package Tests - pid ${process.pid}`,
  reporter: process.env.MOCHA_REPORTER || 'list',
  overrideTestPaths: [/spec$/, /test/],
  testSuffixes,
}, (mocha, {terminate}) => {
  // Ensure that we expect to be deployable to this version of Atom.
  const engineRange = require('../package.json').engines.atom;
  const atomEnv = global.buildAtomEnvironment();
  const atomVersion = atomEnv.getVersion();
  const atomReleaseChannel = atomEnv.getReleaseChannel();
github qlik-oss / after-work.js / src / browser / browser-test-runner.js View on Github external
/* eslint camelcase:0, no-process-exit: 0, no-console: 0 */
import path from 'path';
import fs from 'fs';
import util from 'util';
import globby from 'globby';
import Promise from 'bluebird';
import { create } from 'browser-sync';
import child_process from 'child_process';
import program from 'commander';
import NYC from 'nyc';
import disableCache from './disable-cache';

const nyc = new NYC({
  reporter: ['text', 'lcov', 'text-summary'],
});
const instrumenter = nyc.instrumenter();

function srcFiles(files) {
  return files.map(f => ``).join('\n');
}

export function relativeFromDirToCwd(p) {
  return path.relative(process.cwd(), path.resolve(__dirname, p));
}

export function relativeToCwd(p) {
  return path.relative(process.cwd(), path.resolve(p));
}
github atom / github / test / runner.js View on Github external
// And the process-under-test wrapping done by:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/wrap.js

  const configUtil = require('nyc/lib/config-util');

  const yargs = configUtil.buildYargs();
  const config = configUtil.loadConfig({}, path.join(__dirname, '..'));
  configUtil.addCommandsAndHelp(yargs);
  const argv = yargs.config(config).parse([]);

  argv.instrumenter = require.resolve('nyc/lib/instrumenters/noop');
  argv.reporter = 'lcovonly';
  argv.cwd = path.join(__dirname, '..');
  argv.tempDirectory = path.join(__dirname, '..', '.nyc_output');

  global._nyc = new NYC(argv);

  if (argv.clean) {
    global._nyc.reset();
  } else {
    global._nyc.createTempDirectory();
  }
  if (argv.all) {
    global._nyc.addAllFiles();
  }

  process.env.NYC_CONFIG = JSON.stringify(argv);
  process.env.NYC_CWD = path.join(__dirname, '..');
  process.env.NYC_ROOT_ID = global._nyc.rootId;
  process.env.NYC_INSTRUMENTER = argv.instrumenter;
  process.env.NYC_PARENT_PID = process.pid;
github atom / github / test / runner.js View on Github external
// Give tests that rely on filesystem event delivery lots of breathing room.
until.setDefaultTimeout(parseInt(process.env.UNTIL_TIMEOUT || '3000', 10));

if (process.env.ATOM_GITHUB_BABEL_ENV === 'coverage' && !process.env.NYC_CONFIG) {
  // Set up Istanbul in this process.
  // This mimics the argument parsing and setup performed in:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/nyc.js
  // And the process-under-test wrapping done by:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/wrap.js

  const configUtil = require('nyc/lib/config-util');

  const yargs = configUtil.buildYargs();
  const config = configUtil.loadConfig({}, path.join(__dirname, '..'));
  configUtil.addCommandsAndHelp(yargs);
  const argv = yargs.config(config).parse([]);

  argv.instrumenter = require.resolve('nyc/lib/instrumenters/noop');
  argv.reporter = 'lcovonly';
  argv.cwd = path.join(__dirname, '..');
  argv.tempDirectory = path.join(__dirname, '..', '.nyc_output');

  global._nyc = new NYC(argv);

  if (argv.clean) {
    global._nyc.reset();
  } else {
    global._nyc.createTempDirectory();
  }
  if (argv.all) {
    global._nyc.addAllFiles();
github atom / github / test / runner.js View on Github external
chai.use(chaiAsPromised);
global.assert = chai.assert;

// Give tests that rely on filesystem event delivery lots of breathing room.
until.setDefaultTimeout(parseInt(process.env.UNTIL_TIMEOUT || '3000', 10));

if (process.env.ATOM_GITHUB_BABEL_ENV === 'coverage' && !process.env.NYC_CONFIG) {
  // Set up Istanbul in this process.
  // This mimics the argument parsing and setup performed in:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/nyc.js
  // And the process-under-test wrapping done by:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/wrap.js

  const configUtil = require('nyc/lib/config-util');

  const yargs = configUtil.buildYargs();
  const config = configUtil.loadConfig({}, path.join(__dirname, '..'));
  configUtil.addCommandsAndHelp(yargs);
  const argv = yargs.config(config).parse([]);

  argv.instrumenter = require.resolve('nyc/lib/instrumenters/noop');
  argv.reporter = 'lcovonly';
  argv.cwd = path.join(__dirname, '..');
  argv.tempDirectory = path.join(__dirname, '..', '.nyc_output');

  global._nyc = new NYC(argv);

  if (argv.clean) {
    global._nyc.reset();
  } else {
    global._nyc.createTempDirectory();
  }
github atom / github / test / runner.js View on Github external
global.assert = chai.assert;

// Give tests that rely on filesystem event delivery lots of breathing room.
until.setDefaultTimeout(parseInt(process.env.UNTIL_TIMEOUT || '3000', 10));

if (process.env.ATOM_GITHUB_BABEL_ENV === 'coverage' && !process.env.NYC_CONFIG) {
  // Set up Istanbul in this process.
  // This mimics the argument parsing and setup performed in:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/nyc.js
  // And the process-under-test wrapping done by:
  //   https://github.com/istanbuljs/nyc/blob/v13.0.0/bin/wrap.js

  const configUtil = require('nyc/lib/config-util');

  const yargs = configUtil.buildYargs();
  const config = configUtil.loadConfig({}, path.join(__dirname, '..'));
  configUtil.addCommandsAndHelp(yargs);
  const argv = yargs.config(config).parse([]);

  argv.instrumenter = require.resolve('nyc/lib/instrumenters/noop');
  argv.reporter = 'lcovonly';
  argv.cwd = path.join(__dirname, '..');
  argv.tempDirectory = path.join(__dirname, '..', '.nyc_output');

  global._nyc = new NYC(argv);

  if (argv.clean) {
    global._nyc.reset();
  } else {
    global._nyc.createTempDirectory();
  }
  if (argv.all) {
github tapjs / node-tap / bin / run.js View on Github external
'tap-parser': require('tap-parser/package.json').version,
      nyc: require('nyc/package.json').version,
      'tap-yaml': require('tap-yaml/package.json').version,
      treport: require('treport/package.json').version,
      tcompare: require('tcompare/package.json').version,
    }))
  }

  if (options.version)
    return console.log(require('../package.json').version)

  if (options['parser-version'])
    return console.log(require('tap-parser/package.json').version)

  if (options['nyc-version'])
    return console.log(require('nyc/package.json').version)

  if (options['nyc-help'])
    return nycHelp()

  process.stdout.on('error', er => {
    /* istanbul ignore else */
    if (er.code === 'EPIPE')
      process.exit()
    else
      throw er
  })

  // we test this directly, not from here.
  /* istanbul ignore next */
  if (options.watch)
    return new Repl(options, process.stdin, process.stdout)
github chaijs / type-detect / rollup.conf.js View on Github external
import coverage from 'rollup-plugin-istanbul';
import common from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import transform from 'rollup-plugin-buble';
import nyc from 'nyc';
const Instrumenter = (new (new nyc)._instrumenterLib.istanbul).createInstrumenter; // eslint-disable-line
const env = process.env.NODE_ENV || 'test'; // eslint-disable-line no-process-env
const plugins = [ common(), resolve(), transform() ];
if (env === 'test') {
  plugins.unshift(coverage({ exclude: 'test/*.js', instrumenter: { Instrumenter } }));
}
export default {
  input: env === 'test' ? 'test/index.js' : 'index.js',
  output: {
    file: env === 'test' ? 'type-detect.test.js' : 'type-detect.js',
    name: 'typeDetect',
    format: 'umd',
  },
  plugins,
};
github blackflux / js-gardener / lib / subtasks / nyc.js View on Github external
nyc.reset();
  if (wrap) {
    nyc.wrap();
  }
  testFilesAbs.forEach((f) => {
    safeDeleteCache(f);
    mocha.addFile(f);
  });
  srcFilesAbs.forEach((f) => {
    logger.info(`Loading ${f}`);
    // eslint-disable-next-line global-require, import/no-dynamic-require
    require(`${f}`);
  });

  // eslint-disable-next-line no-underscore-dangle
  const coverageSaved = libCoverage.createCoverageMap(global.__coverage__);
  let success = true;
  const runner = mocha.run((failures) => {
    success = success && failures === 0;
  });
  runner.on('end', () => {
    nyc.writeCoverageFile();
    nyc.report();
    nyc.checkCoverage({
      lines: 100,
      statements: 100,
      functions: 100,
      branches: 100
    }, false);
    /* eslint-disable no-underscore-dangle */
    coverageSaved.merge(global.__coverage__);
    global.__coverage__ = coverageSaved.toJSON();
github SSENSE / node-cucumber-testrail-sync / tests / coverage / merge.js View on Github external
}
    }
}

if (mergedCoverageMap === null) {
    console.warn('Warning: No cover files to be merged');
    return;
}

var context = libReport.createContext({
    dir: path.join(rootFolder, mergeIntoFolder)
});

tree = libReport.summarizers.pkg(mergedCoverageMap);

tree.visit(reports.create('html'), context);
tree.visit(reports.create('lcov'), context);

fs.writeFileSync(path.join(rootFolder, '..', '..', '.nyc_output', 'coverage-final.json'), JSON.stringify(mergedCoverageMap.toJSON()));