2020-09-13 08:15:38 -04:00
|
|
|
// deno-lint-ignore-file no-undef
|
|
|
|
|
2019-11-18 18:30:24 -05:00
|
|
|
import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
|
2020-09-08 11:37:58 -04:00
|
|
|
import * as path from "../path/mod.ts";
|
2020-06-23 16:00:47 -04:00
|
|
|
import * as all from "./process.ts";
|
|
|
|
import { env, argv } from "./process.ts";
|
2019-11-18 18:30:24 -05:00
|
|
|
|
|
|
|
// NOTE: Deno.execPath() (and thus process.argv) currently requires --allow-env
|
2020-04-29 14:48:19 -04:00
|
|
|
// (Also Deno.env.toObject() (and process.env) requires --allow-env but it's more obvious)
|
2019-11-18 18:30:24 -05:00
|
|
|
|
2020-06-23 16:00:47 -04:00
|
|
|
Deno.test({
|
|
|
|
name: "process exports are as they should be",
|
|
|
|
fn() {
|
|
|
|
// * should be the same as process, default, and globalThis.process
|
|
|
|
// without the export aliases, and with properties that are not standalone
|
|
|
|
const allKeys = new Set<string>(Object.keys(all));
|
|
|
|
// without { process } for deno b/c
|
|
|
|
allKeys.delete("process");
|
|
|
|
// without esm default
|
|
|
|
allKeys.delete("default");
|
|
|
|
// with on, which is not exported via *
|
|
|
|
allKeys.add("on");
|
|
|
|
const allStr = Array.from(allKeys).sort().join(" ");
|
|
|
|
assertEquals(Object.keys(all.default).sort().join(" "), allStr);
|
|
|
|
assertEquals(Object.keys(all.process).sort().join(" "), allStr);
|
|
|
|
assertEquals(Object.keys(process).sort().join(" "), allStr);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.cwd and process.chdir success",
|
|
|
|
fn() {
|
2020-09-08 11:37:58 -04:00
|
|
|
assertEquals(process.cwd(), Deno.cwd());
|
|
|
|
|
|
|
|
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
|
|
|
|
process.chdir(path.resolve(moduleDir, ".."));
|
|
|
|
|
2019-11-18 18:30:24 -05:00
|
|
|
assert(process.cwd().match(/\Wstd$/));
|
|
|
|
process.chdir("node");
|
|
|
|
assert(process.cwd().match(/\Wnode$/));
|
|
|
|
process.chdir("..");
|
|
|
|
assert(process.cwd().match(/\Wstd$/));
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.chdir failure",
|
|
|
|
fn() {
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
process.chdir("non-existent-directory-name");
|
|
|
|
},
|
2020-02-24 15:48:35 -05:00
|
|
|
Deno.errors.NotFound,
|
2020-07-14 15:24:17 -04:00
|
|
|
"file",
|
2019-11-18 18:30:24 -05:00
|
|
|
// On every OS Deno returns: "No such file" except for Windows, where it's:
|
|
|
|
// "The system cannot find the file specified. (os error 2)" so "file" is
|
|
|
|
// the only common string here.
|
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.version",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof process, "object");
|
|
|
|
assertEquals(typeof process.version, "string");
|
|
|
|
assertEquals(typeof process.versions, "object");
|
|
|
|
assertEquals(typeof process.versions.node, "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.platform",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof process.platform, "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.arch",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof process.arch, "string");
|
|
|
|
// TODO(rsp): make sure that the arch strings should be the same in Node and Deno:
|
|
|
|
assertEquals(process.arch, Deno.build.arch);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.pid",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof process.pid, "number");
|
|
|
|
assertEquals(process.pid, Deno.pid);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.on",
|
|
|
|
fn() {
|
|
|
|
assertEquals(typeof process.on, "function");
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
process.on("uncaughtException", (_err: Error) => {});
|
|
|
|
},
|
|
|
|
Error,
|
2020-07-14 15:24:17 -04:00
|
|
|
"implemented",
|
2019-11-18 18:30:24 -05:00
|
|
|
);
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.argv",
|
2020-06-25 07:18:01 -04:00
|
|
|
fn() {
|
2019-11-18 18:30:24 -05:00
|
|
|
assert(Array.isArray(process.argv));
|
2020-06-25 07:18:01 -04:00
|
|
|
assert(Array.isArray(argv));
|
2019-11-18 18:30:24 -05:00
|
|
|
assert(
|
|
|
|
process.argv[0].match(/[^/\\]*deno[^/\\]*$/),
|
2020-07-14 15:24:17 -04:00
|
|
|
"deno included in the file name of argv[0]",
|
2019-11-18 18:30:24 -05:00
|
|
|
);
|
|
|
|
// we cannot test for anything else (we see test runner arguments here)
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|
|
|
|
|
2020-06-12 15:23:38 -04:00
|
|
|
Deno.test({
|
2019-11-18 18:30:24 -05:00
|
|
|
name: "process.env",
|
2020-06-25 07:18:01 -04:00
|
|
|
fn() {
|
2019-11-18 18:30:24 -05:00
|
|
|
assertEquals(typeof process.env.PATH, "string");
|
2020-06-25 07:18:01 -04:00
|
|
|
assertEquals(typeof env.PATH, "string");
|
2020-03-28 13:03:49 -04:00
|
|
|
},
|
2019-11-18 18:30:24 -05:00
|
|
|
});
|