• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2const path = require('path')
3const test = require('tap').test
4const Tacks = require('tacks')
5const File = Tacks.File
6const Dir = Tacks.Dir
7const common = require('../common-tap.js')
8
9const e404 = /test-npm-404@latest' is not in the npm registry/
10const invalidPackage = /Your package name is not valid, because[\s\S]+1\. name can only contain URL-friendly characters/
11
12const basedir = common.pkg
13const testdir = path.join(basedir, 'testdir')
14const cachedir = common.cache
15const globaldir = path.join(basedir, 'global')
16const tmpdir = path.join(basedir, 'tmp')
17
18const env = common.newEnv().extend({
19  npm_config_cache: cachedir,
20  npm_config_tmp: tmpdir,
21  npm_config_prefix: globaldir,
22  npm_config_registry: common.registry,
23  npm_config_loglevel: 'error'
24})
25
26const fixture = new Tacks(Dir({
27  cache: Dir(),
28  global: Dir(),
29  tmp: Dir(),
30  testdir: Dir({
31    'package.json': File({
32      name: 'test',
33      version: '1.0.0'
34    })
35  })
36}))
37
38function setup () {
39  cleanup()
40  fixture.create(basedir)
41}
42
43function cleanup () {
44  fixture.remove(basedir)
45}
46
47test('setup', function (t) {
48  setup()
49  return common.fakeRegistry.listen()
50})
51
52test('404 message for basic package', function (t) {
53  return common.npm(['install', 'test-npm-404'], {cwd: testdir, env}).then(([code, stdout, stderr]) => {
54    t.is(code, 1, 'error code')
55    t.match(stderr, e404, 'error output')
56    t.notMatch(stderr, invalidPackage, 'no invalidity error')
57  })
58})
59
60test('404 message for scoped package', function (t) {
61  return common.npm(['install', '@npm/test-npm-404'], {cwd: testdir, env}).then(([code, stdout, stderr]) => {
62    t.is(code, 1, 'error code')
63    t.match(stderr, e404, 'error output')
64    t.notMatch(stderr, invalidPackage, 'no invalidity error')
65  })
66})
67
68test('cleanup', function (t) {
69  common.fakeRegistry.close()
70  cleanup()
71  t.done()
72})
73