Welcome to mirror list, hosted at ThFree Co, Russian Federation.

consistent-resolve.js « test « arborist « workspaces - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6145758fa1fff0bc4c2ea6198fa103c66a94d26a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const t = require('tap')
const { normalizePath } = require('./fixtures/utils.js')
const consistentResolve = require('../lib/consistent-resolve.js')
const cr = (...args) => {
  const r = consistentResolve(...args)
  return r && normalizePath(r)
}

t.test('file and directories resolved to toPath', t => {
  const tp = '/foo'
  const fp = '/foo/bar'
  t.equal(cr('/foo/bar/baz', fp, tp, true), 'file:bar/baz')
  t.equal(cr('/foo/bar/baz', fp, tp), 'file:/foo/bar/baz')

  t.equal(cr('./baz', fp, tp, true), 'file:bar/baz')
  t.equal(cr('./baz', fp, tp), 'file:/foo/bar/baz')

  t.equal(cr('/foo/bar/baz.tgz', fp, tp, true), 'file:bar/baz.tgz')
  t.equal(cr('/foo/bar/baz.tgz', fp, tp), 'file:/foo/bar/baz.tgz')

  t.equal(cr('baz.tgz', fp, tp, true), 'file:bar/baz.tgz')
  t.equal(cr('baz.tgz', fp, tp), 'file:/foo/bar/baz.tgz')

  t.equal(cr('file:/foo/bar/baz', fp, tp, true), 'file:bar/baz')
  t.equal(cr('file:/foo/bar/baz', fp, tp), 'file:/foo/bar/baz')

  t.equal(cr('file:baz', fp, tp, true), 'file:bar/baz')
  t.equal(cr('file:baz', fp, tp), 'file:/foo/bar/baz')

  t.equal(cr('file:/foo/bar/baz.tgz', fp, tp, true), 'file:bar/baz.tgz')
  t.equal(cr('file:/foo/bar/baz.tgz', fp, tp), 'file:/foo/bar/baz.tgz')

  t.equal(cr('file:baz.tgz', fp, tp, true), 'file:bar/baz.tgz')
  t.equal(cr('file:baz.tgz', fp, tp), 'file:/foo/bar/baz.tgz')
  t.end()
})

t.test('file and directories made consistent if toPath not set', t => {
  const fp = '/foo/bar'
  for (const rel of [true, false]) {
    // relative doesn't matter if toPath not set
    t.test(`rel=${rel}`, t => {
      t.equal(cr('/foo/bar/baz', fp, null, rel), 'file:/foo/bar/baz')
      t.equal(cr('./baz', fp, null, rel), 'file:/foo/bar/baz')
      t.equal(cr('/foo/bar/baz.tgz', fp, null, rel), 'file:/foo/bar/baz.tgz')
      t.equal(cr('baz.tgz', fp, null, rel), 'file:/foo/bar/baz.tgz')
      t.equal(cr('file:/foo/bar/baz', fp, null, rel), 'file:/foo/bar/baz')
      t.equal(cr('file:baz', fp, null, rel), 'file:/foo/bar/baz')
      t.equal(cr('file:/foo/bar/baz.tgz', fp, null, rel), 'file:/foo/bar/baz.tgz')
      t.equal(cr('file:baz.tgz', fp, null, rel), 'file:/foo/bar/baz.tgz')
      t.end()
    })
  }
  t.end()
})

t.test('consistent hosted git info urls', t => {
  const expect = 'git+ssh://git@github.com/a/b.git'
  const expectAuth = 'git+https://user:pass@github.com/a/b.git'
  t.equal(cr('a/b'), expect)
  t.equal(cr('github:a/b'), expect)
  t.equal(cr('git+https://github.com/a/b'), expect)
  t.equal(cr('git://github.com/a/b'), expect)
  t.equal(cr('git+ssh://git@github.com/a/b'), expect)
  t.equal(cr('git+https://github.com/a/b.git'), expect)
  t.equal(cr('git://github.com/a/b.git'), expect)
  t.equal(cr('git+ssh://git@github.com/a/b.git'), expect)
  t.equal(cr('git+https://user:pass@github.com/a/b.git'), expectAuth)

  const hash = '#0000000000000000000000000000000000000000'
  t.equal(cr('a/b' + hash), expect + hash)
  t.equal(cr('github:a/b' + hash), expect + hash)
  t.equal(cr('git+https://github.com/a/b' + hash), expect + hash)
  t.equal(cr('git://github.com/a/b' + hash), expect + hash)
  t.equal(cr('git+ssh://git@github.com/a/b' + hash), expect + hash)
  t.equal(cr('git+https://github.com/a/b.git' + hash), expect + hash)
  t.equal(cr('git://github.com/a/b.git' + hash), expect + hash)
  t.equal(cr('git+ssh://git@github.com/a/b.git' + hash), expect + hash)
  t.equal(cr('xyz@a/b' + hash), expect + hash)
  t.equal(cr('xyz@github:a/b' + hash), expect + hash)
  t.equal(cr('xyz@git+https://github.com/a/b' + hash), expect + hash)
  t.equal(cr('xyz@git://github.com/a/b' + hash), expect + hash)
  t.equal(cr('xyz@git+ssh://git@github.com/a/b' + hash), expect + hash)
  t.equal(cr('xyz@git+https://github.com/a/b.git' + hash), expect + hash)
  t.equal(cr('xyz@git://github.com/a/b.git' + hash), expect + hash)
  t.equal(cr('xyz@git+ssh://git@github.com/a/b.git' + hash), expect + hash)
  t.end()
})

t.test('unhosted git returns saveSpec', t => {
  const r = 'git+https://x.com/y.git#0000000000000000000000000000000000000000'
  t.equal(cr(r), r)
  t.equal(cr('xyz@' + r), r)
  t.end()
})

t.test('remotes returned as-is', t => {
  const r = 'http://x.com/y.tgz'
  t.equal(cr(r), r)
  t.equal(cr('xyz@' + r), r)
  t.end()
})

t.test('just a tag name interpreted as a tag name, not a name@', t => {
  t.equal(cr('foo'), 'foo')
  t.equal(cr('foo@'), '')
  t.end()
})

t.test('falsey resolved returns null', t => {
  t.equal(cr(null), null)
  t.equal(cr(0), null)
  t.equal(cr(false), null)
  t.equal(cr(undefined), null)
  t.end()
})

t.test('invalid resolved returns as-is', t => {
  t.equal(cr('not ! a : v@lid t*A*g'), 'not ! a : v@lid t*A*g')
  t.end()
})