Skip to content

Commit

Permalink
chore: improve test with esm.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mabels committed Dec 6, 2024
1 parent d4d4486 commit a671495
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
File renamed without changes.
33 changes: 27 additions & 6 deletions smoke/esm/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
import { page } from "@vitest/browser/context";
import { expect, it, vi } from "vitest";

it("iife", async () => {
it("esm.sh", async () => {
const script = document.createElement("script");
script.textContent = `
import { fireproof } from 'http://localhost:4874/@fireproof/core'
async function main() {
const db = fireproof("iife-test");
const ok = await db.put({ sort: Math.random(), test: "iife-success" });
function invariant(cond, message) {
if (!cond) {
throw new Error(message)
}
}
async function action(run) {
const db = fireproof("esm-test");
const ok = await db.put({ sort: Math.random(), test: "esm-success" });
const beforeAll = await db.allDocs()
await db.put({ foo: 1 })
const afterAll = await db.allDocs()
invariant(
afterAll.rows.length == beforeAll.rows.length + 1,
"all docs wrong count",
)
const res = await db.get(ok.id)
const label = document.querySelector('label')
label.innerHTML = res.test
label.innerHTML = [run,res.test].join(' - ')
await db.close()
}
async function main() {
for (let i = 0; i < 10; i++) {
await action(i)
}
label.setAttribute("data-ready", "");
}
main().catch(console.error)
Expand All @@ -22,5 +43,5 @@ main().catch(console.error)
document.body.appendChild(script);

await vi.waitUntil(() => document.querySelector("[data-ready]"), { timeout: 500_000 });
expect(await page.getByTestId("label").element().innerText).toBe("iife-success");
expect(await page.getByTestId("label").element().innerText).toBe("9 - esm-success");
});

0 comments on commit a671495

Please sign in to comment.