cmorten / superoak Goto Github PK
View Code? Open in Web Editor NEWHTTP assertions for Oak made easy via SuperDeno. ๐ฟ ๐ฆ
Home Page: https://cmorten.github.io/superoak/
License: MIT License
HTTP assertions for Oak made easy via SuperDeno. ๐ฟ ๐ฆ
Home Page: https://cmorten.github.io/superoak/
License: MIT License
Setup:
When sending a form like:
superoak(app)
.post("/")
.type("form")
.field("hello", "world")
.field("foo", "bar")
Instead of receiving {hello: "world", foo: "bar"}
I'm receiving the following:
{
"------9219543305020510994576475827\r\nContent-Disposition: form-data; name": '"hello"\r\n\r\nworld\r\n------9219543305020510994576475827\r\nContent-Disposition: form-data; name="foo"\r\n\r\n...'
}
I'm going to open a PR with a failing test to validate this
Setup:
When running the tests with deno test --allow-net app.test.ts
I get the above error message.
Following the example I set up the tests and ran deno test --allow-net app.test.ts
but this error occurs.
ฮป deno test --allow-net app.test.ts
running 2 tests
test GET "/" route ... Listening on: http://127.0.0.1:30162
FAILED (9ms)
test GET "/user/:id" ... Listening on: http://127.0.0.1:21887
FAILED (4ms)
failures:
GET "/" route
ReferenceError: Access to "location", run again with --location <href>.
at get (deno:op_crates/web/12_location.js:376:17)
at Function.request.getXHR (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:91:39)
at Test.Request._end (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:753:24)
at Test.Request.end (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:736:10)
at Test.end (test.ts:443:9)
at https://dev.jspm.io/npm:[email protected]/lib/request-base.dew.js:291:14
at new Promise (<anonymous>)
at Test.RequestBase.then (https://dev.jspm.io/npm:[email protected]/lib/request-base.dew.js:273:33)
GET "/user/:id"
ReferenceError: Access to "location", run again with --location <href>.
at get (deno:op_crates/web/12_location.js:376:17)
at Function.request.getXHR (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:91:39)
at Test.Request._end (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:753:24)
at Test.Request.end (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:736:10)
at Test.end (test.ts:443:9)
at https://dev.jspm.io/npm:[email protected]/lib/request-base.dew.js:291:14
at new Promise (<anonymous>)
at Test.RequestBase.then (https://dev.jspm.io/npm:[email protected]/lib/request-base.dew.js:273:33)
failures:
GET "/" route
GET "/user/:id"
test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out (14ms)
Passing in any random "valid" URL like deno test --allow-net --location http://anything app.test.ts
makes the tests run again.
deno test --allow-net --location http://anything app.test.ts
running 2 tests
test GET "/" route ... Listening on: http://127.0.0.1:17370
ok (18ms)
test GET "/user/:id" ... Listening on: http://127.0.0.1:26924
ok (7ms)
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (29ms)
It even runs when I just pass in --location http://a
. I hope this only has to do with the Deno update to 1.7.2.
Thanks in advance for looking into it. :)
Setup:
Use the same superoak
instance multiple times in a same test
// ...
Deno.test("app", async () => {
const testClient = await superoak(app);
await testClient.get("/").expect("Hello GET!");
await testClient.post("/").expect("Hello POST!");
});
// ...
leads to vague error message like below:
Error: Request has been terminated
Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
at Test.Request.crossDomainError (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:680:15)
at XMLHttpRequestSham.xhr.onreadystatechange (https://dev.jspm.io/npm:[email protected]/lib/client.dew.js:783:21)
at XMLHttpRequestSham.xhrReceive (https://deno.land/x/[email protected]/src/xhrSham.js:105:29)
at XMLHttpRequestSham.send (https://deno.land/x/[email protected]/src/xhrSham.js:64:12)
I'm not sure is this a bug or not. Maybe add this to a FAQ section in README.md would save people's time. ๐
Setup:
deno 1.1.0
v8 8.4.300
typescript 3.9.2
oak version: v5.3.0
Getting the following error (screenshot above)
AssertionError: Test case is leaking async ops.
Before:
- dispatched: 7
- completed: 6
After:
- dispatched: 23
- completed: 23
Am I meant to chain a .end()
to the last request in each test file?
Hi! When running Deno superoak tests with --unstable
flag in recent Deno / Oak -versions, the tests get stuck.
Setup:
Example code:
import { Application } from "https://deno.land/x/[email protected]/mod.ts";
import { superoak } from "https://deno.land/x/[email protected]/mod.ts";
const app = new Application();
const greet = (context) => {
context.response.body = "Hello world!";
};
app.use(greet);
Deno.test("Response is 'Hello world!'", async () => {
const response = await superoak(app);
await response
.get("/")
.expect("Hello world!");
});
When running the tests with deno test --allow-net --unstable app.js
, the tests get stuck. However, with deno test --allow-net app.js
, the tests can be successfully run. This might have something to do with the native HTTP server enabled in oak when using the --unstable
-flag, but have not looked into this in detail. Oak can be normally used with the --unstable
flag though.
Project not compiling using oak
Setup:
macOS Big Sur
deno 1.3.0
v8 8.6.334
typescript 3.9.7
Not sure exactly why but my project is not compiling with the latest version of superoak and oak
Here is a reproducible case:
deps.ts
export {
Application,
Router,
} from "https://deno.land/x/oak/mod.ts";
export { superoak } from "https://deno.land/x/superoak/mod.ts";
app.ts
import { Application, Router } from './deps.ts';
const router = new Router();
router
.get('/', (context) => {
context.response.body = 'Hello ๐';
})
const app = new Application();
export { app };
app.use(router.routes());
await app.listen({ port: 8080 });
I am running
/usr/local/bin/den ./app.ts
Setup:
deno 1.0.5
v8 8.4.300
typescript 3.9.2
What i did:
copy paste your demo code on the github
The Error:
error: error sending request for url (https://raw.githubusercontent.com/garronej/minimal_polyfills/2.1.0/Set.ts): error trying to connect: dns error: ่ฏทๆฑ็ๅ็งฐๆๆ๏ผไฝๆฏๆพไธๅฐ่ฏทๆฑ็็ฑปๅ็ๆฐๆฎใ (os error 11004)
translation: title of the request is valid, but could not find the data of requesting type.(sorry for the bad translation)
When running the demo script it throws four errors.
Setup:
The script was copied from the readme file and named demo.test.ts
$ deno test --allow-net demo.test.ts
error: TS2322 [ERROR]: Type '{}' is not assignable to type 'RouteParams<R>'.
params: RouteParams<R> = {},
~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/router.ts:223:3
TS2322 [ERROR]: Type '{}' is not assignable to type 'RouteParams<R>'.
let replace: RouteParams<R> = {};
~~~~~~~
at https://deno.land/x/[email protected]/router.ts:227:7
TS2322 [ERROR]: Type '{}' is not assignable to type 'RouteParams<R>'.
existingParams: RouteParams<R> = {},
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/router.ts:301:5
TS2322 [ERROR]: Type '{}' is not assignable to type 'RouteParams<R>'.
params: RouteParams<R> = {},
~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/router.ts:321:5
Found 4 errors.
I followed the advertized example in creating a file "demo.test.ts" and ran deno test --allow-net demo.test.ts
in a fresh directory. Here's the output:
Check file:///.../deno/testing/demo.test.ts
error: TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { AsyncReturnType } from "./AsyncReturnType.ts";
~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/tools/typeSafety/index.ts:2:10
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { UnpackPromise } from "./UnpackPromise.ts";
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/tools/typeSafety/index.ts:8:10
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { UnpackTypeGuard } from "./UnpackTypeGuard.ts";
~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/tools/typeSafety/index.ts:9:10
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Ctx, DoneOrAborted } from "./Ctx.ts";
~~~
at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:1:10
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Ctx, DoneOrAborted } from "./Ctx.ts";
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:1:15
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { CtxLike, VoidCtxLike } from "./CtxLike.ts";
~~~~~~~~~~~
at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:2:19
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Evt } from "./Evt.ts";
~~~
at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:3:10
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { NonPostableEvt } from "./NonPostableEvt.ts";
~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/lib/types/interfaces/index.ts:4:10
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Postable } from "./Postable.ts";
...
Setup:
Hi @asos-craigmorten, I'm using your module (including the wrappers describe and it) and it would be great if some other Jest helper functions are also implemented, like the Setup and Teardown ones (beforeEach/All and afterEach/All) and Mock Functions.
Thanks.
Setup:
I am trying to run a simple test in my app, but it constantly fails because of leaking async ops, even though there's nothing running.
import { Application} from "https://deno.land/x/[email protected]/mod.ts";
import { superoak } from "https://deno.land/x/[email protected]/mod.ts";
const app = new Application();
app.use((ctx) => {
ctx.response.body = "Hello world!";
});
Deno.test("Example", async () => {
const request = await superoak(app);
});
To run: deno test --allow-net <that code>.ts
Error log:
running 1 tests
test test ... FAILED (8ms)
failures:
test
AssertionError: Test case is leaking async ops.
Before:
- dispatched: 0
- completed: 0
After:
- dispatched: 2
- completed: 1
Make sure to await all promises returned from Deno APIs before
finishing test case.
at assert (deno:cli/rt/06_util.js:33:13)
at asyncOpSanitizer (deno:cli/rt/40_testing.js:44:7)
at async Object.resourceSanitizer [as fn] (deno:cli/rt/40_testing.js:68:7)
at async TestRunner.[Symbol.asyncIterator] (deno:cli/rt/40_testing.js:240:13)
at async Object.runTests (deno:cli/rt/40_testing.js:317:22)
failures:
test
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (8ms)
I cannot find any documented way of sending a post request with a body or setting custom headers on the request. According to the docs Test.post(url:string)
there is only a url accepted. How should I set headers and post body on request?
Setup:
Please replace this quote block with the details of the feature / bug you wish
to be addressed. If it is a bug please do your best to add steps to reproduce.
Trying to test that an endpoint returns an error status code (like 400) fails.
https://github.com/twhitbeck/superoak-testcase
curl localhost:8080/create -H "Content-Type: application/json" -d "{\"url\":\"foo\"}" -v
I'm trying to create a test case that this endpoint will respond with 400.
deno test --allow-net
[uncaught oak error]: BadRequestError - Invalid url
request: { url: "http://127.0.0.1:19542/create", method: "POST", hasBody: true }
response: { status: 404, type: undefined, hasBody: false, writable: true }
at createHttpError (https://deno.land/x/[email protected]/httpError.ts:128:10)
at Context.throw (https://deno.land/x/[email protected]/context.ts:177:17)
at file:///home/twhitbeck/src/local/superoak-testcase/server.ts:18:18
at async dispatch (https://deno.land/x/[email protected]/middleware.ts:41:7)
at async dispatch (https://deno.land/x/[email protected]/middleware.ts:41:7)
at async dispatch (https://deno.land/x/[email protected]/middleware.ts:41:7)
at async Application.#handleRequest (https://deno.land/x/[email protected]/application.ts:378:9)
test it should respond with 400 when the url is marlformed ... FAILED (18ms)
failures:
it should respond with 400 when the url is marlformed
AssertionError: Test case is leaking async ops.
Before:
- dispatched: 2
- completed: 2
After:
- dispatched: 13
- completed: 12
Make sure to await all promises returned from Deno APIs before
finishing test case.
at assert (deno:runtime/js/06_util.js:42:13)
at asyncOpSanitizer (deno:runtime/js/40_testing.js:48:7)
at async resourceSanitizer (deno:runtime/js/40_testing.js:72:7)
at async exitSanitizer (deno:runtime/js/40_testing.js:99:9)
at async runTest (deno:runtime/js/40_testing.js:215:7)
at async Object.runTests (deno:runtime/js/40_testing.js:283:22)
at async file:///home/twhitbeck/src/local/superoak-testcase/c7629de1-c472-4780-a46d-d82b87eba195$deno$test.js:4:1
failures:
it should respond with 400 when the url is marlformed
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out (90208ms)
error: Test failed
Setup:
Callback function parameters are displaced.
I want to use callback function like below but the test fails because res is undefined.
Deno.test("test", async () => {
const req = await superoak(app);
await req.post("/").expect((err, res) => {
expect(res.body.message).toEqual("Hello Deno!");
});
});
Callback described as CallbackHandler(err: any, res: IResponse): void
in typescript autocomplete, but actually the first argument contains response value so it should be CallbackHandler(res: IResponse, err: any): void
.
Setup:
Hello, I'm trying to figure out how to use superoak to test multiple routes that would sign-up and sign-in a user via session cookie. Is there any way to read headers from response and pass them to a request?
Setup:
deno 1.0.3
v8 8.4.300
typescript 3.9.2
const router = new Router();
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
const response: SuperDeno = await superoak(app);
Running this code gives me:
error: TS2345 [ERROR]: Argument of type 'Application<Record<string, any>>' is not assignable to parameter of type 'string | Application<Record<string, any>>'.
Type 'import("https://deno.land/x/oak/application").Application<Record<string, any>>' is not assignable to type 'import("https://deno.land/x/[email protected]/application").Application<Record<string, any>>'.
Property '#middleware' in type 'Application' refers to a different member that cannot be accessed from within type 'Application'.
const response: SuperDeno = await superoak(app);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.