Files
bun.sh/test/js/bun/util/BunObject.test.ts

36 lines
1.0 KiB
TypeScript

import { env } from "bun";
import { hasNonReifiedStatic } from "bun:internal-for-testing";
import { expect, test } from "bun:test";
test("hasNonReifiedStatic", () => {
expect(hasNonReifiedStatic(Bun), "do not eagerly initialize the Bun object. This will make Bun much slower.").toBe(
true,
);
expect(env.a).toBeUndefined();
expect(hasNonReifiedStatic(Bun), "do not eagerly initialize the Bun object. This will make Bun much slower.").toBe(
true,
);
const a = { ...Bun };
globalThis.a = a;
expect(hasNonReifiedStatic(Bun)).toBe(false);
});
test("require('bun')", () => {
const str = eval("'bun'");
expect(require(str)).toBe(Bun);
});
test("await import('bun')", async () => {
const str = eval("'bun'");
const BunESM = await import(str);
// console.log it so that we iterate through all the fields and crash if it's
// in an unexpected state.
console.log(BunESM);
for (let property in Bun) {
expect(BunESM).toHaveProperty(property);
expect(BunESM[property]).toBe(Bun[property]);
}
expect(BunESM.default).toBe(Bun);
});