Files
bun.sh/test/bun.js/process.test.js
Colin McDonnell f7f1b60444 Add bun-types, add typechecking, add child_process types (#1475)
* Add bun-types to packages

* Improve typing

* Fix types in tests

* Fix dts tests

* Run formatter

* Fix all type errors

* Add strict mode, fix type errors

* Add ffi changes

* Move workflows to root

* Add workflows

* Remove labeler

* Add child_process types

* Fix synthetic defaults issue

* Remove docs

* Move scripts

* Run prettier

* Include examples in typechecking

* captureStackTrace types

* moved captureStackTrace types to globals

* Address reviews

Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2022-11-09 15:40:40 -08:00

78 lines
2.3 KiB
JavaScript

import { describe, expect, it } from "bun:test";
it("process", () => {
// this property isn't implemented yet but it should at least return a string
const isNode = !process.isBun;
if (!isNode && process.title !== "bun")
throw new Error("process.title is not 'bun'");
if (typeof process.env.USER !== "string")
throw new Error("process.env is not an object");
if (process.env.USER.length === 0)
throw new Error("process.env is missing a USER property");
if (process.platform !== "darwin" && process.platform !== "linux")
throw new Error("process.platform is invalid");
if (isNode) throw new Error("process.isBun is invalid");
// partially to test it doesn't crash due to various strange types
process.env.BACON = "yummy";
if (process.env.BACON !== "yummy") {
throw new Error("process.env is not writable");
}
delete process.env.BACON;
if (typeof process.env.BACON !== "undefined") {
throw new Error("process.env is not deletable");
}
process.env.BACON = "yummy";
if (process.env.BACON !== "yummy") {
throw new Error("process.env is not re-writable");
}
if (JSON.parse(JSON.stringify(process.env)).BACON !== "yummy") {
throw new Error("process.env is not serializable");
}
if (typeof JSON.parse(JSON.stringify(process.env)).toJSON !== "undefined") {
throw new Error(
"process.env should call toJSON to hide its internal state",
);
}
var { env, ...proces } = process;
console.log(JSON.stringify(proces, null, 2));
console.log(proces);
console.log("CWD", process.cwd());
console.log("SET CWD", process.chdir("../"));
console.log("CWD", process.cwd());
});
it("process.hrtime()", () => {
const start = process.hrtime();
const end = process.hrtime(start);
const end2 = process.hrtime();
expect(end[0]).toBe(0);
expect(end2[1] > start[1]).toBe(true);
});
it("process.hrtime.bigint()", () => {
const start = process.hrtime.bigint();
const end = process.hrtime.bigint();
expect(end > start).toBe(true);
});
it("process.release", () => {
expect(process.release.name).toBe("bun");
expect(process.release.sourceUrl).toBe(
`https://github.com/oven-sh/bun/release/bun-v${process.versions.bun}/bun-${
process.platform
}-${{ arm64: "aarch64", x64: "x64" }[process.arch] || process.arch}.zip`,
);
});