1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-27 16:10:57 -05:00
denoland-deno/std/node/module_test.ts

60 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-04-20 14:30:52 -04:00
/* eslint-disable @typescript-eslint/no-var-requires */
const { test } = Deno;
import { assertEquals, assert, assertStrContains } from "../testing/asserts.ts";
import { createRequire } from "./module.ts";
2020-04-20 14:30:52 -04:00
const require = createRequire(import.meta.url);
test("requireSuccess", function () {
// Relative to import.meta.url
2020-04-20 14:30:52 -04:00
const result = require("./tests/cjs/cjs_a.js");
assert("helloA" in result);
assert("helloB" in result);
assert("C" in result);
assert("leftPad" in result);
assertEquals(result.helloA(), "A");
assertEquals(result.helloB(), "B");
assertEquals(result.C, "C");
assertEquals(result.leftPad("pad", 4), " pad");
});
test("requireCycle", function () {
2020-04-20 14:30:52 -04:00
const resultA = require("./tests/cjs/cjs_cycle_a");
const resultB = require("./tests/cjs/cjs_cycle_b");
assert(resultA);
assert(resultB);
});
test("requireBuiltin", function () {
2020-04-20 14:30:52 -04:00
const fs = require("fs");
assert("readFileSync" in fs);
2020-04-20 14:30:52 -04:00
const { readFileSync, isNull, extname } = require("./tests/cjs/cjs_builtin");
assertEquals(
readFileSync("./node/_fs/testdata/hello.txt", { encoding: "utf8" }),
"hello world"
);
assert(isNull(null));
assertEquals(extname("index.html"), ".html");
});
test("requireIndexJS", function () {
2020-04-20 14:30:52 -04:00
const { isIndex } = require("./tests/cjs");
assert(isIndex);
});
test("requireNodeOs", function () {
2020-04-20 14:30:52 -04:00
const os = require("os");
assert(os.arch);
assert(typeof os.arch() == "string");
});
test("requireStack", function () {
2020-04-20 14:30:52 -04:00
const { hello } = require("./tests/cjs/cjs_throw");
try {
hello();
} catch (e) {
assertStrContains(e.stack, "/tests/cjs/cjs_throw.js");
}
});