tests: minor cleanups of tests/precompile_test.ts (#2870)

A tiny lesson that `URL` and `import.meta` can be used instead of
`@std/path`. Also, might fix CI thanks to `deno.lock` being updated.
This commit is contained in:
Asher Gomez
2025-04-29 08:10:17 +02:00
committed by GitHub
parent ca6493757e
commit cfa7fdc6b9
2 changed files with 1144 additions and 27 deletions
Generated
+1129 -1
View File
File diff suppressed because it is too large Load Diff
+15 -26
View File
@@ -1,37 +1,26 @@
import * as path from "@std/path";
import { expect } from "@std/expect"; import { expect } from "@std/expect";
Deno.test("JSX precompile - check config", async () => { Deno.test("JSX precompile - check config", async () => {
const cwd = path.join(import.meta.dirname!, "fixture_precompile", "invalid"); const { stderr, success } = await new Deno.Command(Deno.execPath(), {
const output = await new Deno.Command(Deno.execPath(), { args: ["run", "-A", "dev.ts"],
args: [ cwd: new URL("./fixture_precompile/invalid", import.meta.url),
"run",
"-A",
path.join(cwd, "dev.ts"),
],
cwd,
}).output(); }).output();
const stderr = new TextDecoder().decode(output.stderr); const stderrText = new TextDecoder().decode(stderr);
expect(stderr).toContain("jsxPrecompileSkipElements to contain"); expect(stderrText).toContain("jsxPrecompileSkipElements to contain");
expect(output.code).toEqual(1); expect(success).toEqual(false);
}); });
Deno.test("JSX precompile - run vnode hooks", async () => { Deno.test("JSX precompile - run vnode hooks", async () => {
const cwd = path.join(import.meta.dirname!, "fixture_precompile", "valid"); const { stdout, success } = await new Deno.Command(Deno.execPath(), {
const output = await new Deno.Command(Deno.execPath(), { args: ["run", "-A", "main.tsx"],
args: [ cwd: new URL("./fixture_precompile/valid", import.meta.url),
"run",
"-A",
path.join(cwd, "main.tsx"),
],
cwd,
}).output(); }).output();
const stdout = new TextDecoder().decode(output.stdout); const stdoutText = new TextDecoder().decode(stdout);
expect(stdout).toContain('<img src="/foo.jpg?__frsh_c='); expect(stdoutText).toContain('<img src="/foo.jpg?__frsh_c=');
expect(stdout).toContain('<source src="/bar.jpg?__frsh_c='); expect(stdoutText).toContain('<source src="/bar.jpg?__frsh_c=');
expect(stdout).toContain('<div f-client-nav="true">'); expect(stdoutText).toContain('<div f-client-nav="true">');
expect(stdout).toContain('<span f-client-nav="false">'); expect(stdoutText).toContain('<span f-client-nav="false">');
expect(output.code).toEqual(0); expect(success).toEqual(true);
}); });