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

deno test --require or --import (setup file) #26988

Open
birkskyum opened this issue Nov 21, 2024 · 0 comments
Open

deno test --require or --import (setup file) #26988

birkskyum opened this issue Nov 21, 2024 · 0 comments

Comments

@birkskyum
Copy link
Contributor

birkskyum commented Nov 21, 2024

I can't really figure how to do some browser mocking in deno.

I'm using the node command like this, which works:

node --experimental-strip-types --test --import ./test/mock-browser.ts (link to code)

But with deno i get:

deno test --no-check:

error: ReferenceError: document is not defined
      container: document.createElement("div"),

I have in my deno.json

    "lib": [
      "deno.window",
      "dom"
    ]

The mock-browser.ts being:

import MockBrowser from "mock-browser";
const mock = new MockBrowser.mocks.MockBrowser();

global.document = mock.getDocument();
global.window = {};

// Polyfill based on https://gist.github.com/paulirish/1579671
let lastTime = 0;
global.requestAnimationFrame = function (fn) {
  const now = Date.now();
  const nextTime = Math.max(lastTime + 16, now);
  setTimeout(() => fn(lastTime = nextTime), nextTime - now);
};

For node compat, I believe I need a way to do a similar --import in deno test, or another way to give a setup file, which I believe vitest calls it

@birkskyum birkskyum changed the title deno test --require or --import deno test --require or --import (setup file) Nov 21, 2024
@birkskyum birkskyum changed the title deno test --require or --import (setup file) [node compat] deno test --require or --import (setup file) Nov 21, 2024
@birkskyum birkskyum changed the title [node compat] deno test --require or --import (setup file) deno test --require or --import (setup file) Nov 21, 2024
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

1 participant