|
1 | 1 | /* eslint-disable max-len */ |
2 | 2 | 'use strict' |
| 3 | +const { test } = require('node:test') |
| 4 | +const assert = require('node:assert') |
3 | 5 | const HostedGit = require('..') |
4 | | -const t = require('tap') |
| 6 | + |
| 7 | +// Helper function to assert actual object contains all expected properties |
| 8 | +const assertHasStrict = (actual, expected, message) => { |
| 9 | + for (const [key, value] of Object.entries(expected)) { |
| 10 | + assert.strictEqual(actual[key], value, `${message} (${key})`) |
| 11 | + } |
| 12 | +} |
5 | 13 |
|
6 | 14 | const invalid = [ |
7 | 15 | // invalid protocol |
@@ -142,75 +150,70 @@ const valid = { |
142 | 150 | 'https://:[email protected]/foo/bar.git#branch': { ... defaults, default: 'https', auth: ':password', committish: 'branch' }, |
143 | 151 | } |
144 | 152 |
|
145 | | -t.test('valid urls parse properly', t => { |
146 | | - t.plan(Object.keys(valid).length) |
| 153 | +test('valid urls parse properly', () => { |
147 | 154 | for (const [url, result] of Object.entries(valid)) { |
148 | | - t.hasStrict(HostedGit.fromUrl(url), result, `${url} parses`) |
| 155 | + const parsed = HostedGit.fromUrl(url) |
| 156 | + assertHasStrict(parsed, result, `${url} parses`) |
149 | 157 | } |
150 | 158 | }) |
151 | 159 |
|
152 | | -t.test('invalid urls return undefined', t => { |
153 | | - t.plan(invalid.length) |
| 160 | +test('invalid urls return undefined', () => { |
154 | 161 | for (const url of invalid) { |
155 | | - t.equal(HostedGit.fromUrl(url), undefined, `${url} returns undefined`) |
| 162 | + assert.strictEqual(HostedGit.fromUrl(url), undefined, `${url} returns undefined`) |
156 | 163 | } |
157 | 164 | }) |
158 | 165 |
|
159 | | -t.test('toString respects defaults', t => { |
| 166 | +test('toString respects defaults', () => { |
160 | 167 | const sshurl = HostedGit.fromUrl('git+ssh://bitbucket.org/foo/bar') |
161 | | - t.equal(sshurl.default, 'sshurl', 'got the right default') |
162 | | - t.equal(sshurl.toString(), sshurl.sshurl(), 'toString calls sshurl') |
| 168 | + assert.strictEqual(sshurl.default, 'sshurl', 'got the right default') |
| 169 | + assert.strictEqual(sshurl.toString(), sshurl.sshurl(), 'toString calls sshurl') |
163 | 170 |
|
164 | 171 | const https = HostedGit.fromUrl('https://bitbucket.org/foo/bar') |
165 | | - t.equal(https.default, 'https', 'got the right default') |
166 | | - t.equal(https.toString(), https.https(), 'toString calls https') |
| 172 | + assert.strictEqual(https.default, 'https', 'got the right default') |
| 173 | + assert.strictEqual(https.toString(), https.https(), 'toString calls https') |
167 | 174 |
|
168 | 175 | const shortcut = HostedGit.fromUrl('bitbucket:foo/bar') |
169 | | - t.equal(shortcut.default, 'shortcut', 'got the right default') |
170 | | - t.equal(shortcut.toString(), shortcut.shortcut(), 'toString calls shortcut') |
171 | | - |
172 | | - t.end() |
| 176 | + assert.strictEqual(shortcut.default, 'shortcut', 'got the right default') |
| 177 | + assert.strictEqual(shortcut.toString(), shortcut.shortcut(), 'toString calls shortcut') |
173 | 178 | }) |
174 | 179 |
|
175 | | -t.test('string methods populate correctly', t => { |
| 180 | +test('string methods populate correctly', () => { |
176 | 181 | const parsed = HostedGit.fromUrl('git+ssh://bitbucket.org/foo/bar') |
177 | | - t.equal(parsed.getDefaultRepresentation(), parsed.default, 'getDefaultRepresentation()') |
178 | | - t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset') |
179 | | - t.equal(parsed.ssh(), '[email protected]:foo/bar.git') |
180 | | - t.equal(parsed.sshurl(), 'git+ssh://[email protected]/foo/bar.git') |
181 | | - t.equal(parsed.edit(), 'https://bitbucket.org/foo/bar') |
182 | | - t.equal(parsed.edit('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js?mode=edit') |
183 | | - t.equal(parsed.browse(), 'https://bitbucket.org/foo/bar') |
184 | | - t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js') |
185 | | - t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js#l100') |
186 | | - t.equal(parsed.docs(), 'https://bitbucket.org/foo/bar#readme') |
187 | | - t.equal(parsed.https(), 'git+https://bitbucket.org/foo/bar.git') |
188 | | - t.equal(parsed.shortcut(), 'bitbucket:foo/bar') |
189 | | - t.equal(parsed.path(), 'foo/bar') |
190 | | - t.equal(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/HEAD.tar.gz') |
191 | | - t.equal(parsed.file(), 'https://bitbucket.org/foo/bar/raw/HEAD/') |
192 | | - t.equal(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/HEAD/lib/index.js') |
193 | | - t.equal(parsed.bugs(), 'https://bitbucket.org/foo/bar/issues') |
194 | | - |
195 | | - t.equal(parsed.docs({ committish: 'fix/bug' }), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme', 'allows overriding options') |
196 | | - |
197 | | - t.same(parsed.git(), null, 'git() returns null') |
| 182 | + assert.strictEqual(parsed.getDefaultRepresentation(), parsed.default, 'getDefaultRepresentation()') |
| 183 | + assert.strictEqual(parsed.hash(), '', 'hash() returns empty string when committish is unset') |
| 184 | + assert.strictEqual(parsed.ssh(), '[email protected]:foo/bar.git') |
| 185 | + assert.strictEqual(parsed.sshurl(), 'git+ssh://[email protected]/foo/bar.git') |
| 186 | + assert.strictEqual(parsed.edit(), 'https://bitbucket.org/foo/bar') |
| 187 | + assert.strictEqual(parsed.edit('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js?mode=edit') |
| 188 | + assert.strictEqual(parsed.browse(), 'https://bitbucket.org/foo/bar') |
| 189 | + assert.strictEqual(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js') |
| 190 | + assert.strictEqual(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/HEAD/lib/index.js#l100') |
| 191 | + assert.strictEqual(parsed.docs(), 'https://bitbucket.org/foo/bar#readme') |
| 192 | + assert.strictEqual(parsed.https(), 'git+https://bitbucket.org/foo/bar.git') |
| 193 | + assert.strictEqual(parsed.shortcut(), 'bitbucket:foo/bar') |
| 194 | + assert.strictEqual(parsed.path(), 'foo/bar') |
| 195 | + assert.strictEqual(parsed.tarball(), 'https://bitbucket.org/foo/bar/get/HEAD.tar.gz') |
| 196 | + assert.strictEqual(parsed.file(), 'https://bitbucket.org/foo/bar/raw/HEAD/') |
| 197 | + assert.strictEqual(parsed.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/HEAD/lib/index.js') |
| 198 | + assert.strictEqual(parsed.bugs(), 'https://bitbucket.org/foo/bar/issues') |
| 199 | + |
| 200 | + assert.strictEqual(parsed.docs({ committish: 'fix/bug' }), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme', 'allows overriding options') |
| 201 | + |
| 202 | + assert.deepStrictEqual(parsed.git(), null, 'git() returns null') |
198 | 203 |
|
199 | 204 | const extra = HostedGit.fromUrl('https://[email protected]/foo/bar#fix/bug') |
200 | | - t.equal(extra.hash(), '#fix/bug') |
201 | | - t.equal(extra.https(), 'git+https://[email protected]/foo/bar.git#fix/bug') |
202 | | - t.equal(extra.shortcut(), 'bitbucket:foo/bar#fix/bug') |
203 | | - t.equal(extra.ssh(), '[email protected]:foo/bar.git#fix/bug') |
204 | | - t.equal(extra.sshurl(), 'git+ssh://[email protected]/foo/bar.git#fix/bug') |
205 | | - t.equal(extra.browse(), 'https://bitbucket.org/foo/bar/src/fix%2Fbug') |
206 | | - t.equal(extra.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/fix%2Fbug/lib/index.js') |
207 | | - t.equal(extra.browse('/lib/index.js', 'L200'), 'https://bitbucket.org/foo/bar/src/fix%2Fbug/lib/index.js#l200') |
208 | | - t.equal(extra.docs(), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme') |
209 | | - t.equal(extra.file(), 'https://bitbucket.org/foo/bar/raw/fix%2Fbug/') |
210 | | - t.equal(extra.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/fix%2Fbug/lib/index.js') |
211 | | - |
212 | | - t.equal(extra.sshurl({ noCommittish: true }), 'git+ssh://[email protected]/foo/bar.git', 'noCommittish drops committish from urls') |
213 | | - t.equal(extra.sshurl({ noGitPlus: true }), 'ssh://[email protected]/foo/bar.git#fix/bug', 'noGitPlus drops git+ prefix from urls') |
214 | | - |
215 | | - t.end() |
| 205 | + assert.strictEqual(extra.hash(), '#fix/bug') |
| 206 | + assert.strictEqual(extra.https(), 'git+https://[email protected]/foo/bar.git#fix/bug') |
| 207 | + assert.strictEqual(extra.shortcut(), 'bitbucket:foo/bar#fix/bug') |
| 208 | + assert.strictEqual(extra.ssh(), '[email protected]:foo/bar.git#fix/bug') |
| 209 | + assert.strictEqual(extra.sshurl(), 'git+ssh://[email protected]/foo/bar.git#fix/bug') |
| 210 | + assert.strictEqual(extra.browse(), 'https://bitbucket.org/foo/bar/src/fix%2Fbug') |
| 211 | + assert.strictEqual(extra.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/fix%2Fbug/lib/index.js') |
| 212 | + assert.strictEqual(extra.browse('/lib/index.js', 'L200'), 'https://bitbucket.org/foo/bar/src/fix%2Fbug/lib/index.js#l200') |
| 213 | + assert.strictEqual(extra.docs(), 'https://bitbucket.org/foo/bar/src/fix%2Fbug#readme') |
| 214 | + assert.strictEqual(extra.file(), 'https://bitbucket.org/foo/bar/raw/fix%2Fbug/') |
| 215 | + assert.strictEqual(extra.file('/lib/index.js'), 'https://bitbucket.org/foo/bar/raw/fix%2Fbug/lib/index.js') |
| 216 | + |
| 217 | + assert.strictEqual(extra.sshurl({ noCommittish: true }), 'git+ssh://[email protected]/foo/bar.git', 'noCommittish drops committish from urls') |
| 218 | + assert.strictEqual(extra.sshurl({ noGitPlus: true }), 'ssh://[email protected]/foo/bar.git#fix/bug', 'noGitPlus drops git+ prefix from urls') |
216 | 219 | }) |
0 commit comments