Skip to content

test(extension,streams): Set up browser tests #12

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
rekmarks opened this issue Aug 3, 2024 · 1 comment
Closed

test(extension,streams): Set up browser tests #12

rekmarks opened this issue Aug 3, 2024 · 1 comment
Assignees
Labels
chore Not a feature, not documentation, but something we still have to do.

Comments

@rekmarks
Copy link
Member

rekmarks commented Aug 3, 2024

We are eventually going to want to test in the browser, under ses, in an environment that's as close to what we'd expect in production as possible. vitest allows you to do this using its browser mode. I played around with doing this in #11, but punted until the future because I didn't want to rewrite existing JSDOM tests. Here's what I found:

  • For unit tests, the coverage provider has to be istanbul
    • We may as well switch to istanbul everywhere if possible.
  • The following vitest config appeared to work:
const defaultConfig = getDefaultConfig();
delete defaultConfig.test?.environment;

export default mergeConfig(
  defaultConfig,
  defineConfig({
    test: {
      setupFiles: '../shims/dist/endoify.mjs',
      browser: {
        provider: 'playwright',
        name: 'chromium',
        enabled: true,
        headless: true,
      }
    },
  }),
);
@rekmarks rekmarks added the chore Not a feature, not documentation, but something we still have to do. label Aug 3, 2024
rekmarks added a commit that referenced this issue Aug 7, 2024
Jest's ESM support sucks
([ref](jestjs/jest#9430)) and is held up on
some interminable issues related to Node VMs
([ref](nodejs/node#37648)). I was impressed
with `vite` and `vitest` following my experience implementing #8, and
after I discovered that `vitest` has a [browser mode for unit
tests](https://vitest.dev/guide/browser/#browser-mode)—which will
ultimately allow us to test under `ses` in an actual browser
environment—I was sold.

This migrates the entire repo from `jest` to `vitest`. They work very
similarly, except [`vitest` has a number of benefits over
`jest`](https://vitest.dev/guide/comparisons.html), such as not
polluting the global namespace by default. I tried running some tests
under `ses` with lockdown in the browser, and it worked perfectly.
However, it's held up on rewriting tests that rely on JSDOM, so we're
tracking that work in #12.
@rekmarks rekmarks changed the title Set up browser tests test(extension,streams): Set up browser tests Aug 11, 2024
@grypez
Copy link
Contributor

grypez commented Aug 22, 2024

#33 @SMotaal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Not a feature, not documentation, but something we still have to do.
Projects
None yet
Development

No branches or pull requests

2 participants