octo3.
octo3.
DDeno
Created by octo3. on 8/3/2024 in #help
not found ctx.data
The data set in the handler is not reflected, is there any reason for this?
import { FreshContext, Handlers } from "$fresh/server.ts";

export const handler: Handlers = {
GET: async (_req: Request, ctx: FreshContext) => {
return await ctx.render({
message: "Welcome to Fresh"
});
},
};

export default function Home(_req: Request, ctx:FreshContext) {
console.log(ctx.data) // undefined !!!
return (
<div >
{ctx.data.message}
</div>
);
}
import { FreshContext, Handlers } from "$fresh/server.ts";

export const handler: Handlers = {
GET: async (_req: Request, ctx: FreshContext) => {
return await ctx.render({
message: "Welcome to Fresh"
});
},
};

export default function Home(_req: Request, ctx:FreshContext) {
console.log(ctx.data) // undefined !!!
return (
<div >
{ctx.data.message}
</div>
);
}
3 replies
DDeno
Created by octo3. on 4/12/2024 in #help
Is there a workaround for the maximum number limit for getMany?
When using getMany, the maximum number of items is 10. Is there a workaround for this? If not, when using the list method, is it possible to set what to exclude?
1 replies
DDeno
Created by octo3. on 3/18/2024 in #help
Is there a way to specify a range and list from KV?
const kv = await Deno.openKv();
kv.set(["parent", 1], "key1")
kv.set(["parent", 2], "key1")
kv.set(["parent", 3], "key1")
kv.set(["parent", 4], "key1")
const kv = await Deno.openKv();
kv.set(["parent", 1], "key1")
kv.set(["parent", 2], "key1")
kv.set(["parent", 3], "key1")
kv.set(["parent", 4], "key1")
Is it possible to retrieve only those of these that match the content of ["parent", 1~3] ?
5 replies
DDeno
Created by octo3. on 12/17/2023 in #help
How to get `require.main.filename` like Node as Deno
I am making a module to be published on deno.land/x. I want the user to put a file describing the configuration for the module on the same level as the entrypoint file. I could not figure out how to get the entrypoint filename from the module side. In Node.js, require.main.filename seems to solve this. How would this be appropriate to write in Deno?
11 replies
DDeno
Created by octo3. on 9/29/2023 in #help
Is the Fresh compornents test function enabled?
Attempting to write a test for Fresh compornents. I was able to verify the rendered content. I am not able to validate the event. I would appreciate any help if anyone has a solution. Here is the source code.
// test/islands/Counter_test.tsx
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
import { assertEquals } from "https://deno.land/std@0.203.0/testing/asserts.ts";
import { fireEvent, render } from "https://esm.sh/@testing-library/preact?deps=preact@10.15.1";
import { waitFor } from "https://esm.sh/@testing-library/dom";
import Counter from "../../islands/Counter.tsx";
import { signal } from "@preact/signals";

Deno.test("Counter Component", async () => {
const document = new DOMParser().parseFromString(
"<!DOCTYPE html>",
"text/html",
)!;

globalThis.document = document;
window.document = document;

const count = signal(3);
const { container, getByText } = render(<Counter count={count} />);
const counter = container.querySelector("p")!;
assertEquals(counter.textContent, count.value.toString());

fireEvent.click(getByText("-1"));

await waitFor(() => {
assertEquals(counter.textContent, count.value.toString());
});
});
// test/islands/Counter_test.tsx
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
import { assertEquals } from "https://deno.land/std@0.203.0/testing/asserts.ts";
import { fireEvent, render } from "https://esm.sh/@testing-library/preact?deps=preact@10.15.1";
import { waitFor } from "https://esm.sh/@testing-library/dom";
import Counter from "../../islands/Counter.tsx";
import { signal } from "@preact/signals";

Deno.test("Counter Component", async () => {
const document = new DOMParser().parseFromString(
"<!DOCTYPE html>",
"text/html",
)!;

globalThis.document = document;
window.document = document;

const count = signal(3);
const { container, getByText } = render(<Counter count={count} />);
const counter = container.querySelector("p")!;
assertEquals(counter.textContent, count.value.toString());

fireEvent.click(getByText("-1"));

await waitFor(() => {
assertEquals(counter.textContent, count.value.toString());
});
});
Here is the execution command.
deno test --allow-env --no-check
deno test --allow-env --no-check
Here is the execution result.(Excerpt)
$deno test --allow-env --no-check
ERRORS
Counter Component => ./test/islands/Counter_test.tsx:8:6
error: Error: The given node is not an Element, the node type is: object.
at Pe (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:7:1421)
at _ (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:43:9839)
at Function.v.<computed> [as click] (https://esm.sh/v127/@testing-library/preact@3.2.3/X-ZC9wcmVhY3RAMTAuMTUuMQ/denonext/preact.mjs:3:1149)
at file:///D:/development/test/test428-fresh-test/test/islands/Counter_test.tsx:22:13
$deno test --allow-env --no-check
ERRORS
Counter Component => ./test/islands/Counter_test.tsx:8:6
error: Error: The given node is not an Element, the node type is: object.
at Pe (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:7:1421)
at _ (https://esm.sh/v127/@testing-library/dom@8.20.1/denonext/dom.mjs:43:9839)
at Function.v.<computed> [as click] (https://esm.sh/v127/@testing-library/preact@3.2.3/X-ZC9wcmVhY3RAMTAuMTUuMQ/denonext/preact.mjs:3:1149)
at file:///D:/development/test/test428-fresh-test/test/islands/Counter_test.tsx:22:13
4 replies