Files
orca/src/shared/node-dist-mirror.test.ts
T
Neil e0cf91c62a feat(ssh): one-click Node.js mirror when neither machine can download Node (#31069)
* feat(ssh): offer a Node.js mirror when neither machine can download Node

* fix(ssh): put the mirror action beside Details on the host row

* fix(ssh): offer the mirror only where this computer's setting applies, and word main's error by mirror state

* test(ssh): type the refusal case

* test(ssh): one checked settings fixture for the mirror dialog
2026-10-20 01:55:13 -07:00

52 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { normalizeNodeDistMirrorUrl, resolveNodeDistMirror } from './node-dist-mirror'
describe('Node dist mirror URL', () => {
it('keeps an http(s) base and drops trailing slashes', () => {
expect(normalizeNodeDistMirrorUrl(' https://npmmirror.com/mirrors/node/ ')).toEqual({
ok: true,
value: 'https://npmmirror.com/mirrors/node'
})
expect(normalizeNodeDistMirrorUrl('')).toEqual({ ok: true, value: '' })
for (const empty of [
'https://m.example/dist?',
'https://m.example/dist#',
'https://m.example/dist/?#'
]) {
expect(normalizeNodeDistMirrorUrl(empty)).toEqual({
ok: true,
value: 'https://m.example/dist'
})
}
})
it.each([
['ftp://mirror.example.com/node', 'http or https', 'protocol'],
['https://user:secret@mirror.example.com/node', 'user name or password', 'credentials'],
['https://mirror.example.com/node?token=1', 'query', 'query'],
['not a url', 'valid mirror URL', 'invalid'],
[`https://m.example/${'a'.repeat(2048)}`, 'too long', 'too-long']
])('refuses %s', (value, message, reason) => {
expect(normalizeNodeDistMirrorUrl(value)).toMatchObject({
ok: false,
message: expect.stringContaining(message),
reason
})
})
it('prefers the setting, then NODEJS_ORG_MIRROR, then NVM_NODEJS_ORG_MIRROR', () => {
const env = {
NODEJS_ORG_MIRROR: 'https://a.example/dist',
NVM_NODEJS_ORG_MIRROR: 'https://b.example/dist'
}
expect(resolveNodeDistMirror('https://setting.example/dist', env)).toBe(
'https://setting.example/dist'
)
expect(resolveNodeDistMirror('', env)).toBe('https://a.example/dist')
expect(resolveNodeDistMirror(undefined, { NVM_NODEJS_ORG_MIRROR: 'https://b.example/' })).toBe(
'https://b.example'
)
expect(resolveNodeDistMirror('nonsense', {})).toBeNull()
})
})