<commit_before>'use strict'
var test = require('tap').test
var npm = require('../../lib/npm')
var stream = require('readable-stream')

var moduleName = 'xyzzy-wibble'
var testModule = {
  name: moduleName,
  'dist-tags': {
    latest: '1.3.0-a'
  },
  versions: {
    '1.0.0-a': {
      name: moduleName,
      version: '1.0.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.0.0-a.tgz'
      }
    },
    '1.1.0-a': {
      name: moduleName,
      version: '1.1.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.1.0-a.tgz'
      }
    },
    '1.2.0-a': {
      name: moduleName,
      version: '1.2.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.2.0-a.tgz'
      }
    },
    '1.3.0-a': {
      name: moduleName,
      version: '1.3.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.3.0-a.tgz'
      }
    }
  }
}

var lastFetched
test('setup', function (t) {
  npm.load(function () {
    npm.config.set('loglevel', 'silly')
    npm.registry = {
      get: function (uri, opts, cb) {
        setImmediate(function () {
          cb(null, testModule, null, {statusCode: 200})
        })
      },
      fetch: function (u, opts, cb) {
        lastFetched = u
        setImmediate(function () {
          var empty = new stream.Readable()
          empty.push(null)
          cb(null, empty)
        })
      }
    }
    t.end()
  })
})

test('splat', function (t) {
  t.plan(4)
  var addNamed = require('../../lib/cache/add-named.js')
  addNamed('xyzzy-wibble', '*', testModule, function (err, pkg) {
    t.error(err, 'Succesfully resolved a splat package')
    t.is(pkg.name, moduleName)
    t.is(pkg.version, testModule['dist-tags'].latest)
    t.is(lastFetched, 'https://registry.npmjs.org/aproba/-/xyzzy-wibble-1.3.0-a.tgz')
  })
})<commit_msg>test: Remove setImmediates for 0.8 compatibility<commit_after>'use strict'
var test = require('tap').test
var npm = require('../../lib/npm')
var stream = require('readable-stream')

var moduleName = 'xyzzy-wibble'
var testModule = {
  name: moduleName,
  'dist-tags': {
    latest: '1.3.0-a'
  },
  versions: {
    '1.0.0-a': {
      name: moduleName,
      version: '1.0.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.0.0-a.tgz'
      }
    },
    '1.1.0-a': {
      name: moduleName,
      version: '1.1.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.1.0-a.tgz'
      }
    },
    '1.2.0-a': {
      name: moduleName,
      version: '1.2.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.2.0-a.tgz'
      }
    },
    '1.3.0-a': {
      name: moduleName,
      version: '1.3.0-a',
      dist: {
        shasum: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
        tarball: 'http://registry.npmjs.org/aproba/-/xyzzy-wibble-1.3.0-a.tgz'
      }
    }
  }
}

var lastFetched
test('setup', function (t) {
  npm.load(function () {
    npm.config.set('loglevel', 'silly')
    npm.registry = {
      get: function (uri, opts, cb) {
        setTimeout(function () {
          cb(null, testModule, null, {statusCode: 200})
        })
      },
      fetch: function (u, opts, cb) {
        lastFetched = u
        setTimeout(function () {
          var empty = new stream.Readable()
          empty.push(null)
          cb(null, empty)
        })
      }
    }
    t.end()
  })
})

test('splat', function (t) {
  t.plan(4)
  var addNamed = require('../../lib/cache/add-named.js')
  addNamed('xyzzy-wibble', '*', testModule, function (err, pkg) {
    t.error(err, 'Succesfully resolved a splat package')
    t.is(pkg.name, moduleName)
    t.is(pkg.version, testModule['dist-tags'].latest)
    t.is(lastFetched, 'https://registry.npmjs.org/aproba/-/xyzzy-wibble-1.3.0-a.tgz')
  })
})
{'fraction_non_alphanumeric': 0.18084859726408534, 'fraction_numerical': 0.06631115233016462, 'mean_word_length': 2.2218073188946974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146207', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1761, 'n_words': 249}