summaryrefslogtreecommitdiff
path: root/tests/js/hero.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/js/hero.mjs')
-rw-r--r--tests/js/hero.mjs49
1 files changed, 28 insertions, 21 deletions
diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs
index 4537197..3bed524 100644
--- a/tests/js/hero.mjs
+++ b/tests/js/hero.mjs
@@ -671,7 +671,7 @@ const test_configLogger = async t => {
const test_logit = async t => {
t.start("logit()");
- t.test("we can log data", () => {
+ await t.test("we can log data", () => {
configLogger({ app: "hero-based app" });
const contents = [];
const writerFn = x => contents.push(x);
@@ -685,7 +685,7 @@ const test_logit = async t => {
type: "log-test",
}]);
- // reset the logger out of the values specific to this test
+ /// reset the logger out of the values specific to this test
configLogger({});
});
@@ -704,7 +704,7 @@ const test_logit = async t => {
});
logit(writerFn, "unseen", { level: "overwritten by o" });
- // reset the logger out of the values specific to this test
+ /// reset the logger out of the values specific to this test
configLogger({});
assert.deepEqual(contents.map(JSON.parse), [
@@ -772,7 +772,7 @@ const test_makeLogger = async t => {
process.env.DEBUG = "1";
log.debug({ x: "seen" });
delete process.env.DEBUG;
- // call the function that toggles
+ /// call the function that toggles
log.debug({ x: "ignored" });
assert.deepEqual(contents.map(JSON.parse), [{
@@ -1284,7 +1284,7 @@ const test_mkfifo = async t => {
});
await t.test("error when path already exists", async () => {
- const path = "tests/hero-0.pipe"
+ const path = "tests/hero-mkfifo-0.pipe"
fs.writeFileSync(path, " ", { flush: true });
@@ -1298,7 +1298,7 @@ const test_mkfifo = async t => {
});
await t.test("new pipe file", async () => {
- const path = "tests/hero-1.pipe"
+ const path = "tests/hero-mkfifo-1.pipe"
rmIf(path);
assert.ok(!fs.existsSync(path));
@@ -1393,38 +1393,45 @@ const test_makePipeReaderFn = async t => {
t.start("makePipeReaderFn()");
await t.test("we can close it manually with no data", async () => {
- const path = "tests/hero-2.pipe";
+ const path = "tests/hero-makePipeReader-0.pipe";
const lines = [];
+ const logs = [];
const lineFn = x => lines.push(x);
- const makePipeReader = makePipeReaderFn({ lineFn: null });
+ const logger = { debug: x => logs.push(x) };
+ const makePipeReader = makePipeReaderFn({ lineFn, logger });
rmIf(path);
- makePipeReader(path);
- fs.createWriteStream(path).end();
+ await makePipeReader(path)();
assert.deepEqual(lines, []);
});
await t.test("closing on pipe EOF reopens", async () => {
- const path = "tests/hero-3.pipe";
+ const path = "tests/hero-makePipeReader-1.pipe";
const lines = [];
+ const logs = [];
const lineFn = x => lines.push(x);
- const makePipeReader = makePipeReaderFn({ lineFn });
+ const logger = { debug: x => logs.push(x) };
+ const makePipeReader = makePipeReaderFn({ lineFn, logger });
rmIf(path);
- makePipeReader(path);
+ const closeReader = makePipeReader(path);
const writer = fs.createWriteStream(path);
writer.end("first\nsecond\nthird\n");
- return new Promise((resolve, reject) => {
- writer.close(() => {
+ return new Promise((resolve, reject) =>
+ writer.close(async () => {
+ await closeReader();
assert.deepEqual(lines, [
"first",
"second",
"third",
]);
+ assert.deepEqual(logs, [
+ { message: "pipe closed, reopening" },
+ { message: "pipe closed, NOT reopening" },
+ ]);
resolve();
- });
- });
+ }));
});
};
@@ -1613,8 +1620,8 @@ const test_buildServer = async t => {
});
await t.test("empty values", async () => {
- const socket = "tests/hero-4.socket";
- const pipe = "tests/hero-4.pipe";
+ const socket = "tests/hero-buildServer-0.socket";
+ const pipe = "tests/hero-buildServer-0.pipe";
const name = "my-empty-app";
const server = buildServer({ name, socket, pipe });
await server.listen();
@@ -1625,8 +1632,8 @@ const test_buildServer = async t => {
});
await t.test("integrated application server", async () => {
- const socket = "tests/hero-5.socket";
- const pipe = "tests/hero-5.pipe";
+ const socket = "tests/hero-buildServer-1.socket";
+ const pipe = "tests/hero-buildServer-1.pipe";
const name = "the-app";
const pathHandler = req => ({ status: 200, body: "something" });
const routes = [ [ "GET", "/path", pathHandler ] ];