Skip to content

Commit

Permalink
more weird testing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed Apr 3, 2024
1 parent dd02434 commit 2011929
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/vanilla/mathmock.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "@playwright/test";
import { test } from "rollwright";
import alias from "@rollup/plugin-alias";
import virtual from "@rollup/plugin-virtual";

test.describe("mock", () => {
test.use({ plugins: [alias({ entries: { "./math.js": "./math.mock.js" } })] });
Expand Down Expand Up @@ -29,6 +30,44 @@ test.describe("mock", () => {
});
});

test.describe("virtual mock", () => {
test.use({
plugins: [
virtual({
inlinemock: `
import { stub } from "sinon";
export let sum = await (${async () => {
let { stub } = await import("sinon");
return stub().returns(10);
}})();
export let multiply = stub();
`,
}),
alias({ entries: { "./math.js": "inlinemock" } }),
],
});

test("sum 1", async ({ execute }) => {
let mock = await execute(async () => {
let { sum } = await import("inlinemock");
return sum;
});

let res = await execute(async (from) => {
let element = document.createElement("div");
document.body.append(element);

let { sum } = await import("./math.js");
element.append(document.createTextNode(String(sum(from, 2))));
return element;
}, 1);

expect(await res.asElement().innerText()).toContain(String(10));
expect(await mock.evaluate((v) => v.callCount)).toEqual(1);
expect(await mock.evaluate((v) => v.calledWith(1, 2))).toEqual(true);
});
});

test.describe("real", () => {
test("sum 1", async ({ execute }) => {
let res = await execute(async (from) => {
Expand Down
1 change: 1 addition & 0 deletions examples/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@playwright/test": "^1.42.1",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-virtual": "^3.0.2",
"rollup-plugin-worker-url": "file:../../packages/rollup-plugin-worker-url",
"rollwright": "file:../../packages/rollwright",
"sinon": "^17.0.1"
Expand Down

0 comments on commit 2011929

Please sign in to comment.