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

Support Deno 2.0 #32

Open
andrija-tosic-rs opened this issue Oct 14, 2024 · 3 comments
Open

Support Deno 2.0 #32

andrija-tosic-rs opened this issue Oct 14, 2024 · 3 comments

Comments

@andrija-tosic-rs
Copy link

Issue

Setup:

  • Deno Version: 2.0.0 (stable, release, aarch64-apple-darwin)
  • v8 Version: 12.9.202.13-rusty
  • Typescript Version: 5.6.2
  • SuperOak Version: 4.8.1

Details

Deno test started breaking after upgrading to Deno 2.0:

Test code:

Deno.test({
	name: 'init test',
	fn: async () => {
		const initReq = await superoak(app);
		const initRes = await initReq
			.post('/init')
			.set('Content-Type', 'application/json')
			.send(initPayloadDemo)
			.expect(Status.OK)

	sanitizeOps: false,
	sanitizeResources: false,
});
ERRORS 
./src/tests/play.test.ts (uncaught error)
error: (in promise) ReferenceError: window is not defined
      (window as any)[SHAM_SYMBOL].promises,
      ^
    at completeXhrPromises (https://deno.land/x/[email protected]/src/test.ts:192:7)
    at https://deno.land/x/[email protected]/src/test.ts:558:21
    at close (https://deno.land/x/[email protected]/src/close.ts:47:52)
  
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

Superoak still works fine on Deno 1.46.3, the latest Deno 1.x version before 2.0.

@petruki
Copy link

petruki commented Oct 14, 2024

This is a problem with superdeno module.
I am not quite familiar with the code that handles the xhr sham, but you can try this workaround to make your tests work with Deno v2 and superoak.

Before your tests, run this line:

(globalThis as any).window = globalThis;

@jlp-craigmorten
Copy link
Collaborator

jlp-craigmorten commented Oct 14, 2024

Hi all 👋

As @petruki points out, it seems there has been a long lived bug in https://github.com/cmorten/superdeno/blob/main/src/test.ts#L192 which makes Deno v2 fall over (this line should read (globalThis as any)[SHAM_SYMBOL].promises!)

I could patch this line however both superdeno and superoak were only ever meant to be drop-in replacements for the supertest package in a world where NPM wasn't supported by Deno.

Deno is now very much claiming Node and NPM compatability (especially with v2) so I would encourage as you do the major upgrades to consider migrating off of superdeno and superoak.

I might consider continuing to support superoak as a thin wrapper over supertest, but will most likely look to sunset superdeno now that it's purpose is over.

@andrija-tosic-rs
Copy link
Author

Thank you both for responding so quickly. If you don't have anything to add, I can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants