• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const t = require('tap')
2const replaceInfo = require('../../../lib/utils/replace-info.js')
3
4t.equal(
5  replaceInfo(),
6  undefined,
7  'should return undefined item'
8)
9
10t.equal(
11  replaceInfo(null),
12  null,
13  'should return null'
14)
15
16t.equal(
17  replaceInfo(1234),
18  1234,
19  'should return numbers'
20)
21
22t.equal(
23  replaceInfo('  ==  = = '),
24  '  ==  = = ',
25  'should return same string with only separators'
26)
27
28t.equal(
29  replaceInfo(''),
30  '',
31  'should return empty string'
32)
33
34t.equal(
35  replaceInfo('https://user:pass@registry.npmjs.org/'),
36  'https://user:***@registry.npmjs.org/',
37  'should replace single item'
38)
39
40t.equal(
41  replaceInfo(`https://registry.npmjs.org/path/npm_${'a'.repeat('36')}`),
42  'https://registry.npmjs.org/path/npm_***',
43  'should replace single item token'
44)
45
46t.equal(
47  replaceInfo('https://example.npmjs.org'),
48  'https://example.npmjs.org',
49  'should not replace single item with no password'
50)
51
52t.equal(
53  replaceInfo('foo bar https://example.npmjs.org lorem ipsum'),
54  'foo bar https://example.npmjs.org lorem ipsum',
55  'should not replace single item with no password with multiple items'
56)
57
58t.equal(
59  replaceInfo('https://user:pass@registry.npmjs.org/ http://a:b@reg.github.com'),
60  'https://user:***@registry.npmjs.org/ http://a:***@reg.github.com/',
61  'should replace multiple items on a string'
62)
63
64t.equal(
65  replaceInfo('Something https://user:pass@registry.npmjs.org/ foo bar'),
66  'Something https://user:***@registry.npmjs.org/ foo bar',
67  'should replace single item within a phrase'
68)
69
70t.equal(
71  replaceInfo('Something --x=https://user:pass@registry.npmjs.org/ foo bar'),
72  'Something --x=https://user:***@registry.npmjs.org/ foo bar',
73  'should replace single item within a phrase separated by ='
74)
75
76t.same(
77  replaceInfo([
78    'Something https://user:pass@registry.npmjs.org/ foo bar',
79    'http://foo:bar@registry.npmjs.org',
80    'http://example.npmjs.org',
81  ]),
82  [
83    'Something https://user:***@registry.npmjs.org/ foo bar',
84    'http://foo:***@registry.npmjs.org/',
85    'http://example.npmjs.org',
86  ],
87  'should replace items in an array'
88)
89
90t.same(
91  replaceInfo([
92    'Something --x=https://user:pass@registry.npmjs.org/ foo bar',
93    '--url=http://foo:bar@registry.npmjs.org',
94    '--url=http://example.npmjs.org',
95  ]),
96  [
97    'Something --x=https://user:***@registry.npmjs.org/ foo bar',
98    '--url=http://foo:***@registry.npmjs.org/',
99    '--url=http://example.npmjs.org',
100  ],
101  'should replace items in an array with equals'
102)
103
104t.same(
105  replaceInfo([
106    'Something https://user:pass@registry.npmjs.org/ foo bar',
107    null,
108    [],
109  ]),
110  [
111    'Something https://user:***@registry.npmjs.org/ foo bar',
112    null,
113    [],
114  ],
115  'should ignore invalid items of array'
116)
117