Files
blb-throne-of-the-bone-king/__tests__/toolkitSocketClient.test.ts
T
jacob-mathison 1e9d3f0917
ci/woodpecker/push/woodpecker Pipeline was successful
Lint and Build Checks / Lint, Test, and Build (push) Failing after 345h51m17s
feat(styles): add browser scss builder system
2026-06-25 09:46:09 -05:00

62 lines
1.7 KiB
TypeScript

import { getToolkitSocketUrl } from '../src/socket/toolkitSocketClient';
const originalToolkitSocketUrl = process.env.TOOLKIT_SOCKET_URL;
const originalLocation = Object.getOwnPropertyDescriptor(
globalThis,
'location',
);
function setTestLocation(hostname: string, protocol = 'http:') {
Object.defineProperty(globalThis, 'location', {
configurable: true,
value: {
hostname,
protocol,
},
});
}
function restoreTestLocation() {
if (originalLocation == null) {
Reflect.deleteProperty(globalThis, 'location');
return;
}
Object.defineProperty(globalThis, 'location', originalLocation);
}
describe('toolkit socket client configuration', () => {
afterEach(() => {
if (originalToolkitSocketUrl == null) {
delete process.env.TOOLKIT_SOCKET_URL;
} else {
process.env.TOOLKIT_SOCKET_URL = originalToolkitSocketUrl;
}
restoreTestLocation();
});
it('uses explicit toolkit socket URL configuration first', () => {
process.env.TOOLKIT_SOCKET_URL = 'http://socket.example.test:5174';
setTestLocation('bone-kingdom.tabitha.tealthrone');
expect(getToolkitSocketUrl()).toBe('http://socket.example.test:5174');
});
it('uses local socket defaults for localhost development', () => {
delete process.env.TOOLKIT_SOCKET_URL;
setTestLocation('localhost');
expect(getToolkitSocketUrl()).toBe('http://127.0.0.1:5175');
});
it('derives the deployed socket URL from the current browser host', () => {
delete process.env.TOOLKIT_SOCKET_URL;
setTestLocation('bone-kingdom.tabitha.tealthrone');
expect(getToolkitSocketUrl()).toBe(
'http://bone-kingdom.tabitha.tealthrone:5174',
);
});
});