summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-02-25 05:01:00 -0300
committerEuAndreh <eu@euandre.org>2024-02-25 05:01:00 -0300
commit458bf0fc628d9bcf6a59a0efb898045266dab6ba (patch)
treebb538753668dad5abc7eec4a65bf4f233b34d93a /tests
parentNormalize how modules import and name each other (diff)
downloadpapod-458bf0fc628d9bcf6a59a0efb898045266dab6ba.tar.gz
papod-458bf0fc628d9bcf6a59a0efb898045266dab6ba.tar.xz
Explicit import from "node:process"; move log() to hero.mjs
Diffstat (limited to 'tests')
-rw-r--r--tests/js/accretion.mjs14
-rw-r--r--tests/js/db.mjs5
-rw-r--r--tests/js/hero.mjs24
-rw-r--r--tests/js/utils.mjs16
4 files changed, 35 insertions, 24 deletions
diff --git a/tests/js/accretion.mjs b/tests/js/accretion.mjs
index a0fbb66..73c93c8 100644
--- a/tests/js/accretion.mjs
+++ b/tests/js/accretion.mjs
@@ -1,10 +1,12 @@
import assert from "node:assert/strict";
+import fs from "node:fs";
import sqlite from "../../src/sqlite.cjs";
import * as runner from "../runner.mjs";
import * as db from "../../src/db.mjs";
import {
+ MIGRATIONS_DIR,
runMigrations,
} from "../../src/accretion.mjs";
@@ -13,6 +15,8 @@ const test_runMigrations = t => {
t.start("runMigrations()");
t.test("running twice is a noop", async () => {
+ const contents = [];
+ const logFn = x => contents.push(x);
const handle = await db.open(":memory:");
const migrationsFn = () => handle.all("SELECT filename FROM migrations;");
@@ -21,13 +25,19 @@ const test_runMigrations = t => {
{ message: "SQLITE_ERROR: no such table: migrations" },
);
- await runMigrations(handle);
+ await runMigrations(logFn, handle);
const filled = await migrationsFn();
- await runMigrations(handle);
+ await runMigrations(logFn, handle);
const unchanged = await migrationsFn();
assert.deepEqual(filled, unchanged);
+
+ const migrationLogs = fs
+ .readdirSync(MIGRATIONS_DIR)
+ .sort((a, b) => a.localeCompare(b, "POSIX"))
+ .map(filename => ({ log: "exec-migration", filename }));
+ assert.deepEqual(contents, migrationLogs);
});
};
diff --git a/tests/js/db.mjs b/tests/js/db.mjs
index c6c5c85..c02c43e 100644
--- a/tests/js/db.mjs
+++ b/tests/js/db.mjs
@@ -92,9 +92,10 @@ const test_open = t => {
const test_init = t => {
t.start("init()");
t.test("we only know how to deal with 1 database", async () => {
- await init();
+ const logFn = () => {};
+ await init(logFn);
const ref1 = handle;
- await init();
+ await init(logFn);
const ref2 = handle;
assert.notDeepEqual(ref1, ref2);
diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs
index bc9d3d2..5507375 100644
--- a/tests/js/hero.mjs
+++ b/tests/js/hero.mjs
@@ -15,6 +15,7 @@ import {
extractQueryParams,
handleRequest,
makeRequestListener,
+ log,
interceptorsFn,
interceptors,
defaultInterceptors,
@@ -562,7 +563,7 @@ const test_handleRequest = t => {
await handleRequest({}, "GET", "/"),
{
status: 404,
- body: "Not Found",
+ body: "Not Found\n",
},
);
});
@@ -631,6 +632,20 @@ const test_makeRequestListener = t => {
});
};
+const test_log = t => {
+ t.start("log()");
+
+ t.test("we can log data", () => {
+ log({ a: 1, type: "log-test" });
+ });
+
+ t.test("we can't log unserializable things", () => {
+ const obj = { self: null };
+ obj.self = obj;
+ assert.throws(() => log(obj), TypeError);
+ });
+};
+
const test_interceptorsFn = t => {
const next = x => x;
@@ -800,7 +815,7 @@ const test_interceptorsFn = t => {
await interceptorsFn({ logger }).serverError({ id: 123 }, next),
{
status: 500,
- body: "Internal Server Error",
+ body: "Internal Server Error\n",
},
);
assert.deepEqual(
@@ -823,7 +838,7 @@ const test_interceptorsFn = t => {
),
{
status: 500,
- body: "Internal Server Error",
+ body: "Internal Server Error\n",
},
);
assert.deepEqual(
@@ -1158,7 +1173,7 @@ const test_buildServer = t => {
const response = await socketRequest(socketPath, "/anything");
await server.close();
- assert.deepEqual(response, { status: 404, body: "Not Found" });
+ assert.deepEqual(response, { status: 404, body: "Not Found\n" });
});
t.test("integrated application server", async () => {
@@ -1188,6 +1203,7 @@ await runner.runTests([
test_extractQueryParams,
test_handleRequest,
test_makeRequestListener,
+ test_log,
test_interceptorsFn,
test_chainInterceptors,
test_wrapHandler,
diff --git a/tests/js/utils.mjs b/tests/js/utils.mjs
index e2475b0..5a1507c 100644
--- a/tests/js/utils.mjs
+++ b/tests/js/utils.mjs
@@ -8,7 +8,6 @@ import {
assocIn,
getIn,
first,
- log,
promisify,
} from "../../src/utils.mjs";
@@ -245,20 +244,6 @@ const test_first = t => {
});
};
-const test_log = t => {
- t.start("log()");
-
- t.test("we can log data", () => {
- log({ a: 1, type: "log-test" });
- });
-
- t.test("we can't log unserializable things", () => {
- const obj = { self: null };
- obj.self = obj;
- assert.throws(() => log(obj), TypeError);
- });
-};
-
const test_promisify = t => {
t.start("promisify()");
@@ -298,6 +283,5 @@ await runner.runTests([
test_assocIn,
test_getIn,
test_first,
- test_log,
test_promisify,
]);