How to use the tap.testdir 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 npm / npm-packlist / test / cannot-exclude-shrinkwrap.js View on Github external
// cannot exclude npm-shrinkwrap.json in the root
const t = require('tap')
const pkg = t.testdir({
  'package.json': JSON.stringify({
    files: ['.npmignore', '!npm-shrinkwrap.json']
  }),
  '.npmignore': 'npm-shrinkwrap.json',
  'npm-shrinkwrap.json': '{}',
})

const packlist = require('../')
t.test('package with negated files', async t => {
  t.matchSnapshot(packlist.sync({path: pkg}))
  await t.resolveMatchSnapshot(packlist({path: pkg}))
})
github npm / npm-packlist / test / package-json-files-and-containing-dir.js View on Github external
// ensure we don't get files more than one time, even if specified
// in ways that will have them included from multiple directions
const t = require('tap')
const pkg = t.testdir({
  'package.json': JSON.stringify({
    files: [
      'lib',
      '/lib/*.js',
      'lib/*.js',
      '/lib/one.js',
      'lib/one.js',
      'lib/one.*',
    ]
  }),
  lib: {
    'one.js': 'one',
    'two.js': 'two',
    'tre.js': 'tre',
    'for.js': 'for',
    '.npmignore': 'two.js',
github npm / npm-packlist / test / package-json-files-nested-dir-and-nested-ignore.js View on Github external
// Show that a nested .npmignore will be skipped over if the
// 'files' array matches a dir that passes by it.
const t = require('tap')
const pkg = t.testdir({
  'package.json': JSON.stringify({
    files: [
      'lib/dir',
    ]
  }),
  lib: {
    dir: {
      'one.js': 'one',
      'two.js': 'two',
      'tre.js': 'tre',
      'for.js': 'for',
    },
    '.npmignore': 'dir/two.js',
    '.DS_Store': 'a store of ds',
  },
})
github npm / pacote / test / index.js View on Github external
const t = require('tap')
const pacote = require('../lib/index.js')
const fs = require('fs')

const { resolve, relative } = require('path')
const abbrev = resolve(__dirname, 'fixtures/abbrev-1.1.1.tgz')
const abbrevspec = `file:${relative(process.cwd(), abbrev)}`
const abbrevMani = require('./fixtures/abbrev-manifest-min.json')
const weird = resolve(__dirname, 'fixtures/weird-pkg.tgz')
const weirdspec = `file:${relative(process.cwd(), weird)}`
const ignore = resolve(__dirname, 'fixtures/ignore-pkg.tgz')
const ignorespec = `file:${relative(process.cwd(), ignore)}`

const mkdirp = require('mkdirp')
const me = t.testdir()

t.cleanSnapshot = str => str
  .split(process.cwd()).join('${CWD}')
  .replace(/\\/g, '/')

t.resolveMatchSnapshot(pacote.resolve(abbrevspec), 'resolve')
t.resolveMatchSnapshot(pacote.extract(abbrevspec, me + '/extract'), 'extract')
t.resolveMatchSnapshot(pacote.manifest(abbrevspec), 'manifest')
t.resolveMatchSnapshot(pacote.packument(abbrevspec), 'packument')
t.resolveMatch(pacote.tarball(abbrevspec), fs.readFileSync(abbrev), 'tarball')
t.resolveMatchSnapshot(pacote.tarball.file(abbrevspec, me + '/tarball.tgz'),
  'tarball to file').then(() =>
    t.match(fs.readFileSync(me + '/tarball.tgz'), fs.readFileSync(abbrev)))
const stream = pacote.tarball.stream(abbrevspec, stream =>
  new Promise((res, rej) => {
    stream.on('end', res)
github npm / npm-packlist / test / package-json-read-fail.js View on Github external
const mutateFS = require('mutate-fs')
const t = require('tap')
const pkg = t.testdir({
  'package.json': 'no json here',
  'index.js': '',
})

const packlist = require('../')
t.test('read fails on package.json', async t => {
  const poop = new Error('poop')
  t.teardown(mutateFS.fail('readFile', poop))

  t.rejects(packlist({ path: pkg }), poop)
  t.throws(() => packlist.sync({ path: pkg }), poop)
})
github npm / pacote / test / fetcher.js View on Github external
if (fakeSudo) {
  process.realUid = process.getuid()
  process.getuid = () => 0
  const fakeChown = type => (path, uid, gid, cb) => {
    process.chownLog.push({type, path, uid, gid})
    process.nextTick(cb)
  }
  const chown = fs.chown
  const lchown = fs.lchown
  fs.chown = fakeChown('chown')
  fs.lchown = fakeChown('lchown')
}

const { relative, resolve, basename } = require('path')
const t = require('tap')
const me = t.testdir()
const Fetcher = require('../lib/fetcher.js')
t.cleanSnapshot = s => s.split(process.cwd()).join('{CWD}')

const npa = require('npm-package-arg')
const { promisify } = require('util')
const mkdirp = require('mkdirp')

const _tarballFromResolved = Symbol.for('pacote.Fetcher._tarballFromResolved')

const abbrev = resolve(__dirname, 'fixtures/abbrev-1.1.1.tgz')
const abbrevspec = `file:${relative(process.cwd(), abbrev)}`
const abbrevMani = require('./fixtures/abbrev-manifest-min.json')
const weird = resolve(__dirname, 'fixtures/weird-pkg.tgz')
const weirdspec = `file:${relative(process.cwd(), weird)}`
const ignore = resolve(__dirname, 'fixtures/ignore-pkg.tgz')
const ignorespec = `file:${relative(process.cwd(), ignore)}`
github npm / pacote / test / dir.js View on Github external
const DirFetcher = require('../lib/dir.js')
const t = require('tap')
const npa = require('npm-package-arg')
const fs = require('fs')
const { promisify } = require('util')

const { relative, resolve, basename } = require('path')

const me = t.testdir()

t.cleanSnapshot = str => str.split(process.cwd()).join('${CWD}')

const abbrev = resolve(__dirname, 'fixtures/abbrev')
const abbrevspec = `file:${relative(process.cwd(), abbrev)}`

t.test('basic', t => {
  const f = new DirFetcher(abbrevspec, {})
  t.same(f.types, ['directory'])
  t.resolveMatchSnapshot(f.packument(), 'packument')
  t.resolveMatchSnapshot(f.manifest(), 'manifest')
  const pj = me + '/abbrev/package.json'
  return t.resolveMatchSnapshot(f.extract(me + '/abbrev'), 'extract')
    .then(() => t.matchSnapshot(require(pj), 'package.json extracted'))
    .then(() => t.matchSnapshot(f.package, 'saved package.json'))
    .then(() => f.manifest().then(mani => t.equal(mani, f.package)))
github npm / pacote / test / remote.js View on Github external
const RemoteFetcher = require('../lib/remote.js')
const http = require('http')
const t = require('tap')

const { relative, resolve } = require('path')
const me = t.testdir()
const cache = resolve(me, 'cache')

t.cleanSnapshot = str => str.split(''+port).join('{PORT}')

const fs = require('fs')
const abbrev = resolve(__dirname, 'fixtures/abbrev-1.1.1.tgz')
const abbrevspec = `file:${relative(process.cwd(), abbrev)}`
const abbrevMani = require('./fixtures/abbrev-manifest-min.json')
const port = 12345 + (+process.env.TAP_CHILD_ID || 0)
const server = `http://localhost:${port}`
const requestLog = []
t.test('start server', t => {
  const data = fs.readFileSync(abbrev)
  const server = http.createServer((req, res) => {
    res.setHeader('cache-control', 'max-age=432000')
    res.setHeader('accept-ranges', 'bytes')
github npm / npm-packlist / test / package-json-filed-dir-nested-npmignore.js View on Github external
const t = require('tap')
const pkg = t.testdir({
  'package.json': JSON.stringify({
    files: [
      'lib',
    ]
  }),
  lib: {
    'one.js': 'one',
    'two.js': 'two',
    'tre.js': 'tre',
    'for.js': 'for',
    '.npmignore': 'two.js',
    '.DS_Store': 'a store of ds',
  },
})

const packlist = require('../')
github npm / npm-packlist / test / package-json-files-including-npmignore.js View on Github external
const t = require('tap')
const pkg = t.testdir({
  'package.json': JSON.stringify({
    files: [
      'lib/sub/*.js',
      '.npmignore',
    ]
  }),
  lib: {
    sub: {
      'one.js': 'one',
      'two.js': 'two',
      'tre.js': 'tre',
      'for.js': 'for',
    },
    '.DS_Store': 'a store of ds',
  },
  '.npmignore': 'two.js',