Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Deno 2.0 compatible #45

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.0.5
2 changes: 1 addition & 1 deletion .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Use Deno
uses: denolib/setup-deno@v2
with:
deno-version: 1.40.2
deno-version: 2.0.5
- run: make typedoc
- run: make ci
- name: Publish Updated Type Docs
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.40.2]
deno-version: [2.0.5]

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
FILES_TO_FORMAT = ./src ./test ./deps.ts ./mod.ts ./version.ts

build:
@deno run --reload mod.ts
@deno run --allow-import --reload mod.ts

ci:
@make fmt-check
Expand Down Expand Up @@ -32,8 +32,8 @@ precommit:
@make fmt

test:
@deno test --allow-net --allow-read --allow-env --no-check --doc
@deno test --allow-net --allow-read --allow-env --no-check --doc --unstable
@deno test --allow-net --allow-read --allow-env --allow-import --no-check --doc
@deno test --allow-net --allow-read --allow-env --allow-import --no-check --doc --unstable

typedoc:
@rm -rf docs
Expand Down
142 changes: 71 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ SuperTest not working for you? [Raise an issue on Deno](https://github.com/denol
## Getting Started

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

const app = opine();

app.get("/user", (req, res) => {
res.setStatus(200).json({ name: "Deno" });
});

superdeno(app)
.get("/user")
.expect("Content-Type", /json/)
.expect("Content-Length", "15")
.expect(200)
.end((err, res) => {
if (err) throw err;
});
// import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
// import { opine } from "https://deno.land/x/opine@2.3.4/mod.ts";

// const app = opine();

// app.get("/user", (req, res) => {
// res.setStatus(200).json({ name: "Deno" });
// });

// superdeno(app)
// .get("/user")
// .expect("Content-Type", /json/)
// .expect("Content-Length", "15")
// .expect(200)
// .end((err, res) => {
// if (err) throw err;
// });
```

Looking to test an Oak web server? Check out
Expand Down Expand Up @@ -126,26 +126,26 @@ Deno.test("GET /user responds with json", async () => {
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@2.3.4/mod.ts";
import { expect } from "https://deno.land/x/expect@v0.4.0/mod.ts";

const app = opine();

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

Deno.test("it should support regular expressions", async () => {
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"'
);
});
});
// import { superdeno } from "https://deno.land/x/superdeno/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();

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

// Deno.test("it should support regular expressions", async () => {
// 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 [Opine test suite](./test/superdeno.opine.test.ts).
Expand Down Expand Up @@ -181,35 +181,35 @@ 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@v12.6.2/mod.ts";

const router = new Router();
router.get("/", (ctx) => {
ctx.response.body = "Hello Deno!";
});

const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());

Deno.test("it should support the Oak framework", () => {
const controller = new AbortController();
const { signal } = controller;

app.addEventListener("listen", async ({ hostname, port, secure }) => {
const protocol = secure ? "https" : "http";
const url = `${protocol}://${hostname}:${port}`;

await superdeno(url)
.get("/")
.expect("Hello Deno!", () => {
controller.abort();
});
});

await app.listen({ port: 0, signal });
});
// import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
// import { Application, Router } from "https://deno.land/x/oak@v12.6.2/mod.ts";

// const router = new Router();
// router.get("/", (ctx) => {
// ctx.response.body = "Hello Deno!";
// });

// const app = new Application();
// app.use(router.routes());
// app.use(router.allowedMethods());

// Deno.test("it should support the Oak framework", () => {
// const controller = new AbortController();
// const { signal } = controller;

// app.addEventListener("listen", async ({ hostname, port, secure }) => {
// const protocol = secure ? "https" : "http";
// const url = `${protocol}://${hostname}:${port}`;

// await superdeno(url)
// .get("/")
// .expect("Hello Deno!", () => {
// controller.abort();
// });
// });

