• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const common = require('../common-tap.js')
4const test = require('tap').test
5const fs = require('fs')
6const pkg = common.pkg
7
8fs.writeFileSync(pkg + '/package.json', JSON.stringify({
9  name: 'npm-test-publish-config',
10  version: '1.2.3',
11  publishConfig: {
12    registry: common.registry
13  }
14}), 'utf8')
15
16fs.writeFileSync(pkg + '/fixture_npmrc',
17  '//localhost:' + common.port + '/:email = fancy@feast.net\n' +
18  '//localhost:' + common.port + '/:username = fancy\n' +
19  '//localhost:' + common.port + '/:_password = ' + Buffer.from('feast').toString('base64'))
20
21test(function (t) {
22  let child
23  t.plan(5)
24  require('http').createServer(function (req, res) {
25    t.pass('got request on the fakey fake registry')
26    let body = ''
27    req.on('data', (d) => { body += d })
28    req.on('end', () => {
29      this.close()
30      res.statusCode = 500
31      res.end(JSON.stringify({
32        error: 'sshhh. naptime nao. \\^O^/ <(YAWWWWN!)'
33      }))
34      t.match(body, /"beta"/, 'got expected tag')
35      child.kill('SIGINT')
36    })
37  }).listen(common.port, () => {
38    t.pass('server is listening')
39
40    // don't much care about listening to the child's results
41    // just wanna make sure it hits the server we just set up.
42    //
43    // there are plenty of other tests to verify that publish
44    // itself functions normally.
45    //
46    // Make sure that we don't sit around waiting for lock files
47    child = common.npm([
48      'publish',
49      '--userconfig=' + pkg + '/fixture_npmrc',
50      '--tag=beta',
51      '--loglevel', 'error'
52    ], {
53      cwd: pkg,
54      env: {
55        'npm_config_cache_lock_stale': 1000,
56        'npm_config_cache_lock_wait': 1000,
57        HOME: process.env.HOME,
58        Path: process.env.PATH,
59        PATH: process.env.PATH,
60        USERPROFILE: process.env.USERPROFILE
61      }
62    }, function (err, code, stdout, stderr) {
63      t.comment(stdout)
64      t.comment(stderr)
65      t.ifError(err, 'publish command finished successfully')
66      t.notOk(code, 'npm install exited with code 0')
67    })
68  })
69})
70