summaryrefslogtreecommitdiff
path: root/std/node/_fs
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/_fs
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/_fs')
-rw-r--r--std/node/_fs/_fs_readFile_test.ts5
-rw-r--r--std/node/_fs/_fs_writeFile_test.ts3
-rw-r--r--std/node/_fs/promises/_fs_readFile_test.ts5
3 files changed, 6 insertions, 7 deletions
diff --git a/std/node/_fs/_fs_readFile_test.ts b/std/node/_fs/_fs_readFile_test.ts
index ff449dbb2..9ada80057 100644
--- a/std/node/_fs/_fs_readFile_test.ts
+++ b/std/node/_fs/_fs_readFile_test.ts
@@ -2,9 +2,8 @@ import { readFile, readFileSync } from "./_fs_readFile.ts";
import * as path from "../../path/mod.ts";
import { assertEquals, assert } from "../../testing/asserts.ts";
-const testData = path.resolve(
- path.join("node", "_fs", "testdata", "hello.txt"),
-);
+const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
+const testData = path.resolve(moduleDir, "testdata", "hello.txt");
Deno.test("readFileSuccess", async function () {
const data = await new Promise((res, rej) => {
diff --git a/std/node/_fs/_fs_writeFile_test.ts b/std/node/_fs/_fs_writeFile_test.ts
index a11e0fb67..6d50d1013 100644
--- a/std/node/_fs/_fs_writeFile_test.ts
+++ b/std/node/_fs/_fs_writeFile_test.ts
@@ -9,7 +9,8 @@ import { writeFile, writeFileSync } from "./_fs_writeFile.ts";
import type { TextEncodings } from "./_fs_common.ts";
import * as path from "../../path/mod.ts";
-const testDataDir = path.resolve(path.join("node", "_fs", "testdata"));
+const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
+const testDataDir = path.resolve(moduleDir, "testdata");
const decoder = new TextDecoder("utf-8");
Deno.test("Callback must be a function error", function fn() {
diff --git a/std/node/_fs/promises/_fs_readFile_test.ts b/std/node/_fs/promises/_fs_readFile_test.ts
index a5f5a1327..5414a3a09 100644
--- a/std/node/_fs/promises/_fs_readFile_test.ts
+++ b/std/node/_fs/promises/_fs_readFile_test.ts
@@ -2,9 +2,8 @@ import { readFile } from "./_fs_readFile.ts";
import * as path from "../../../path/mod.ts";
import { assertEquals, assert } from "../../../testing/asserts.ts";
-const testData = path.resolve(
- path.join("node", "_fs", "testdata", "hello.txt"),
-);
+const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
+const testData = path.resolve(moduleDir, "..", "testdata", "hello.txt");
Deno.test("readFileSuccess", async function () {
const data: Uint8Array = await readFile(testData);