How to use the tap.cleanSnapshot 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 / arborist / test / arborist / build-ideal-tree.js View on Github external
.sort((a, b) => a[0].localeCompare(b[0]))
      .map(([name, edge]) => [name, printEdge(edge, 'out')]))
  } : {}),
  ...( tree.target || !tree.children.size ? {}
    : {
      children: new Map([...tree.children.entries()]
        .sort((a, b) => a[0].localeCompare(b[0]))
        .map(([name, tree]) => [name, printTree(tree)]))
    }),
  __proto__: { constructor: tree.constructor },
})

const { format } = require('tcompare')

const cwd = process.cwd()
t.cleanSnapshot = s => s.split(cwd).join('{CWD}')

const printIdeal = (path, opt) => buildIdeal(path, opt).then(printTree)

const buildIdeal = (path, opt) =>
  new Arborist({registry, path, ...(opt || {})}).buildIdealTree(opt)

t.test('testing-peer-deps package', t => {
  const path = resolve(__dirname, '../fixtures/testing-peer-deps')
  return t.resolveMatchSnapshot(printIdeal(path), 'build ideal tree with peer deps')
})

t.test('testing-peer-deps nested', t => {
  const path = resolve(__dirname, '../fixtures/testing-peer-deps-nested')
  return t.resolveMatchSnapshot(printIdeal(path), 'build ideal tree')
    .then(() => t.resolveMatchSnapshot(printIdeal(path, {
      // hit the branch where update is just a list of names
github npm / arborist / test / shrinkwrap.js View on Github external
const Shrinkwrap = require('../lib/shrinkwrap.js')
const Node = require('../lib/node.js')
const Link = require('../lib/link.js')
const calcDepFlags = require('../lib/calc-dep-flags.js')
const mutateFS = require('mutate-fs')

const t = require('tap')

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

const {relative, resolve, basename} = require('path')
const fixture = resolve(__dirname, 'fixtures/install-types')
const swonlyFixture = resolve(__dirname, 'fixtures/install-types-sw-only')
const YarnLock = require('../lib/yarn-lock.js')
const yarnFixture = resolve(__dirname, 'fixtures/yarn-stuff')
const emptyFixture = resolve(__dirname, 'fixtures/empty')
const depTypesFixture = resolve(__dirname, 'fixtures/dev-deps')
const badJsonFixture = resolve(__dirname, 'fixtures/testing-peer-deps-bad-sw')

t.test('path defaults to .', async t => {
  const sw = new Shrinkwrap()
  t.equal(sw.path, process.cwd())
})

t.test('load and then reset gets empty lockfile', t =>
github npm / arborist / test / spec-from-lock.js View on Github external
const sfl = require('../lib/spec-from-lock.js')
const t = require('tap')
const cwd = process.cwd()
const dirname = require('path').dirname(cwd)

t.cleanSnapshot = s => s
  .split(cwd).join('{CWD}')
  .split(dirname).join('{..}')
  .split(/\s+"pathmatch": .*/g).join('\n{pathmatch regexp},')

t.matchSnapshot(sfl('x', {
  version: '1.2.3',
  integrity: 'integral',
}), 'version and integrity')

t.matchSnapshot(sfl('gitthing', {
  version: 'git+ssh://git@github.com/isaacs/abbrev-js#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb',
  from: 'github:isaacs/abbrev-js#some-ref',
}), 'git repo with resolved value')

t.matchSnapshot(sfl('legacy', {
  from: '1.2.3',
github npm / pacote / test / index.js View on Github external
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)
    stream.on('error', rej)
    stream.pipe(fs.createWriteStream(me + '/stream.tgz'))
github npm / pacote / test / fetcher.js View on Github external
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)}`

const cacache = require('cacache')
github npm / pacote / test / bin.js View on Github external
const bin = require.resolve('../lib/bin.js')
const {main, run, usage, parseArg, parse} = require('../lib/bin.js')
const {spawn} = require('child_process')
const t = require('tap')
const version = require('../package.json').version
t.cleanSnapshot = str =>
  str.split(version).join('{VERSION}')
  .split(process.env.HOME).join('{HOME}')

const pacote = require('../')
const called = []
pacote.resolve = (spec, conf) =>
  spec === 'fail' ? Promise.reject(new Error('fail'))
  : spec === 'string' ? Promise.resolve('just a string')
  : Promise.resolve({method: 'resolve', spec, conf})
pacote.manifest = (spec, conf) => Promise.resolve({
  method: 'manifest',
  spec,
  conf,
  _resolved: 'manifest resolved',
  _integrity: 'manifest integrity',
  _from: 'manifest from',
github npm / pacote / test / file.js View on Github external
const FileFetcher = require('../lib/file.js')
const t = require('tap')
const { relative, resolve, basename } = require('path')
const npa = require('npm-package-arg')
const { promisify } = require('util')
const rimraf = promisify(require('rimraf'))
const mkdirp = require('mkdirp')
const me = t.testdir()
t.cleanSnapshot = str => str.split(process.cwd()).join('${CWD}')

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

t.test('basic', async t => {
  const f = new FileFetcher(abbrevspec, {})
  t.same(f.types, ['file'])
  const fm = await f.manifest()
  t.matchSnapshot(fm, 'manifest')
  t.equal(fm, f.package)
  t.equal(await f.manifest(), fm, 'cached manifest')
  t.matchSnapshot(await f.packument(), 'packument')
  const pj = me + '/extract/package.json'
  return t.resolveMatchSnapshot(f.extract(me + '/extract'), 'extract')
    .then(() => t.matchSnapshot(require(pj), 'package.json extracted'))
})
github npm / arborist / test / arborist / load-virtual.js View on Github external
.sort((a, b) => a[0].localeCompare(b[0]))
      .map(([name, edge]) => [name, printEdge(edge, 'out')]))
  } : {}),
  ...( tree.target || !tree.children.size ? {}
    : {
      children: new Map([...tree.children.entries()]
        .sort((a, b) => a[0].localeCompare(b[0]))
        .map(([name, tree]) => [name, printTree(tree)]))
    }),
  __proto__: { constructor: tree.constructor },
})

const { format } = require('tcompare')

const cwd = process.cwd()
t.cleanSnapshot = s => s.split(cwd).join('{CWD}')

const loadVirtual = path => new Arborist({path}).loadVirtual()

t.test('load from fixture', t =>
  loadVirtual(fixture).then(tree =>
    t.matchSnapshot(printTree(tree), 'loaded virtual tree from fixture')))

t.test('load from cwd', t => {
  const cwd = process.cwd()
  t.teardown(() => process.chdir(cwd))
  process.chdir(fixture)
  return loadVirtual().then(tree =>
    t.matchSnapshot(printTree(tree), 'loaded virtual tree from fixture'))
})

t.test('loading without a package-lock fails', t =>
github npm / arborist / test / load-virtual.js View on Github external
.sort((a, b) => a[0].localeCompare(b[0]))
      .map(([name, edge]) => [name, printEdge(edge, 'out')]))
  } : {}),
  ...( tree.target || !tree.children.size ? {}
    : {
      children: new Map([...tree.children.entries()]
        .sort((a, b) => a[0].localeCompare(b[0]))
        .map(([name, tree]) => [name, printTree(tree)]))
    }),
  __proto__: { constructor: tree.constructor },
})

const { format } = require('tcompare')

const cwd = process.cwd()
t.cleanSnapshot = s => s.split(cwd).join('{CWD}')

t.test('load from fixture', t =>
  loadVirtual(fixture).then(tree =>
    t.matchSnapshot(printTree(tree), 'loaded virtual tree from fixture')))

t.test('load from cwd', t => {
  const cwd = process.cwd()
  t.teardown(() => process.chdir(cwd))
  process.chdir(fixture)
  return loadVirtual().then(tree =>
    t.matchSnapshot(printTree(tree), 'loaded virtual tree from fixture'))
})

t.test('loading without a package-lock fails', t =>
  t.rejects(loadVirtual(badfixture), {
    message: 'loadVirtual requires a package-lock.json or npm-shrinkwrap.json',
github npm / arborist / test / arborist / reify.js View on Github external
.sort((a, b) => a[0].localeCompare(b[0]))
      .map(([name, edge]) => [name, printEdge(edge, 'out')]))
  } : {}),
  ...( tree.target || !tree.children.size ? {}
    : {
      children: new Map([...tree.children.entries()]
        .sort((a, b) => a[0].localeCompare(b[0]))
        .map(([name, tree]) => [name, printTree(tree)]))
    }),
  __proto__: { constructor: tree.constructor },
})

const { format } = require('tcompare')

const cwd = process.cwd()
t.cleanSnapshot = s => s.split(cwd).join('{CWD}')

const fixture = (t, p) =>
  t.testdir(require('../fixtures/reify-cases/' + p)(t))

const printReified = (path, opt) => reify(path, opt).then(printTree)

const reify = (path, opt) =>
  new Arborist({registry, path, ...(opt || {})}).reify(opt)

t.test('testing-peer-deps package', t =>
  t.resolveMatchSnapshot(printReified(fixture(t, 'testing-peer-deps'))))

t.test('testing-peer-deps nested', t =>
  t.resolveMatchSnapshot(printReified(fixture(t, 'testing-peer-deps-nested'))))

t.test('testing-peer-deps nested with update', t =>