2026-07-27 10:58:33 +00:00
|
|
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
|
|
|
import { getVSCodeBootstrapConfig, isVSCodeBootstrapPresent } from './vscodeBootstrap';
|
|
|
|
|
|
2026-08-29 01:06:36 +03:00
|
|
|
interface TestWindow {
|
|
|
|
|
__VSCODE_CONFIG__?: { workspaceFolder: string; workspaceFolders: { name: string; path: string }[] };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* bun test runs without a DOM, so `globalThis` has no `window` binding to
|
|
|
|
|
* assign through. Defining the property directly installs the stub without
|
|
|
|
|
* asserting that it is a real `Window`.
|
|
|
|
|
*/
|
|
|
|
|
const setTestWindow = (value: TestWindow | undefined): void => {
|
|
|
|
|
if (value === undefined) {
|
|
|
|
|
Reflect.deleteProperty(globalThis, 'window');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Object.defineProperty(globalThis, 'window', { value, configurable: true, writable: true });
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-27 10:58:33 +00:00
|
|
|
describe('VS Code bootstrap config', () => {
|
|
|
|
|
afterEach(() => {
|
2026-08-29 01:06:36 +03:00
|
|
|
setTestWindow(undefined);
|
2026-07-27 10:58:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('reads extension-host __VSCODE_CONFIG__ before RuntimeAPIs exist', () => {
|
2026-08-29 01:06:36 +03:00
|
|
|
setTestWindow({
|
2026-07-27 10:58:33 +00:00
|
|
|
__VSCODE_CONFIG__: {
|
|
|
|
|
workspaceFolder: '/workspace/project-one',
|
|
|
|
|
workspaceFolders: [{ name: 'project-one', path: '/workspace/project-one' }],
|
|
|
|
|
},
|
2026-08-29 01:06:36 +03:00
|
|
|
});
|
2026-07-27 10:58:33 +00:00
|
|
|
|
|
|
|
|
expect(getVSCodeBootstrapConfig()).toEqual({
|
|
|
|
|
workspaceFolder: '/workspace/project-one',
|
|
|
|
|
workspaceFolders: [{ name: 'project-one', path: '/workspace/project-one' }],
|
|
|
|
|
});
|
|
|
|
|
expect(isVSCodeBootstrapPresent()).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('treats missing window/bootstrap as not VS Code', () => {
|
|
|
|
|
expect(getVSCodeBootstrapConfig()).toBeNull();
|
|
|
|
|
expect(isVSCodeBootstrapPresent()).toBe(false);
|
|
|
|
|
expect(isVSCodeBootstrapPresent(null)).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
});
|