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

Vitest support #173

Closed
fregante opened this issue Jan 15, 2023 · 5 comments
Closed

Vitest support #173

fregante opened this issue Jan 15, 2023 · 5 comments

Comments

@fregante
Copy link
Contributor

I'm looking to switch to Vitest, do you think it would be possible to look for the vi global as well as jest? I'm not sure if that's enough.

Current Vitest config

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    globals: true,
    setupFiles: [
      "jest-webextension-mock"
    ]
  },
})

Output

 FAIL  utils.test.ts [ utils.test.ts ]
ReferenceError: jest is not defined
 ❯ Object.<anonymous> node_modules/jest-webextension-mock/dist/setup.js:5:25

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

Related

@clarkbw
Copy link
Owner

clarkbw commented Jan 23, 2023

Looks like this solution should work vitest-dev/vitest#2667 (comment)

@fregante
Copy link
Contributor Author

fregante commented Jan 23, 2023

I know, I opened that issue there, 😅 but the point of this issue here would be to avoid having figure out any config for it. It looks like it's as easy as using globalThis.jest ?? globalThis.vi here. I don't know if that's desirable here though if you don't use vitest anywhere.

@clarkbw
Copy link
Owner

clarkbw commented Jan 24, 2023

I don't know if that's desirable here though if you don't use vitest anywhere.

I don't use vitest so I'm not inclined to attempt to support it here. I wouldn't mind a shim for it but given we'd need some test infra of both systems to make sure it continues to work I think ultimately this would be a pretty big lift for someone to write and then continue to maintain.

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2023
@albertpratomo
Copy link

@fregante did you manage to mock webextension-polyfill in Vitest tests? If yes could you share how / the public repo that you have? Very much appreciated 🙏🏼

@fa-sharp
Copy link

For anyone who comes here wondering how to make this library work with Vitest:

// vitest.setup.ts
import { vi } from "vitest";

//@ts-ignore
globalThis.jest = vi;
// vitest.config.ts
export default defineConfig({
  //...
  test: {
    setupFiles: ["vitest.setup.ts", "jest-webextension-mock"],
    sequence: { setupFiles: "list" },
    environment: "jsdom"
  },
  //...
});

I've only been using this for mocking Chrome storage, so I can't speak for the other aspects of web extensions.

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

4 participants