// await app.listen({ port: 0, signal });
// });
```

See more examples in the [Oak test suite](./test/superdeno.oak.test.ts).
Expand Down Expand Up @@ -292,12 +292,12 @@ Pass a custom assertion function. It'll be given the response object to check.
If the check fails, throw an error.

```ts
function hasPreviousAndNextKeys(res) {
if (!("next" in res.parsedBody)) throw new Error("missing next key");
if (!("prev" in res.parsedBody)) throw new Error("missing prev key");
}
// function hasPreviousAndNextKeys(res) {
// if (!("next" in res.parsedBody)) throw new Error("missing next key");
// if (!("prev" in res.parsedBody)) throw new Error("missing prev key");
// }

await superdeno(app).get("/").expect(hasPreviousAndNextKeys);
// await superdeno(app).get("/").expect(hasPreviousAndNextKeys);
```

### .end(fn)
Expand Down
2 changes: 1 addition & 1 deletion egg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "superdeno",
"description": "HTTP assertions for Deno made easy via superagent.",
"version": "4.9.0",
"version": "5.0.0",
"repository": "https://github.com/cmorten/superdeno",
"stable": true,
"checkFormat": false,
Expand Down
7 changes: 3 additions & 4 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type Parser = (str: string) => any;
type MultipartValueSingle =
| Blob
| Uint8Array
| Deno.Reader
| string
| boolean
| number;
Expand Down Expand Up @@ -189,7 +188,7 @@ exposeSham(SHAM_SYMBOL);
async function completeXhrPromises() {
for (
const promise of Object.values(
(window as any)[SHAM_SYMBOL].promises,
(globalThis as any)[SHAM_SYMBOL].promises,
)
) {
if (promise) {
Expand Down Expand Up @@ -221,7 +220,7 @@ export class Test extends SuperRequest {
#urlSetupPromise: Promise<void>;

public app: string | ListenerLike | ServerLike;
public url!: string;
public override url!: string;

constructor(
app: string | ListenerLike | ServerLike,
Expand Down Expand Up @@ -536,7 +535,7 @@ export class Test extends SuperRequest {
* @returns {Test} for chaining
* @public
*/
end(callback?: CallbackHandler): this {
override end(callback?: CallbackHandler): this {
Promise.allSettled([this.#serverSetupPromise, this.#urlSetupPromise]).then(
() => {
const self = this;
Expand Down
2 changes: 1 addition & 1 deletion test/deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { dirname, join } from "https://deno.land/std@0.213.0/path/mod.ts";
export { expect } from "https://deno.land/x/expect@v0.4.0/mod.ts";
export * as Opine from "https://deno.land/x/opine@2.3.4/mod.ts";
// export * as Opine from "https://deno.land/x/opine@2.3.4/mod.ts";

// TODO: upgrade to v13.0.0 - appear to be getting error when using AbortController
export * as Oak from "https://deno.land/x/oak@v12.6.2/mod.ts";
Expand Down
40 changes: 20 additions & 20 deletions test/form-data.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Oak, Opine } from "./deps.ts";
import { Oak } from "./deps.ts";
import { describe, it } from "./utils.ts";
import {
assertStrictEquals,
Expand Down Expand Up @@ -29,20 +29,20 @@ const setupOak = () => {
return app;
};

const setupOpine = () => {
const app = Opine.opine();
// const setupOpine = () => {
// const app = Opine.opine();

app.post("/", (req, res) => {
assertStringIncludes(
req.headers.get("content-type") ?? "",
"multipart/form-data; boundary=",
);
// app.post("/", (req, res) => {
// assertStringIncludes(
// req.headers.get("content-type") ?? "",
// "multipart/form-data; boundary=",
// );

res.send("done");
});
// res.send("done");
// });

return app;
};
// return app;
// };

describe("post multipart/form-data", () => {
it("should work with oak", async () => {
Expand All @@ -55,13 +55,13 @@ describe("post multipart/form-data", () => {
.expect(200);
});

it("should work with opine", async () => {
const app = setupOpine();
// it("should work with opine", async () => {
// const app = setupOpine();

await superdeno(app)
.post("/")
.field("form_key", "form_value")
.attach("file_key", "path_to_file", "filename")
.expect(200);
});
// await superdeno(app)
// .post("/")
// .field("form_key", "form_value")
// .attach("file_key", "path_to_file", "filename")
// .expect(200);
// });
});
Loading