summaryrefslogtreecommitdiff
path: root/std/node/module_test.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-09-08 23:37:58 +0800
committerGitHub <noreply@github.com>2020-09-08 11:37:58 -0400
commit11afd071aec2d5ea6eb37a934c0835d8f6b1e764 (patch)
treea07d3266da81183cc2f2c8721459d3e84f663c7b /std/node/module_test.ts
parentac455050ee5de10984a9bd9f704e430ac244cb54 (diff)
test(std/node): make tests runnable from any directory (#7397)
This makes std/node tests runnable from any directory by resolving the testdata directory and files relative to the module directory resolved from import.meta.url.
Diffstat (limited to 'std/node/module_test.ts')
-rw-r--r--std/node/module_test.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/std/node/module_test.ts b/std/node/module_test.ts
index bdc2f39d3..12021782a 100644
--- a/std/node/module_test.ts
+++ b/std/node/module_test.ts
@@ -4,8 +4,13 @@ import {
assert,
assertStringContains,
} from "../testing/asserts.ts";
+
+import * as path from "../path/mod.ts";
import { createRequire } from "./module.ts";
+const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
+const testdataDir = path.resolve(moduleDir, path.join("_fs", "testdata"));
+
const require = createRequire(import.meta.url);
Deno.test("requireSuccess", function () {
@@ -32,8 +37,13 @@ Deno.test("requireBuiltin", function () {
const fs = require("fs");
assert("readFileSync" in fs);
const { readFileSync, isNull, extname } = require("./tests/cjs/cjs_builtin");
+
+ const testData = path.relative(
+ Deno.cwd(),
+ path.join(testdataDir, "hello.txt"),
+ );
assertEquals(
- readFileSync("./node/_fs/testdata/hello.txt", { encoding: "utf8" }),
+ readFileSync(testData, { encoding: "utf8" }),
"hello world",
);
assert(isNull(null));