This PR speeds up tests by handling custom created `Requests` object
directly instead of binding a socket and making a real HTTP request. For
most tests this is fine, and for those that aren't the existing testing
methods are all preserved.
This can be useful when deploying to other providers.
Also more convenient for projects with multiple developers with port
preferences
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
One can now inline the `imports` and `scopes` from the import map directly into deno.json.
For new projects, `import_map.json` is not generated anymore.
Co-authored-by: Luca Casonato <hello@lcas.dev>
I cut out the function that gets an hundler from fresh.
The purpose is to prepare you to create tests for your application.
The introduction of this feature does not affect fresh.
Example:
```typescript main_test.ts
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />
import { createHandler } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
import { assertEquals } from "https://deno.land/std@0.148.0/testing/asserts.ts";
import {
type RequestHandlerLike,
} from "https://deno.land/x/superdeno/src/types.ts";
import {
Document,
DOMParser,
} from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
Deno.test("HTTP assert test.", async (t) => {
await t.step("#1 GET /", async () => {
const handler = await createHandler(manifest) as RequestHandlerLike;
await superdeno(handler)
.get("/")
.expect(200);
});
await t.step("#2 GET /Foo", async () => {
const server = await createHandler(manifest) as RequestHandlerLike;
const r = await superdeno(server)
.get("/Foo")
.expect(200);
const document: Document = new DOMParser().parseFromString(
r.text,
"text/html",
)!;
assertEquals(document.querySelector("div")?.innerText, "Hello Foo");
});
await t.step("#3 GET /Foo/Bar", async () => {
const server = await createHandler(manifest) as RequestHandlerLike;
await superdeno(server)
.get("/Foo/Bar")
.expect(404);
});
});
```
```sh
$ deno test -A main_test.ts
Check file:///usr/src/app/my-project/main_test.ts
running 1 test from ./main_test.ts
HTTP assert test. ...
#1 GET / ... ok (53ms)
#2 GET /Foo ... ok (50ms)
#3 GET /Foo/Bar ... ok (45ms)
HTTP assert test. ... ok (154ms)
ok | 1 passed (3 steps) | 0 failed (300ms)
```
This was discussed in a separate pull request, but prepared in a
separate branch based on @lucacasonato suggestion.
[Add a function to get a server class
instance.](https://github.com/denoland/fresh/pull/552)
Thenk you.
This commit adds support for JSX automatic mode instead of the default
mode that requires the presence of the JSX pragma in each file.
This commit also adds the config file to the `fresh.gen.ts` manifest,
which is used to determine if the client emit should use automatic mode.
The minimum Deno version has also been bumped to 1.25.0.
This commit adds initial support for fresh "plugins". These are bundles
of functionality that can be added to a fresh plugin through a simple
addition in the `main.ts` file.
Right now plugins are only able to hook into the render steps. This
means that they can inject styling and scripts. They can not yet hook
into routing.
Things that I think should be possible now:
- styling integrations for twind, unocss, and probably a few other tools
Things that are not possible yet:
- google analytics middleware
- database connectors
- CMS connectors
The routing additions to plugins can be added in a follow-up though.
This commit adds API routes. These routes are located in the
./pages/api/ directory. Each file in there will have it's default
export invoked for HTTP calls to the corresponding route.
This commit changes how bundling works, by bundling all routes at once.
Static JS assets are now cached immutably.
Additionally this PR completly refactors how the router works to make it
more modular. This allows users to opt out of the default oak server,
and instead create their own.