BOLL
BOLL
DDeno
Created by BOLL on 11/24/2024 in #help
FileServer from tutorial, 2000+ ms to connect?
No description
6 replies
DDeno
Created by BOLL on 11/3/2024 in #help
Possible to use Deno.test for callbacks?
I've been implementing tests to make sure the porting of my main project to Deno is working out as expected, coupled with this is a WebSocket server done with Deno.serve. For this the test needs to handle both a server and client session, waiting for callbacks to come through. Right now my test finishes prematurely even if I await the termination of the server, I need to set both sanitizeOps: false and sanitizeResources: false to have the test finish at all, but then it skips any assert defined in the callbacks. My previous experience is with Mocha where we get the done callback to run to finish the current test, but for Deno.test I only see us getting the option to make the test caller asynchronous, which in this case doesn't seem to help me. Basically, is it possible to have something like this working:
Deno.test('ws session', async ()=>{
const srv = new Server()
srv.onOpen = ()=>{ /* send message to client */ }
srv.onMessage = ()=>{ /* confirm then disconnect client */ }
srv.onClose = ()=>{ /* finish test */ }
const cli = new Client()
cli.onMessage(()=>{ /* respond to server */ })
})
Deno.test('ws session', async ()=>{
const srv = new Server()
srv.onOpen = ()=>{ /* send message to client */ }
srv.onMessage = ()=>{ /* confirm then disconnect client */ }
srv.onClose = ()=>{ /* finish test */ }
const cli = new Client()
cli.onMessage(()=>{ /* respond to server */ })
})
My problem now is as mentioned that the callbacks will happen at arbitrary points in time and aren't made to be awaited, so they won't be blocking the test from finishing. I can see adding a few more options to the test options object, like awaitDone and timeout, to enable running until manually marked as done or failing when timing out. To finish a test Deno.TestContext could have a .done() method on it. Unless this already exists, but I haven't found how to achieve this in the docs or in the types, yet. The simulated example but with the above suggestion:
Deno.test('ws session', {awaitDone: true, timeout: 5000}, async (t)=>{
const srv = new Server()
// ...
srv.onClose = ()=>{ t.done() }
// ...
})
Deno.test('ws session', {awaitDone: true, timeout: 5000}, async (t)=>{
const srv = new Server()
// ...
srv.onClose = ()=>{ t.done() }
// ...
})
7 replies
DDeno
Created by BOLL on 10/21/2024 in #help
Run Fresh in subfolder with root deno.json
I'm using Fresh in a project where I have a big pile of other code in a separate folder. It works running the project if I have the deno.json file in the Fresh folder, but then formatting etc won't apply to code in the other folder. Considering this, I am trying to get workspaces working, but I'm kind of stuck. If I make a root file and try to include Fresh as a workspace, the imports in it then fails due to not having been prefixed with ./ or ../, if I move the imports to the root deno.json I get an error that the Fresh deno.json requires imports to be in there to run at all, but then those would override the ones in the root. I'm getting very confused by all of this. Is it even possible to have a Fresh instance as a workspace folder? I'm basically looking to do the below, and I'm struggling to keep my sanity:
/
├── deno.json
├── fresh/
│ ├── deno.json
│ └── main.ts
└── other/
├── deno.json
└── main.ts
/
├── deno.json
├── fresh/
│ ├── deno.json
│ └── main.ts
└── other/
├── deno.json
└── main.ts
But yeah, I'm kind of at a moment 22 here and not sure how to get that to work. If possible I want to have separated imports between fresh and other, thus why it's split up like this, but again I'm struggling to actually get Fresh to work while in a workspace.
7 replies
DDeno
Created by BOLL on 10/20/2024 in #help
Deno workspaces and Fresh, a viable combination?
Hello! I'm attempting to port an existing project to Deno and Fresh. I'm still working on the initial setup, and I have a structure like this:
/
├── deno.json
├── server/
│ ├── deno.json
│ └── a Fresh installation
└── lib/
├── deno.json
└── old code to be ported
/
├── deno.json
├── server/
│ ├── deno.json
│ └── a Fresh installation
└── lib/
├── deno.json
└── old code to be ported
I want to separate the code to port and the Fresh installation as one will be ripped apart and the other should already be functional, and figured I could use workspace to join everything up, but I'm struggling to get it to work. First off, the workspace for lib cannot have a name, as there is not one file but a range of files to reference. Do I need to create an index.ts file in there to reference to make this work at all? I already have a generator for that so should be possible but it'll be a large one. I want this so I can reference the stuff in there without the eventual ../../../lib/###. If I remove the name from the subfolder deno.json, the error for missing a file goes away, but instead I get this error from the Fresh installation:
error: Relative import path "preact" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs"
at https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:46
error: Relative import path "preact" not prefixed with / or ./ or ../ and not in import map from "https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs"
at https://esm.sh/v135/preact-render-to-string@6.3.1/X-ZS8q/denonext/preact-render-to-string.mjs:2:46
Is using workspaces with Fresh even a reasonable approach at this point in time, or should I try to move the Fresh deno.json to my root folder and run it all from there? I mostly want it there so scripts can be executed from the root of the project, but maybe that is just wishful thinking. Thinking about it now it feels like I should just leave the deno.json in the ./server folder, hopefully the compile settings will still apply to the other folders for the language server even if they are a level outside. There's many things I'm unsure of here, but figured I could leave a post here with my musings, I'll be back tomorrow 😅 This is so I can sleep after having spent many hours trying to make sense of Fresh today, sadly I'm not that fresh myself so it's been slow going!
4 replies
DDeno
Created by BOLL on 9/29/2024 in #help
PHPStorm (JetBrains) needs restart of LSP server to pick up on code changes, fact of life?
I saw in the only other post showing up for JetBrains that the plugin is apparently not where it should be, I take it that is why I have to constantly restart the LSP server for the linting to actually pick up on my code changes, possibly when it has to do with imports and/or file name changes. I'm converting an old project now and fixes I do don't get registered without this LSP server restart, but then I am doing some pretty substantial refactoring. It hampers the transition to Deno quite a bit for me personally so I'm checking if others are experiencing the same, and if there is an easy fix for this or not. Otherwise I guess the place to talk about this would be in JetBrains issue tracker yeah? 😅 I will stick to Deno in any case, I adore that I can run TypeScript directly, and I won't let that go 😌 (For posterity: PHPStorm 2024.1, Deno plugin 241.17011.2)
1 replies