Files
peardock/test/node-url-shim.test.js
T
Raven Scott 2e51c49526
Release rolling / release (push) Has been cancelled
Fix Bare dockerode failure: polyfill Node url.resolve
docker-modem calls url.resolve/parse/format, which bare-url does not
implement. Map bare url imports to build/shims/node-url.cjs so the
standalone peardock-server can talk to the Docker socket again.
2026-07-11 15:34:12 -04:00

41 lines
1.2 KiB
JavaScript

/**
* Ensure Bare Node url shim matches Node for docker-modem call patterns.
*/
import test from 'brittle'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const nodeUrl = require('url')
const shim = require('../build/shims/node-url.cjs')
test('url.resolve matches Node for docker-modem patterns', (t) => {
const cases = [
['http://localhost:2375/v1.41/', 'containers/json'],
['http://localhost:2375/v1.41', 'containers/json'],
['http://localhost/v1.41/', '/v1.41/containers/json'],
['/v1.41/', 'containers/json'],
]
for (const [a, b] of cases) {
t.is(shim.resolve(a, b), nodeUrl.resolve(a, b), `${a} + ${b}`)
}
})
test('url.parse provides host/path/protocol', (t) => {
const p = shim.parse('http://localhost:2375/v1.41/containers/json')
t.is(p.protocol, 'http:')
t.is(p.host, 'localhost:2375')
t.is(p.path, '/v1.41/containers/json')
})
test('url.format builds request URLs', (t) => {
t.is(
shim.format({
protocol: 'http:',
hostname: 'localhost',
port: '2375',
pathname: '/v1.41/x',
}),
'http://localhost:2375/v1.41/x'
)
t.ok(typeof shim.URL === 'function')
})