lowlight
lowlight
DDeno
Created by lowlight on 10/29/2023 in #help
Deno.test without Deno namespace ?
Yeah finally I went with just not testing other environments in Deno. It makes more sense like you said and seems more clean indeed. It just that the ocd was triggered by the red lines shown in deno coverage Just to clarify, the workers weren't really part of the code, it was just a workaround for creating a "Realm" since ShadowRealms are not yet supported. Removing deno namespace from them was mostly to "simulate" a browser environment. Thanks for taking the time to answer and for your thoughtful explanation
9 replies
DDeno
Created by lowlight on 10/29/2023 in #help
Deno.test without Deno namespace ?
But basically I'm looking for something like this (but even in the web worker this option was removed as deno is always available so I assume it's not possible to do it anymore)
Deno.test("non-deno", {deno:{namespace:false}}, () => { func()})
Deno.test("non-deno", {deno:{namespace:false}}, () => { func()})
9 replies
DDeno
Created by lowlight on 10/29/2023 in #help
Deno.test without Deno namespace ?
I got this part right, but my question was more oriented towards testing and coverage Like in your example, how would you use Deno.test to pass into the "non-deno" branch ? I'd like to avoid using something this (unless it's the only way):
const {Deno:_Deno} = globalThis
Deno.test("deno", () => { func() })
Deno.test("non-deno", () => { delete globalThis.Deno; func(); globalThis.Deno = _Deno })
const {Deno:_Deno} = globalThis
Deno.test("deno", () => { func() })
Deno.test("non-deno", () => { delete globalThis.Deno; func(); globalThis.Deno = _Deno })
Currently I use something like this so it doesn't affect the global env as workers are kind of sepearate thread, but because of the bug mentionned, the code executed within workers is not covered
Deno.test("deno", () => { func() })
Deno.test("non-deno", async () => {
const script = `delete self.Deno; self.postMessage((${func.toString()})()); self.close`
const worker = new Worker(`data:text/javascript;base64,${btoa(script)}`, {type:"module"})
const promise = deferred()
worker.addEventListener("message", ({data}) => promise.resolve(data))
await promise
})
Deno.test("deno", () => { func() })
Deno.test("non-deno", async () => {
const script = `delete self.Deno; self.postMessage((${func.toString()})()); self.close`
const worker = new Worker(`data:text/javascript;base64,${btoa(script)}`, {type:"module"})
const promise = deferred()
worker.addEventListener("message", ({data}) => promise.resolve(data))
await promise
})
9 replies