From b532b9e3f16320cfd4c5cd255fb87092ef3ebf84 Mon Sep 17 00:00:00 2001 From: Peter Weston <59482636+p-weston@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:08:24 +0000 Subject: [PATCH] Fix tests for windows paths (#1153) --- cmd/test/plug_run.test.ts | 5 +++-- cmd/test/runtime.test.ts | 5 +++-- common/space_lua/language.test.ts | 4 +++- lib/plugos/syscalls/fs.deno.test.ts | 3 ++- plugs/markdown/markdown_render.test.ts | 3 ++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/test/plug_run.test.ts b/cmd/test/plug_run.test.ts index 0dc1bca0..49f12335 100644 --- a/cmd/test/plug_run.test.ts +++ b/cmd/test/plug_run.test.ts @@ -6,6 +6,7 @@ import { assertEquals } from "@std/assert"; import { dirname, join } from "@std/path"; import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; import { runPlug } from "../plug_run.ts"; +import { fileURLToPath } from "node:url"; Deno.test("Test plug run", { sanitizeResources: false, @@ -13,7 +14,7 @@ Deno.test("Test plug run", { }, async () => { const assetBundle = new AssetBundle(assets); - const testFolder = dirname(new URL(import.meta.url).pathname); + const testFolder = dirname(fileURLToPath(new URL(import.meta.url))); const testSpaceFolder = join(testFolder, "test_space"); const plugFolder = join(testSpaceFolder, "_plug"); @@ -27,7 +28,7 @@ Deno.test("Test plug run", { join(testFolder, "test_plug_run.plug.yaml"), plugFolder, { - configPath: new URL("../../deno.json", import.meta.url).pathname, + configPath: fileURLToPath(new URL("../../deno.json", import.meta.url)), }, ); assertEquals( diff --git a/cmd/test/runtime.test.ts b/cmd/test/runtime.test.ts index 7031ef50..aee9f02d 100644 --- a/cmd/test/runtime.test.ts +++ b/cmd/test/runtime.test.ts @@ -4,6 +4,7 @@ import { assertEquals } from "@std/assert"; import { compileManifest } from "../compile.ts"; import * as esbuild from "esbuild"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; +import { fileURLToPath } from "node:url"; Deno.test("Run a deno sandbox", { sanitizeResources: false, @@ -32,10 +33,10 @@ Deno.test("Run a deno sandbox", { const tempDir = await Deno.makeTempDir(); const workerPath = await compileManifest( - new URL("test_runtime.plug.yaml", import.meta.url).pathname, + fileURLToPath(new URL("test_runtime.plug.yaml", import.meta.url)), tempDir, { - configPath: new URL("../../deno.json", import.meta.url).pathname, + configPath: fileURLToPath(new URL("../../deno.json", import.meta.url)), }, ); diff --git a/common/space_lua/language.test.ts b/common/space_lua/language.test.ts index f430c5c2..56361583 100644 --- a/common/space_lua/language.test.ts +++ b/common/space_lua/language.test.ts @@ -3,10 +3,12 @@ import { luaBuildStandardEnv } from "$common/space_lua/stdlib.ts"; import { LuaEnv, LuaStackFrame } from "$common/space_lua/runtime.ts"; import { evalStatement } from "$common/space_lua/eval.ts"; import { assert } from "@std/assert/assert"; +import { fileURLToPath } from "node:url"; + Deno.test("Lua language tests", async () => { // Read the Lua file const luaFile = await Deno.readTextFile( - new URL("./language_test.lua", import.meta.url).pathname, + fileURLToPath(new URL("./language_test.lua", import.meta.url)), ); const chunk = parse(luaFile, {}); const env = new LuaEnv(luaBuildStandardEnv()); diff --git a/lib/plugos/syscalls/fs.deno.test.ts b/lib/plugos/syscalls/fs.deno.test.ts index e54764ba..87f906de 100644 --- a/lib/plugos/syscalls/fs.deno.test.ts +++ b/lib/plugos/syscalls/fs.deno.test.ts @@ -2,10 +2,11 @@ import type { FileMeta } from "../../../plug-api/types.ts"; import { assert } from "@std/assert"; import fileSystemSyscalls from "./fs.deno.ts"; import { dirname, resolve } from "@std/path"; +import { fileURLToPath } from "node:url"; Deno.test("Test FS operations", async () => { const thisFolder = resolve( - dirname(new URL(import.meta.url).pathname), + dirname(fileURLToPath(new URL(import.meta.url))), ); const syscalls = fileSystemSyscalls(thisFolder); const allFiles: FileMeta[] = await syscalls["fs.listFiles"]( diff --git a/plugs/markdown/markdown_render.test.ts b/plugs/markdown/markdown_render.test.ts index 0d4fe9a7..a56b6554 100644 --- a/plugs/markdown/markdown_render.test.ts +++ b/plugs/markdown/markdown_render.test.ts @@ -5,6 +5,7 @@ import { createSandbox } from "../../lib/plugos/sandboxes/deno_worker_sandbox.ts import { renderMarkdownToHtml } from "./markdown_render.ts"; import { extendedMarkdownLanguage } from "$common/markdown_parser/parser.ts"; import { assertEquals } from "@std/assert"; +import { fileURLToPath } from "node:url"; Deno.test("Markdown render", async () => { const system = new System("server"); @@ -21,7 +22,7 @@ Deno.test("Markdown render", async () => { ), ); const testFile = Deno.readTextFileSync( - new URL("test/example.md", import.meta.url).pathname, + fileURLToPath(new URL("test/example.md", import.meta.url)), ); const tree = parse(extendedMarkdownLanguage, testFile); renderMarkdownToHtml(tree, {