Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Jul 30, 2024
1 parent bf85a5d commit a68eb0d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 32 deletions.
1 change: 0 additions & 1 deletion packages/pglite/examples/worker-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { vector } from "../dist/vector/index.js";
worker({
async init() {
const pg = new PGlite({
dataDir: "idb://worker-example",
extensions: {
vector,
},
Expand Down
3 changes: 2 additions & 1 deletion packages/pglite/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,11 @@ function connectTab(
result,
} satisfies WorkerRpcResult<typeof method>);
} catch (error) {
console.error(error);
tabChannel.postMessage({
type: "rpc-error",
callId,
error,
error: { message: (error as Error).message },
} satisfies WorkerRpcError);
}
break;
Expand Down
76 changes: 46 additions & 30 deletions packages/pglite/tests/targets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ export function tests(env, dbFilename, target) {
page = await context.newPage();
await page.goto(`http://localhost:${wsPort}/tests/blank.html`);
page.evaluate(`window.dbFilename = "${dbFilename}";`);
evaluate = async (fn) => await page.evaluate(fn);
page.on("console", (msg) => {
console.log(msg);
});
evaluate = async (fn) => {
try {
return await page.evaluate(fn);
} catch (e) {
console.error(e);
throw e;
}
};
}
});

Expand Down Expand Up @@ -161,6 +171,9 @@ export function tests(env, dbFilename, target) {
const page2 = await context.newPage();
await page2.goto(`http://localhost:${wsPort}/tests/blank.html`);
page2.evaluate(`window.dbFilename = "${dbFilename}";`);
page.on("console", (msg) => {
console.log(msg);
});

const res2Prom = page2.evaluate(async () => {
const { live } = await import("../../dist/live/index.js");
Expand Down Expand Up @@ -232,18 +245,18 @@ export function tests(env, dbFilename, target) {

const res2 = await res2Prom;

for (const res of [res1, res2]) {
t.deepEqual(res.initialResults.rows, [
{
id: 1,
name: "test",
},
{
id: 2,
name: "test2",
},
]);
t.deepEqual(res1.initialResults.rows, [
{
id: 1,
name: "test",
},
{
id: 2,
name: "test2",
},
]);

for (const res of [res1, res2]) {
t.deepEqual(res.updatedResults.rows, [
{
id: 1,
Expand All @@ -265,6 +278,9 @@ export function tests(env, dbFilename, target) {
const page2 = await context.newPage();
await page2.goto(`http://localhost:${wsPort}/tests/blank.html`);
page2.evaluate(`window.dbFilename = "${dbFilename}";`);
page.on("console", (msg) => {
console.log(msg);
});

const res2Prom = page2.evaluate(async () => {
const { live } = await import("../../dist/live/index.js");
Expand Down Expand Up @@ -340,25 +356,25 @@ export function tests(env, dbFilename, target) {

const res2 = await res2Prom;

for (const res of [res1, res2]) {
t.deepEqual(res.initialResults.rows, [
{
__after__: null,
id: 1,
name: "test",
},
{
__after__: 1,
id: 2,
name: "test2",
},
{
__after__: 2,
id: 3,
name: "test3",
},
]);
t.deepEqual(res1.initialResults.rows, [
{
__after__: null,
id: 1,
name: "test",
},
{
__after__: 1,
id: 2,
name: "test2",
},
{
__after__: 2,
id: 3,
name: "test3",
},
]);

for (const res of [res1, res2]) {
t.deepEqual(res.updatedResults.rows, [
{
__after__: null,
Expand Down
10 changes: 10 additions & 0 deletions packages/pglite/tests/targets/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { PGlite } from "../../../dist/index.js";
import { worker } from "../../../dist/worker/index.js";

worker({
async init(options) {
return new PGlite({
dataDir: options.dataDir,
});
},
});

0 comments on commit a68eb0d

Please sign in to comment.