Skip to content

Commit

Permalink
feat: support Express and upgrade dependencies (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmorten authored Jan 28, 2024
1 parent 55ea0ca commit 112b235
Show file tree
Hide file tree
Showing 33 changed files with 1,435 additions and 306 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 12
node-version: 20
- name: Install deps
run: make deps
- name: Use Deno
uses: denolib/setup-deno@v2
with:
deno-version: 1.19.3
deno-version: 1.40.2
- run: make typedoc
- run: make ci
- name: Publish Updated Type Docs
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: publish typedocs
push_options: --force
push_options: --force
2 changes: 1 addition & 1 deletion .github/workflows/publish-egg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: denolib/setup-deno@v2
with:
deno-version: 1.19.3
deno-version: 1.40.2
- run: deno install -A -f --unstable -n eggs https://x.nest.land/[email protected]/eggs.ts
- run: |
export PATH="/home/runner/.deno/bin:$PATH"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
deno-version: [1.19.3]
deno-version: [1.40.2]

runs-on: ${{ matrix.os }}

Expand All @@ -27,7 +27,7 @@ jobs:
strategy:
matrix:
os: [windows-latest]
deno-version: [1.19.3]
deno-version: [1.40.2]

runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ci:
@make test

deps:
@npm install -g typescript [email protected]
@npm install -g typescript@4 [email protected]

doc:
@deno doc ./mod.ts
Expand All @@ -24,7 +24,7 @@ fmt-check:
@deno fmt --check ${FILES_TO_FORMAT}

lint:
@deno lint --unstable ${FILES_TO_FORMAT}
@deno lint ${FILES_TO_FORMAT}

precommit:
@make typedoc
Expand Down
73 changes: 53 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ HTTP assertions for Deno made easy via <a href="https://github.com/visionmedia/s
</p>
<p align="center">
<a href="https://deno.land/x/superdeno"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fsuperdeno%2Fmod.ts" alt="SuperDeno latest /x/ version" /></a>
<a href="https://github.com/denoland/deno/blob/main/Releases.md"><img src="https://img.shields.io/badge/deno-^1.19.3-brightgreen?logo=deno" alt="Minimum supported Deno version" /></a>
<a href="https://github.com/denoland/deno/blob/main/Releases.md"><img src="https://img.shields.io/badge/deno-^1.40.2-brightgreen?logo=deno" alt="Minimum supported Deno version" /></a>
<a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/superdeno/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fdep-count%2Fx%2Fsuperdeno%2Fmod.ts" alt="SuperDeno dependency count" /></a>
<a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/superdeno/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fupdates%2Fx%2Fsuperdeno%2Fmod.ts" alt="SuperDeno dependency outdatedness" /></a>
<a href="https://deno-visualizer.danopia.net/dependencies-of/https/deno.land/x/superdeno/mod.ts"><img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fcache-size%2Fx%2Fsuperdeno%2Fmod.ts" alt="SuperDeno cached size" /></a>
Expand All @@ -31,7 +31,7 @@ HTTP assertions for Deno made easy via <a href="https://github.com/visionmedia/s
- [Getting Started](#getting-started)
- [About](#about)
- [Installation](#installation)
- [Example](#example)
- [Examples](#examples)
- [Documentation](#documentation)
- [API](#api)
- [Notes](#notes)
Expand All @@ -42,7 +42,7 @@ HTTP assertions for Deno made easy via <a href="https://github.com/visionmedia/s

```ts
import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
import { opine } from "https://deno.land/x/opine@1.9.1/mod.ts";
import { opine } from "https://deno.land/x/opine@2.3.4/mod.ts";

const app = opine();

Expand Down Expand Up @@ -85,9 +85,9 @@ import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
SuperDeno is also available on [nest.land](https://nest.land/package/superdeno),
a package registry for Deno on the Blockchain.

> Note: All examples in this README are using the unversioned form of the import URL. In production you should always use the versioned import form such as `https://deno.land/x/superdeno@4.8.0/mod.ts`.
> Note: All examples in this README are using the unversioned form of the import URL. In production you should always use the versioned import form such as `https://deno.land/x/superdeno@4.9.0/mod.ts`.
## Example
## Examples

You may pass a url string,
[`http.Server`](https://doc.deno.land/https/deno.land/std/http/mod.ts#Server), a
Expand Down Expand Up @@ -116,8 +116,8 @@ Here's an example of SuperDeno working with the Opine web framework:

```ts
import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
import { opine } from "https://deno.land/x/opine@1.9.1/mod.ts";
export { expect } from "https://deno.land/x/expect@v0.2.9/mod.ts";
import { opine } from "https://deno.land/x/opine@2.3.4/mod.ts";
import { expect } from "https://deno.land/x/expect@v0.4.0/mod.ts";

const app = opine();

Expand All @@ -129,19 +129,49 @@ Deno.test("it should support regular expressions", async () => {
await superdeno(app)
.get("/")
.expect("Content-Type", /^application/)
.end((err) => {
.catch((err) => {
expect(err.message).toEqual(
'expected "Content-Type" matching /^application/, got "text/html; charset=utf-8"',
'expected "Content-Type" matching /^application/, got "text/html; charset=utf-8"'
);
});
});
```

See more examples in the [Opine test suite](./test/superdeno.opine.test.ts).

Here's an example of SuperDeno working with the Express web framework:

```ts
import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
// @deno-types="npm:@types/express@^4.17"
import express from "npm:[email protected]";
import { expect } from "https://deno.land/x/[email protected]/mod.ts";

Deno.test("it should support regular expressions", async () => {
const app = express();

app.get("/", (_req, res) => {
res.send("Hello Deno!");
});

await superdeno(app)
.get("/")
.expect("Content-Type", /^application/)
.catch((err) => {
expect(err.message).toEqual(
'expected "Content-Type" matching /^application/, got "text/html; charset=utf-8"'
);
});
});
```

See more examples in the [Express test suite](./test/superdeno.express.test.ts).

Here's an example of SuperDeno working with the Oak web framework:

```ts
import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
import { Application, Router } from "https://deno.land/x/oak@v10.0.0/mod.ts";
import { Application, Router } from "https://deno.land/x/oak@v12.6.2/mod.ts";

const router = new Router();
router.get("/", (ctx) => {
Expand Down Expand Up @@ -171,6 +201,8 @@ Deno.test("it should support the Oak framework", () => {
});
```

See more examples in the [Oak test suite](./test/superdeno.oak.test.ts).

If you are using the [Oak](https://github.com/oakserver/oak/) web framework then
it is recommended that you use the specialized
[SuperOak](https://github.com/cmorten/superoak) assertions library for
Expand All @@ -181,7 +213,7 @@ are making use of the `app.handle()` method (for example for serverless apps)
then you can write slightly less verbose tests for Oak:

```ts
import { Application, Router } from "https://deno.land/x/oak@v10.0.0/mod.ts";
import { Application, Router } from "https://deno.land/x/oak@v12.6.2/mod.ts";
import { superdeno } from "https://deno.land/x/superdeno/mod.ts";

const router = new Router();
Expand All @@ -194,15 +226,16 @@ const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

Deno.test("it should support the Oak framework `app.handle` method", async () => {
/**
* Note that we have to bind `app` to the function otherwise `app.handle`
* doesn't preserve the `this` context from `app`.
*/
await superdeno(app.handle.bind(app))
.get("/")
.expect("Hello Deno!");
});
Deno.test(
"it should support the Oak framework `app.handle` method",
async () => {
/**
* Note that we have to bind `app` to the function otherwise `app.handle`
* doesn't preserve the `this` context from `app`.
*/
await superdeno(app.handle.bind(app)).get("/").expect("Hello Deno!");
}
);
```

In this case, SuperDeno handles the setup and closing of the server for you, so
Expand Down
14 changes: 9 additions & 5 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export { Server } from "https://deno.land/[email protected]/http/server.ts";
export { STATUS_TEXT } from "https://deno.land/[email protected]/http/http_status.ts";
export { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
export { methods } from "https://deno.land/x/[email protected]/src/methods.ts";
export { mergeDescriptors } from "https://deno.land/x/[email protected]/src/utils/mergeDescriptors.ts";
export { Server } from "https://deno.land/[email protected]/http/server.ts";
export { STATUS_TEXT } from "https://deno.land/[email protected]/http/status.ts";
export type { StatusCode } from "https://deno.land/[email protected]/http/status.ts";
export { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
export { methods } from "https://deno.land/x/[email protected]/src/methods.ts";
export { mergeDescriptors } from "https://deno.land/x/[email protected]/src/utils/mergeDescriptors.ts";
export { getFreePort } from "https://deno.land/x/[email protected]/mod.ts";

// TODO: upgrade to v8
export { default as superagent } from "https://jspm.dev/[email protected]";
Loading

0 comments on commit 112b235

Please sign in to comment.