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

Move from Karma to Playwright? #644

Open
dfbaskin opened this issue Sep 30, 2023 · 1 comment · May be fixed by #652
Open

Move from Karma to Playwright? #644

dfbaskin opened this issue Sep 30, 2023 · 1 comment · May be fixed by #652

Comments

@dfbaskin
Copy link

Since Karma is deprecated, does it make sense to move the tests over to Playwright?

As an example, this is what the tests/two-way-iframe.comlink.test.js test might look like:

import { test } from "@playwright/test";

test.describe("Comlink across iframes", function () {
  test.beforeEach(async ({ page }) => {
    await page.goto("/");
    await page.evaluate(async () => {
      this.ifr = document.createElement("iframe");
      this.ifr.sandbox.add("allow-scripts", "allow-same-origin");
      this.ifr.src = "/tests/fixtures/two-way-iframe.html";
      document.body.appendChild(this.ifr);
      await new Promise((resolve) => (this.ifr.onload = resolve));
    });
  });

  test.afterEach(async ({ page }) => {
    await page.evaluate(() => {
      this.ifr.remove();
    });
  });

  test("can communicate both ways", async ({ page }) => {
    const { value, called } = await page.evaluate(async () => {
      const Comlink = await import("/dist/esm/comlink.mjs");
      let called = false;
      const iframe = Comlink.windowEndpoint(this.ifr.contentWindow);
      Comlink.expose((a) => {
        called = true;
        return ++a;
      }, iframe);
      const proxy = Comlink.wrap(iframe);
      const value = await proxy(1, 3);
      return {
        value,
        called,
      };
    });
    test.expect(value).toEqual(5);
    test.expect(called).toEqual(true);
  });
});

If this move makes sense, I could submit a PR.

@benjamind
Copy link
Collaborator

Would love to see this, if you're open to filing a PR!

@dfbaskin dfbaskin linked a pull request Dec 26, 2023 that will 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

Successfully merging a pull request may close this issue.

2 participants