summaryrefslogtreecommitdiff
path: root/tests/js/accretion.mjs
blob: 3ea90c36daa5511c4288485bcb47d47756a10fa5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import assert from "node:assert/strict";

import sqlite from "../../src/sqlite.cjs";

import { runTests }          from "../runner.mjs";
import { promisifyDb, open } from "../../src/db.mjs";
import { runMigrations }     from "../../src/accretion.mjs";


const test_runMigrations = t => {
	t.start("runMigrations()");

	t.test("running twice is a noop", async () => {
		const db = await open(":memory:");
		const migrationsFn = () => db.all("SELECT filename FROM migrations;");

		assert.rejects(
			migrationsFn,
			{ message: "SQLITE_ERROR: no such table: migrations" },
		);

		await runMigrations(db);
		const filled = await migrationsFn();

		await runMigrations(db);
		const unchanged = await migrationsFn();

		assert.deepEqual(filled, unchanged);
	});
};


await runTests([
	test_runMigrations,
]);