8000 jsdom manual example - Not Implemented: isContext · Issue #98 · denoland/docs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jsdom manual example - Not Implemented: isContext #98

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

Closed
traceypooh opened this issue Oct 10, 2022 · 3 comments
Closed

jsdom manual example - Not Implemented: isContext #98

traceypooh opened this issue Oct 10, 2022 · 3 comments

Comments

@traceypooh
Copy link
traceypooh commented Oct 10, 2022

Using the manual example for:
https://github.com/denoland/manual/blob/v1.26.1/jsx_dom/jsdom.md
I get:

error: Uncaught Error: Not implemented: isContext
throw new Error(message);
^
at notImplemented (https://deno.land/std@0.153.0/node/_utils.ts:23:9)
at Object.isContext (https://deno.land/std@0.153.0/node/vm.ts:62:3)
at new Sme (https://esm.sh/v96/jsdom@20.0.1/deno/jsdom.js:800:8449)
at iY.createWindow (https://esm.sh/v96/jsdom@20.0.1/deno/jsdom.js:800:6192)
at new py (https://esm.sh/v96/jsdom@20.0.1/deno/jsdom.js:800:23482)
at file:///Users/tracey/av/jsdom.js:4:34

I tried a few versions back in jsdom -- just in case it was that. But get same style failure up to versions 1y old, too, eg:

deno eval 'import { JSDOM } from  "https://esm.sh/jsdom@18.0.0"; new JSDOM("<!DOCTYPE html><html><body></body></html>")'

I'm using latest v1.26.1 of deno. Any help appreciated! I'd love to convert my work codebase jest-based (a fair amount using jsdom) from node to deno. (I tried
import { DOMParser } from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts'; too. And that is working decently for some of the testing -- but we could use a more complete DOM fake for some tests (eg: form submitting, etc.)

Full example here:

> cat deno.jsonc;
{
  "compilerOptions": {
    "lib": [
      "deno.ns",
      "dom",
      "dom.iterable",
      "dom.asynciterable"
    ]
  }
}


> cat jsdom.js   
import { JSDOM } from  "https://esm.sh/jsdom";
import { assert } from "https://deno.land/std@0.132.0/testing/asserts.ts";

const { window: { document } } = new JSDOM(
  `<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Hello from Deno</title>
  </head>
  <body>
    <h1>Hello from Deno</h1>
    <form>
      <input name="user">
      <button>
        Submit
      </button>
    </form>
  </body>
</html>`,
  {
    url: "https://example.com/",
    referrer: "https://example.org/",
    contentType: "text/html",
    storageQuota: 10000000,
  },
);

const h1 = document.querySelector("h1");
assert(h1);

console.log(h1.textContent);


> deno run -A jsdom.js
error: Uncaught Error: Not implemented: isContext
  throw new Error(message);
        ^
    at notImplemented (https://deno.land/std@0.153.0/node/_utils.ts:23:9)
    at Object.isContext (https://deno.land/std@0.153.0/node/vm.ts:62:3)
    at new Sme (https://esm.sh/v96/jsdom@20.0.1/deno/jsdom.js:800:8449)
    at iY.createWindow (https://esm.sh/v96/jsdom@20.0.1/deno/jsdom.js:800:6192)
    at new py (https://esm.sh/v96/jsdom@20.0.1/deno/jsdom.js:800:23482)
    at file:///Users/tracey/av/jsdom.js:4:34
@lino-levan
Copy link
Contributor

This is super weird. From what the error message looks like to me, it seems like it's trying to call node:vm which (as stated in the deno manual) is not going to be supported:

Node has some built-in modules (e.g. like vm) that are effectively incompatible with the scope of Deno and therefore there aren't easy ways to provide a polyfill of the functionality in Deno.

The way I see it, this example could never have worked (assuming it truly does try to access node:vm which is not a guarantee). Definitely worth a review.

@traceypooh
Copy link
Author

In the end, in case anyone's trying to setup jsdom w/ deno -- I found this to be quite good:

import jsdom from 'https://jspm.dev/npm:jsdom-deno@19.0.2';

pairing that with BDD testing worked nicely for us.

(example:)

import {
  describe as describe_bdd, it, beforeEach, afterEach,
} from 'https://deno.land/std/testing/bdd.ts';

import { expect } from 'https://deno.land/x/expect/mod.ts';

const dom = new jsdom.JSDOM(
  '<!doctype html><html><body></body></html>',
  { url: 'http://localhost/' },
);
window.document = dom.window.document;
window.HTMLElement = dom.window.HTMLElement;
window.CSSStyleSheet = dom.window.CSSStyleSheet;
window.customElements = dom.window.customElements;

...

@kwhinnery kwhinnery transferred this issue from denoland/manual Sep 15, 2023
@thisisjofrank
Copy link
Collaborator

Closing for now

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

No branches or pull requests

31CF
4 participants
0