Skip to content

Commit

Permalink
Add tests for Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Jul 12, 2024
1 parent ff8ffac commit 3350b10
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 6 deletions.
5 changes: 4 additions & 1 deletion packages/pglite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"directory": "packages/pglite"
},
"scripts": {
"test": "rm -rf ./pgdata-test && concurrently -s first --hide 1 --prefix none -k \"sleep 2 && ava tests/*.test.js tests/**/*.test.js\" \"npx http-server --port 3334 ./\"",
"test": "rm -rf ./pgdata-test && concurrently -s first --hide 1 --prefix none -k \"sleep 2 && ava tests/**/*.test.js\" \"npx http-server --port 3334 ./\"",
"test:quick": "rm -rf ./pgdata-bun-test && ava tests/*.test.js tests/target/node-*.test.js",
"test:bun": "rm -rf ./pgdata-test && npx bun test tests/basic.test.js && npx bun test tests/pgvector.test.js && npx bun test tests/targets/node-fs.test.js",
"build:js": "tsup && tsx scripts/bundle-wasm.ts",
"build": "npm run build:js",
"format": "prettier --write ./src"
Expand All @@ -55,6 +57,7 @@
"async-mutex": "^0.4.1",
"ava": "^6.1.2",
"buffer": "^6.0.3",
"bun": "^1.1.18",
"comlink": "^4.4.1",
"concurrently": "^8.2.2",
"http-server": "^14.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/tests/basic.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava";
import test from "./polytest.js";
import { PGlite } from "../dist/index.js";

test("basic exec", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/tests/notify.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava";
import test from "./polytest.js";
import { PGlite } from "../dist/index.js";

test("notify", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/tests/pgvector.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava";
import test from "./polytest.js";
import { PGlite } from "../dist/index.js";
import { vector } from "../dist/vector/index.js";

Expand Down
37 changes: 37 additions & 0 deletions packages/pglite/tests/polytest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* This file is a polyfill for AVA tests to run in Bun */

let test;

if (typeof Bun !== "undefined") {
// Minimal implementation of AVA for Bun
const bunTest = await import("bun:test");

const t = {
is: (a, b) => bunTest.expect(a).toBe(b),
deepEqual: (a, b) => bunTest.expect(a).toEqual(b),
like: (a, b) => bunTest.expect(a).toMatchObject(b),
pass: () => bunTest.expect(true).toBe(true),
fail: () => bunTest.expect(true).toBe(false),
throwsAsync: async (fn, expected) => {
try {
await fn();
bunTest.expect(true).toBe(false);
} catch (err) {
bunTest.expect(err).toMatchObject(expected);
}
}
}

test = (name, fn) => {
return bunTest.test(name, () => fn(t));
}
test.before = (fn) => bunTest.beforeAll(() => fn(t));
test.after = (fn) => bunTest.afterAll(() => fn(t));
test.serial = test;
test.serial.before = (fn) => bunTest.beforeEach(() => fn(t));
} else {
// Just use AVA
test = (await import("ava")).default;
}

export default test;
2 changes: 1 addition & 1 deletion packages/pglite/tests/targets/base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava";
import test from "../polytest.js";
import playwright from "playwright";

const wsPort = process.env.WS_PORT || 3334;
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/tests/types.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "ava";
import test from "./polytest.js";
import { types } from "../dist/index.js";

// Parse type tests
Expand Down
84 changes: 84 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3350b10

Please sign in to comment.