Comments (5)
I had this problem and it was solved by dropping superoak
and using superdeno
with the app.handle
:
import { superdeno } from "https://deno.land/x/[email protected]/mod.ts";
import app from "./app.ts";
Deno.test("it should return HTML", async () => {
await superdeno(app.handle.bind(app))
.get("/")
.expect(200)
.expect("Content-Type", "text/html; charset=utf-8");
});
from superoak.
Afaik what you have implemented seems sound, it is certainly good practice to clear up post shutdown.
Generally I would advise (as tends to be common practice with supertest
which these libraries are ported from) that you separate the concerns of app
route and middleware logic from the configuration and start (listen
) of the app as superdeno
/superoak
actually handles the starting and stopping of the server for you.
If you’re implementation is quite coupled to the starting of the server or you have quite bespoke listen
implementation then you can also pass a url
to superoak
.
+/- not having it 100% clear how the signal, import and Deno.test
are all playing together, you might be better off using the url
approach otherwise you may be running the server twice? Note will then also need to handle closing the server yourself if use the url
form.
Not 100% familiar with Deno’s signal
implementation so I’m afraid I can’t advise on that one... I’ll have a read! I’m guessing the signal stream is in effect an unresolved promise being awaited on until a signal is finally sent, perhaps when the test ends? Hence why the started async op before the test and would explain why it is complete at the end?
Perhaps you could extract the abort controller and signal handling to a separate entrypoint file which could import the app? You could then test the app in isolation?
Certainly reach out to the Oak community to sanity check the best way to achieve the signal handling - let me know if find anything out!
from superoak.
Hey @viztastic!
You shouldn’t need to call .end()
, let me know if you find you have to and will investigate.
The error implies that you have a promise/async call that has been dispatched prior to the test but hasn’t completed (see your before
section of the error). Everything is resolved correctly once the test is completed.
This leads me to suspect that you have an async code running before the test you’ve shared and it hasn’t been resolved properly. I would check anything you are importing for this test, or any tests that are being run before this test - I don’t think this test is at fault.
Let me know if need further help debugging!
from superoak.
Appreciate the feedback @asos-craigmorten . Took a deeper look and it seems like lines 37-42 of my app.ts is causing the issue
My intention there was to handle cleanup (e.g. close open db connections) before the app exits, similar to what terminus did in express land. Not sure if there's a way to let both co-exist or perhaps what I'm doing is an anti-pattern with respect to oak/deno ??
Totally respect this might no longer be a super-oak issue. Just trying to figure out how to get them to play along.
from superoak.
Another avenue you can explore is testing your Oak application using the app.handle()
API - I've got an example on the SuperDeno repo's examples.
For now I'm going to close this as it's not an issue with SuperOak per say - please do update this though as / if / when you find a solution so the community can use it as a reference
from superoak.
Related Issues (16)
- error: TS2345 [ERROR]: Argument of type 'Application<Record<string, any>>' is not assignable to parameter of type 'string | Application<Record<string, any>>'. HOT 4
- callback function parameters are displaced. HOT 2
- Need a FAQ section in README.md HOT 3
- ReferenceError: Access to "location", run again with --location <href> HOT 2
- Project does not compile with latest version of oak using Deno 1.3.0 HOT 7
- How to test cookie based sessions? HOT 3
- Tests hang when running with --unstable (Oak 7.3, SuperOak 4.2, Deno 1.9.2) HOT 13
- Document how to send request body, headers, etc HOT 1
- Testing error case fails HOT 5
- Example fails with "Re-exporting a type.." HOT 3
- Does not send correctly an application/x-www-form-urlencoded HOT 2
- Demo Code Throws Errors HOT 1
- Suggestion - Jest features HOT 4
- I can`t install it HOT 4
- AssertionError: Test case is leaking async ops. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superoak.