• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Run all the tests in the `npm-registry-couchapp` suite
2// This verifies that the server-side stuff still works.
3
4var common = require('../common-tap')
5var t = require('tap')
6
7var npmExec = require.resolve('../../bin/npm-cli.js')
8var path = require('path')
9var ca = path.resolve(__dirname, '../../node_modules/npm-registry-couchapp')
10
11var which = require('which')
12
13var v = process.versions.node.split('.').map(function (n) { return parseInt(n, 10) })
14if (v[0] === 0 && v[1] < 10) {
15  console.error(
16    'WARNING: need a recent Node for npm-registry-couchapp tests to run, have',
17    process.versions.node
18  )
19} else {
20  try {
21    which.sync('couchdb')
22    t.test(runTests)
23  } catch (er) {
24    console.error('WARNING: need couch to run test: ' + er.message)
25  }
26}
27
28function runTests (t) {
29  var env = Object.assign({ TAP: 1 }, process.env)
30  env.npm = npmExec
31  // TODO: fix tap and / or nyc to handle nested invocations properly
32  env.COVERALLS_REPO_TOKEN = ''
33
34  var opts = {
35    cwd: ca,
36    stdio: 'inherit'
37  }
38  common.npm(['install'], opts, function (err, code) {
39    if (err) { throw err }
40    if (code) {
41      t.fail('install failed with: ' + code)
42      return t.end()
43    } else {
44      opts = {
45        cwd: ca,
46        env: env,
47        stdio: 'inherit'
48      }
49      common.npm(['test', '--', '-Rtap', '--no-coverage'], opts, function (err, code) {
50        if (err) { throw err }
51        if (code) {
52          t.fail('test failed with: ' + code)
53          return t.end()
54        }
55        opts = {
56          cwd: ca,
57          env: env,
58          stdio: 'inherit'
59        }
60        common.npm(['prune', '--production'], opts, function (err, code) {
61          t.ifError(err)
62          t.equal(code, 0)
63          return t.end()
64        })
65      })
66    }
67  })
68}
69