From 75897de196c0112727ce5af6d4cef6407eb5d275 Mon Sep 17 00:00:00 2001 From: zhizheng Date: Tue, 17 Jun 2025 19:06:21 +0800 Subject: [PATCH] chore: add tests for fresh/compat imports (#3036) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `fresh/compat - defineFn mixed return types` - Tests all supported return types (Response, VNode, null) with both sync and async handlers, including FreshContext parameter usage - `fresh/compat - multiple compat imports` - Tests importing multiple compat functions simultaneously close #3025 --patch-1 try to use deno/std Api to replace --patch-2 make it simple and clean --patch-3 Convert update_test.ts to .tsx for JSX support Use static imports instead of dynamic imports for better performance Switch from @std/assert to @std/expect for consistency Use ReturnType<> for automatic type inference instead of manual type definitions Sincerely grateful to @iuioiua for the guidance and patience. --------- Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com> Co-authored-by: Asher Gomez --- deno.json | 2 +- deno.lock | 2 +- src/compat_test.tsx | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/compat_test.tsx diff --git a/deno.json b/deno.json index 4294f604..3eec8bb1 100644 --- a/deno.json +++ b/deno.json @@ -55,7 +55,7 @@ "@preact/signals": "npm:@preact/signals@^2.0.4", "esbuild": "npm:esbuild@0.25.4", "esbuild-wasm": "npm:esbuild-wasm@0.25.4", - "@std/assert": "jsr:@std/assert@^1.0.16", + "@std/assert": "jsr:@std/assert@^1.0.13", "@std/crypto": "jsr:@std/crypto@1", "@std/datetime": "jsr:@std/datetime@^0.225.2", "@std/encoding": "jsr:@std/encoding@1", diff --git a/deno.lock b/deno.lock index e16da495..563a272c 100644 --- a/deno.lock +++ b/deno.lock @@ -1916,7 +1916,7 @@ "jsr:@fresh/plugin-tailwind@^0.0.1-alpha.7", "jsr:@luca/esbuild-deno-loader@0.11", "jsr:@marvinh-test/fresh-island@^0.0.1", - "jsr:@std/assert@^1.0.16", + "jsr:@std/assert@^1.0.13", "jsr:@std/async@^1.0.13", "jsr:@std/cli@^1.0.19", "jsr:@std/collections@^1.0.11", diff --git a/src/compat_test.tsx b/src/compat_test.tsx new file mode 100644 index 00000000..8480305c --- /dev/null +++ b/src/compat_test.tsx @@ -0,0 +1,16 @@ +import type { FreshContext } from "./context.ts"; +import { assertType, type IsExact } from "@std/testing/types"; +import { expect } from "@std/expect"; +import { type defineApp, type defineLayout, defineRoute } from "./compat.ts"; + +Deno.test("compat - defineFn works", () => { + const ctx = {} as FreshContext; + expect(defineRoute(() => new Response("test"))(ctx)).toBeInstanceOf(Response); + expect(defineRoute(() => test)(ctx)).toBeInstanceOf(Object); + expect(defineRoute(() => null)(ctx)).toEqual(null); +}); + +Deno.test("compat - functions equivalent", () => { + assertType>(true); + assertType>(true); +});