Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function onModuleReady(SQL) {
case "close":
if (db) {
db.close();
db = null;
}
return postMessage({
id: data["id"]
Expand Down
14 changes: 14 additions & 0 deletions test/test_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ exports.test = async function test(SQL, assert) {
for (let i = 0; i < header.length; i++) actual += String.fromCharCode(data.buffer[i]);
assert.equal(actual, header, 'Data returned is an SQLite database file');

// Closing returns the worker to its initial, lazily initialized state.
await worker.postMessage({ action: "close" });
await worker.postMessage({ action: "close" });
data = await worker.postMessage({
action: "exec",
sql: "SELECT count(*) AS count FROM sqlite_master WHERE name = 'test'"
});
assert.deepEqual(data.results, [{ columns: ['count'], values: [[0]] }],
'exec after close creates a fresh database');
await worker.postMessage({ action: "close" });
data = await worker.postMessage({ action: "each", sql: "SELECT 7 AS value" });
assert.deepEqual(data.row, { value: 7 },
'each after close creates a fresh database');

// test worker properly opens db after closing
await worker.postMessage({ action: "close" });
await worker.postMessage({ action: "open" });
Expand Down