diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/js/accretion.mjs | 4 | ||||
-rw-r--r-- | tests/js/db.mjs | 16 | ||||
-rw-r--r-- | tests/js/escape.mjs | 10 | ||||
-rw-r--r-- | tests/js/hero.mjs | 211 | ||||
-rw-r--r-- | tests/js/utils.mjs | 60 | ||||
-rw-r--r-- | tests/runner.mjs | 4 |
6 files changed, 153 insertions, 152 deletions
diff --git a/tests/js/accretion.mjs b/tests/js/accretion.mjs index 14c86d3..c6ec4b2 100644 --- a/tests/js/accretion.mjs +++ b/tests/js/accretion.mjs @@ -12,10 +12,10 @@ import { } from "../../src/accretion.mjs"; -const test_runMigrations = t => { +const test_runMigrations = async t => { t.start("runMigrations()"); - t.test("running twice is a noop", async () => { + await t.test("running twice is a noop", async () => { const contents = []; const logFn = x => contents.push(x); const handle = await db.open(":memory:"); diff --git a/tests/js/db.mjs b/tests/js/db.mjs index c02c43e..12b7405 100644 --- a/tests/js/db.mjs +++ b/tests/js/db.mjs @@ -11,12 +11,12 @@ import { } from "../../src/db.mjs"; -const test_promisifyDb = t => { +const test_promisifyDb = async t => { t.start("promisifyDb()"); const createTable = "CREATE TABLE table_ (column INTEGER NOT NULL PRIMARY KEY);"; - t.test("we can access the underlying database and statement ref", async () => { + await t.test("we can access the underlying database and statement ref", async () => { const db = await open(":memory:"); assert.ok(db.ref instanceof sqlite.Database); @@ -24,7 +24,7 @@ const test_promisifyDb = t => { assert.ok(stmt.ref instanceof sqlite.Statement); }); - t.test("we can run the wrapped fns", async () => { + await t.test("we can run the wrapped fns", async () => { const db = await open(":memory:"); await db.exec(createTable); @@ -53,10 +53,10 @@ const test_promisifyDb = t => { }); }; -const test_open = t => { +const test_open = async t => { t.start("open()"); - t.test("we must provide a name", () => { + await t.test("we must provide a name", () => { assert.rejects( async () => await open(), assert.AssertionError, @@ -78,7 +78,7 @@ const test_open = t => { ); }); - t.test("failure to open causes a promise rejection", () => { + await t.test("failure to open causes a promise rejection", () => { assert.rejects( async () => await open("tests/non/existing/directory/and/file"), { @@ -89,9 +89,9 @@ const test_open = t => { }); }; -const test_init = t => { +const test_init = async t => { t.start("init()"); - t.test("we only know how to deal with 1 database", async () => { + await t.test("we only know how to deal with 1 database", async () => { const logFn = () => {}; await init(logFn); const ref1 = handle; diff --git a/tests/js/escape.mjs b/tests/js/escape.mjs index 8291391..359348a 100644 --- a/tests/js/escape.mjs +++ b/tests/js/escape.mjs @@ -5,21 +5,21 @@ import { escape, } from "../../src/escape.mjs"; -const test_escape = t => { +const test_escape = async t => { t.start("escape()"); - t.test("numbers", () => { + await t.test("numbers", () => { assert.equal(escape(0), "0"); assert.equal(escape(42), "42"); assert.equal(escape(-1), "-1"); }); - t.test("object", () => { + await t.test("object", () => { assert.equal(escape({}), "[object Object]"); assert.equal(escape({ k: "v" }), "[object Object]"); }); - t.test("string with special chars", () => { + await t.test("string with special chars", () => { assert.strictEqual(escape(`"`), """); assert.strictEqual(escape(`"bar`), ""bar"); assert.strictEqual(escape(`foo"`), "foo""); @@ -51,7 +51,7 @@ const test_escape = t => { assert.strictEqual(escape("foo>>bar"), "foo>>bar"); }); - t.test("the combination of all special characters", () => { + await t.test("the combination of all special characters", () => { assert.strictEqual( escape(`foo, "bar", 'baz' & <quux>`), "foo, "bar", 'baz' & <quux>", diff --git a/tests/js/hero.mjs b/tests/js/hero.mjs index 23e4b7a..9c7aa6d 100644 --- a/tests/js/hero.mjs +++ b/tests/js/hero.mjs @@ -34,14 +34,14 @@ import { } from "../../src/hero.mjs"; -const test_normalizeSegments = t => { +const test_normalizeSegments = async t => { t.start("normalizeSegments()"); - t.test("unchanged when already normalized", () => { + await t.test("unchanged when already normalized", () => { assert.deepEqual(normalizeSegments([""]), [""]); }); - t.test("empty terminator added when missing", () => { + await t.test("empty terminator added when missing", () => { assert.deepEqual(normalizeSegments([]), [""]); assert.deepEqual(normalizeSegments([" "]), [" ", ""]); assert.deepEqual(normalizeSegments(["_"]), ["_", ""]); @@ -51,10 +51,10 @@ const test_normalizeSegments = t => { }); }; -const test_pathToSegments = t => { +const test_pathToSegments = async t => { t.start("pathToSegments()"); - t.test("simple paths", () => { + await t.test("simple paths", () => { assert.deepEqual(pathToSegments("/"), [ "" ]); assert.deepEqual(pathToSegments("/simple"), ["simple", ""]); assert.deepEqual(pathToSegments("/simple/route"), ["simple", "route", ""]); @@ -63,23 +63,23 @@ const test_pathToSegments = t => { assert.deepEqual(pathToSegments("/api/user/:id/info"), ["api", "user", ":id", "info", ""]); }); - t.test("extra separators", () => { + await t.test("extra separators", () => { assert.deepEqual(pathToSegments("/api/health/"), ["api", "health", ""]); assert.deepEqual(pathToSegments("/api///health"), ["api", "health", ""]); assert.deepEqual(pathToSegments("//api///health//"), ["api", "health", ""]); }); }; -const test_hasPathParams = t => { +const test_hasPathParams = async t => { t.start("hasPathParam()"); - t.test("has it", () => { + await t.test("has it", () => { assert(hasPathParams(["some", ":path", ""])); assert(hasPathParams(["path", ":params", ""])); assert(hasPathParams(["api", "user", ":id", "info", ""])); }); - t.test("doesn't have it", () => { + await t.test("doesn't have it", () => { assert(!hasPathParams([])); assert(!hasPathParams([ "" ])); assert(!hasPathParams(["some", "path", ""])); @@ -88,12 +88,12 @@ const test_hasPathParams = t => { }); }; -const test_addRoute = t => { +const test_addRoute = async t => { t.start("addRoute()"); const fn1 = () => {}; - t.test("daily usage examples", () => { + await t.test("daily usage examples", () => { assert.deepEqual( addRoute({}, "GET", "/home", fn1), { static: { GET: { home: { "": fn1 }}}}, @@ -146,18 +146,18 @@ const test_addRoute = t => { ); }); - t.test("bad method", () => { + await t.test("bad method", () => { assert.throws( () => addRoute({}, "VERB", "/path", fn1), assert.AssertionError, ); }); - t.test("empty methods array", () => { + await t.test("empty methods array", () => { assert.deepEqual(addRoute({}, [], "", fn1), {}); }); - t.test("subpaths", () => { + await t.test("subpaths", () => { const fn1 = () => {}; const fn2 = () => {}; @@ -181,10 +181,10 @@ const test_addRoute = t => { }); }; -const test_findStaticHandler = t => { +const test_findStaticHandler = async t => { t.start("findStaticHandler()"); - t.test("multiple accesses to the same table", () => { + await t.test("multiple accesses to the same table", () => { const fn1 = () => {}; const fn2 = () => {}; const fn3 = () => {}; @@ -239,14 +239,14 @@ const test_findStaticHandler = t => { }); }; -const test_firstParamMatch = t => { +const test_firstParamMatch = async t => { t.start("firstParamMatch()"); const params = {}; const fn1 = () => {}; const fn2 = () => {}; - t.test("we BACKTRACK when searching down routes", () => { + await t.test("we BACKTRACK when searching down routes", () => { const segments = [ "path", "split", "match", "" ]; const tree = { @@ -270,7 +270,7 @@ const test_firstParamMatch = t => { ); }); - t.test("ambiguous route prefers params at the end", () => { + await t.test("ambiguous route prefers params at the end", () => { const segments = [ "path", "param1", "param2", "" ]; const tree1 = { @@ -296,7 +296,7 @@ const test_firstParamMatch = t => { ); }); - t.test("when 2 params are possible, we pick the first alphabetically", () => { + await t.test("when 2 params are possible, we pick the first alphabetically", () => { const segments = [ "user", "someId", "" ]; const tree1 = { @@ -320,7 +320,7 @@ const test_firstParamMatch = t => { ); }); - t.test(`we deal with segments that start with ":"`, () => { + await t.test(`we deal with segments that start with ":"`, () => { const segments = [ "path", ":param", "" ]; const tree = { path: { @@ -337,10 +337,10 @@ const test_firstParamMatch = t => { }); }; -const test_findDynamicHandler = t => { +const test_findDynamicHandler = async t => { t.start("findDynamicHandler()"); - t.test("daily usage cases", () => { + await t.test("daily usage cases", () => { const fn1 = () => {}; const fn2 = () => {}; @@ -385,10 +385,10 @@ const test_findDynamicHandler = t => { }); }; -const test_findHandler = t => { +const test_findHandler = async t => { t.start("findHandler()"); - t.test("mix of static and dynamic routes", () => { + await t.test("mix of static and dynamic routes", () => { const static1 = () => {}; const static2 = () => {}; const static3 = () => {}; @@ -478,16 +478,16 @@ const test_findHandler = t => { }); }; -const test_extractQueryParams = t => { +const test_extractQueryParams = async t => { t.start("extractQueryParams()"); - t.test("empty values", () => { + await t.test("empty values", () => { assert.deepEqual(extractQueryParams(), {}); assert.deepEqual(extractQueryParams(null), {}); assert.deepEqual(extractQueryParams(undefined), {}); }); - t.test("we get a flat key-value strings", () => { + await t.test("we get a flat key-value strings", () => { assert.deepEqual( extractQueryParams("a[]=1&b=text&c=___"), { @@ -498,18 +498,18 @@ const test_extractQueryParams = t => { ); }); - t.test("duplicate values are suppressed, deterministically", () => { + await t.test("duplicate values are suppressed, deterministically", () => { assert.deepEqual(extractQueryParams("a=1&a=2&a=3"), { a: "3" }); assert.deepEqual(extractQueryParams("a=1&b=2&a=3"), { a: "3", b: "2" }); }); }; -const test_handleRequest = t => { +const test_handleRequest = async t => { t.start("handleRequest()"); const fn = req => req; - t.test("request without params", async () => { + await t.test("request without params", async () => { const table = { static: { GET: { @@ -534,7 +534,7 @@ const test_handleRequest = t => { ); }); - t.test("request with params", async () => { + await t.test("request with params", async () => { const table = { dynamic: { PUT: { @@ -565,7 +565,7 @@ const test_handleRequest = t => { ); }); - t.test("missing route", async () => { + await t.test("missing route", async () => { assert.deepEqual( await handleRequest({}, "GET", "/"), { @@ -576,10 +576,10 @@ const test_handleRequest = t => { }); }; -const test_makeRequestListener = t => { +const test_makeRequestListener = async t => { t.start("makeRequestListener()"); - t.test("straightforward body execution", async () => { + await t.test("straightforward body execution", async () => { const fn = _ => ({ status: "test status", body: "test body", @@ -613,7 +613,7 @@ const test_makeRequestListener = t => { ); }); - t.test("we break if handleRequest() throws an error", async () => { + await t.test("we break if handleRequest() throws an error", async () => { const fn = _ => { throw new Error("handler error"); }; const routes = [[ "GET", "/route2", fn ]]; const requestListener = makeRequestListener(buildRoutes(routes)); @@ -639,14 +639,14 @@ const test_makeRequestListener = t => { }); }; -const test_configLogger = t => { +const test_configLogger = async t => { t.start("configLogger()"); - t.test("globals starts empty", () => { + await t.test("globals starts empty", () => { assert.deepEqual(loggerGlobals, {}); }); - t.test("is gets becomes we assign it", () => { + await t.test("is gets becomes we assign it", () => { const globals = { app: "my-app", color: "green", @@ -656,13 +656,13 @@ const test_configLogger = t => { assert.deepEqual(loggerGlobals, globals); }); - t.test("we can reset it", () => { + await t.test("we can reset it", () => { configLogger({}); assert.deepEqual(loggerGlobals, {}); }); }; -const test_logit = t => { +const test_logit = async t => { t.start("logit()"); t.test("we can log data", () => { @@ -683,7 +683,7 @@ const test_logit = t => { configLogger({}); }); - t.test("the object can change previous fallback values", () => { + await t.test("the object can change previous fallback values", () => { const contents = []; const writerFn = x => contents.push(x); @@ -691,7 +691,7 @@ const test_logit = t => { level: "unseen", a: "unseen", }); - logit(writerFn, "overwritten by level", { a: "overwritten by o" }) + logit(writerFn, "overwritten by level", { a: "overwritten by o" }); configLogger({ pid: "overwritten by loggerGlobals", @@ -717,17 +717,17 @@ const test_logit = t => { }); - t.test("we can't log unserializable things", () => { + await t.test("we can't log unserializable things", () => { const obj = { self: null }; obj.self = obj; assert.throws(() => logit(obj), TypeError); }); }; -const test_makeLogger = t => { +const test_makeLogger = async t => { t.start("makeLogger()"); - t.test("various log levels", () => { + await t.test("various log levels", () => { const contents = []; const writerFn = x => contents.push(x); const log = makeLogger(writerFn); @@ -754,7 +754,7 @@ const test_makeLogger = t => { ]); }); - t.test("debug only works when $DEBUG is set", () => { + await t.test("debug only works when $DEBUG is set", () => { const contents = []; const writerFn = x => contents.push(x); const log = makeLogger(writerFn); @@ -774,7 +774,7 @@ const test_makeLogger = t => { }); }; -const test_interceptorsFn = t => { +const test_interceptorsFn = async t => { const next = x => x; { @@ -783,7 +783,7 @@ const test_interceptorsFn = t => { let i = 0; const uuidFn = () => `${i++}`; - t.test("we add an id to whatever we receive", () => { + await t.test("we add an id to whatever we receive", () => { assert.deepEqual( interceptorsFn({uuidFn}).requestId({}, next), { @@ -799,7 +799,7 @@ const test_interceptorsFn = t => { ); }); - t.test(`we overwrite the "id" if it already exists`, async () => { + await t.test(`we overwrite the "id" if it already exists`, async () => { assert.deepEqual( interceptorsFn({uuidFn}).requestId({ id: "before" }, next), { @@ -807,12 +807,12 @@ const test_interceptorsFn = t => { }, ); }); - } + }; { t.start("interceptorsFn().logged()"); - t.test("we log before and after next()", async () => { + await t.test("we log before and after next()", async () => { const contents = []; const logger = { info: x => contents.push(x) }; const status = 201; @@ -834,12 +834,12 @@ const test_interceptorsFn = t => { ], ); }); - } + }; { t.start("interceptorsFn().contentType()"); - t.test("empty values", async () => { + await t.test("empty values", async () => { assert.deepEqual( await interceptorsFn().contentType({}, next), { @@ -863,7 +863,7 @@ const test_interceptorsFn = t => { ); }); - t.test("body values", async () => { + await t.test("body values", async () => { assert.deepEqual( await interceptorsFn().contentType({ body: { a: 1 }}, next), { @@ -887,7 +887,7 @@ const test_interceptorsFn = t => { ); }); - t.test("header values preference", async () => { + await t.test("header values preference", async () => { assert.deepEqual( await interceptorsFn().contentType({ body: "", @@ -902,11 +902,11 @@ const test_interceptorsFn = t => { "Content-Type": "we have preference", "Content-Length": "and so do we", }, - } + }, ); }); - t.test("headers get propagated", async () => { + await t.test("headers get propagated", async () => { assert.deepEqual( await interceptorsFn().contentType({ body: "", @@ -924,19 +924,19 @@ const test_interceptorsFn = t => { }, ); }); - } + }; { t.start("interceptorsFn().serverError()"); - t.test("no-op when no error occurs", async () => { + await t.test("no-op when no error occurs", async () => { assert.deepEqual( await interceptorsFn().serverError({ status: 1 }, next), { status: 1 }, ); }); - t.test(`an error is thrown if "status" is missing`, async () => { + await t.test(`an error is thrown if "status" is missing`, async () => { const contents = []; const logger = { error: x => contents.push(x) }; assert.deepEqual( @@ -956,7 +956,7 @@ const test_interceptorsFn = t => { ); }); - t.test("we turn a handler error into a 500 response", async () => { + await t.test("we turn a handler error into a 500 response", async () => { const contents = []; const logger = { error: x => contents.push(x) }; assert.deepEqual( @@ -978,17 +978,17 @@ const test_interceptorsFn = t => { }], ); }); - } + }; }; -const test_chainInterceptors = t => { +const test_chainInterceptors = async t => { t.start("chainInterceptors()"); - t.test("empty values", () => { + await t.test("empty values", () => { assert.equal(chainInterceptors([])("req"), "req"); }); - t.test("the order of interceptors matter", () => { + await t.test("the order of interceptors matter", () => { const a = []; const i1 = (req, next) => { @@ -1006,7 +1006,7 @@ const test_chainInterceptors = t => { assert.deepEqual(a, ["i1", "i2", "i2", "i1"]); }); - t.test("with ordering, interceptors implicitly depend on each other", () => { + await t.test("with ordering, interceptors implicitly depend on each other", () => { const i1 = (req, next) => next({ ...req, id: 1 }); const i2 = (req, next) => next({ ...req, id: req.id + 1 }); @@ -1026,7 +1026,7 @@ const test_chainInterceptors = t => { ); }); - t.test("we can chain async interceptors", async () => { + await t.test("we can chain async interceptors", async () => { const i1 = async (req, next) => await next({ ...req, i1: true }); const i2 = async (req, next) => await next({ ...req, i2: true }); @@ -1040,10 +1040,10 @@ const test_chainInterceptors = t => { }); }; -const test_wrapHandler = t => { +const test_wrapHandler = async t => { t.start("wrapHandler()"); - t.test("noop when arr is empty", () => { + await t.test("noop when arr is empty", () => { const fn = () => {}; const wrappedFn1 = wrapHandler(fn, []); assert.deepEqual(fn, wrappedFn1); @@ -1052,7 +1052,7 @@ const test_wrapHandler = t => { assert.notDeepEqual(fn, wrappedFn2); }); - t.test("a handler with chained interceptors change its behaviour", async () => { + await t.test("a handler with chained interceptors change its behaviour", async () => { let i = 0; const uuidFn = () => `${i++}`; @@ -1109,11 +1109,11 @@ const test_wrapHandler = t => { }); }; -const test_actionsFn = t => { +const test_actionsFn = async t => { { t.start(`actionsFn()["toggle-debug-env"()]`); - t.test("we can toggle back and forth", () => { + await t.test("we can toggle back and forth", () => { const contents = []; const logger = { info: x => contents.push(x) }; const actions = actionsFn({logger}); @@ -1141,12 +1141,12 @@ const test_actionsFn = t => { }, ]); }); - } + }; { t.start(`actionsFn()["config-dump"]()`); - t.test("we just dump data as a log entry", () => { + await t.test("we just dump data as a log entry", () => { const contents = []; const logger = { info: x => contents.push(x) }; const actions = actionsFn({logger}); @@ -1180,13 +1180,13 @@ const test_actionsFn = t => { ]); }); - } + }; }; -const test_lineHandlerFn = t => { +const test_lineHandlerFn = async t => { t.start("lineHandlerFn()"); - t.test("empty values", () => { + await t.test("empty values", () => { const contents = []; const logger = { info: x => contents.push(x) }; const lineHandler = lineHandlerFn({logger, actionsMap: {}}); @@ -1202,7 +1202,7 @@ const test_lineHandlerFn = t => { ]); }); - t.test("calling an action", () => { + await t.test("calling an action", () => { const contents = []; const logger = { info: x => contents.push(x) }; const lineHandler = lineHandlerFn({ logger: null, actionsMap: { @@ -1219,11 +1219,11 @@ const test_lineHandlerFn = t => { const test_buildRoutes = t => { t.start("buildRoutes()"); - t.test("empty values", () => { + await t.test("empty values", () => { assert.deepEqual(buildRoutes([]), {}); }); - t.test("overwrites", () => { + await t.test("overwrites", () => { const fn1 = () => {}; const fn2 = () => {}; @@ -1263,7 +1263,7 @@ const test_buildRoutes = t => { ); }); - t.test("wrapped handler functions", async () => { + await t.test("wrapped handler functions", async () => { const handler = req => ({ ...req, handled: true }); const interceptor = (req, next) => next({ ...req, intercepted: true }); @@ -1281,7 +1281,7 @@ const test_buildRoutes = t => { { handled, intercepted }, { handled: true, intercepted: undefined }, ); - } + }; { const { handled, intercepted } = await handleRequest(table, "GET", "/with"); @@ -1289,10 +1289,10 @@ const test_buildRoutes = t => { { handled, intercepted }, { handled: true, intercepted: true }, ); - } + }; }); - t.test("interceptors are combined", async () => { + await t.test("interceptors are combined", async () => { const handler = req => ({ ...req, handled: true }); const interceptor1 = (req, next) => next({ ...req, interceptor1: true }); const interceptor2 = (req, next) => next({ ...req, interceptor2: true }); @@ -1311,7 +1311,7 @@ const test_buildRoutes = t => { { handled, interceptor1, interceptor2 }, { handled: true, interceptor1: true, interceptor2: undefined }, ); - } + }; { const { handled, interceptor1, interceptor2 } = await handleRequest(table, "GET", "/global-and-local"); @@ -1319,10 +1319,10 @@ const test_buildRoutes = t => { { handled, interceptor1, interceptor2 }, { handled: true, interceptor1: true, interceptor2: true }, ); - } + }; }); - t.test("multiple routes built", () => { + await t.test("multiple routes built", () => { const fn1 = () => {}; const fn2 = () => {}; const fn3 = () => {}; @@ -1361,25 +1361,25 @@ const test_buildRoutes = t => { user: { ":id": { "": fn5, - } - } - } + }, + }, + }, }, }, ); }); }; -const test_promisifyServer = t => { +const test_promisifyServer = async t => { t.start("promisifyServer()"); - t.test("we can access the underlying server ref", () => { + await t.test("we can access the underlying server ref", () => { const server = promisifyServer("app-name", http.createServer(() => {})); assert.ok(server.ref instanceof http.Server); }); }; -const test_buildServer = t => { +const test_buildServer = async t => { t.start("buildServer()"); const socketRequest = (socketPath, path) => @@ -1400,28 +1400,29 @@ const test_buildServer = t => { request.end(); }); - t.test("empty values", async () => { - const socketPath = "./tests/hero-0.sock"; + await t.test("empty values", async () => { + const socket = "tests/hero-4.socket"; + const pipe = "tests/hero-4.pipe"; const server = buildServer("my app", []); - - await server.listen(socketPath); - const response = await socketRequest(socketPath, "/anything"); + await server.listen(socket, pipe); + const response = await socketRequest(socket, "/anything"); await server.close(); assert.deepEqual(response, { status: 404, body: "Not Found\n" }); }); - t.test("integrated application server", async () => { - const socketPath = "./tests/hero-1.sock"; - const pathHandler = req => ({ status: 200, body: "OK" }); + await t.test("integrated application server", async () => { + const socket = "tests/hero-5.socket"; + const pipe = "tests/hero-5.pipe"; + const pathHandler = req => ({ status: 200, body: "something" }); const routes = [ [ "GET", "/path", pathHandler ] ]; const server = buildServer("the-app", routes, defaultInterceptors); - await server.listen(socketPath); - const response = await socketRequest(socketPath, "/path"); + await server.listen(socket, pipe); + const response = await socketRequest(socket, "/path"); await server.close(); - assert.deepEqual(response, { status: 200, body: "OK" }); + assert.deepEqual(response, { status: 200, body: "something" }); }); }; diff --git a/tests/js/utils.mjs b/tests/js/utils.mjs index ea5f4eb..425a09f 100644 --- a/tests/js/utils.mjs +++ b/tests/js/utils.mjs @@ -13,16 +13,16 @@ import { } from "../../src/utils.mjs"; -const test_keys = t => { +const test_keys = async t => { t.start("keys()"); - t.test("happy paths", () => { + await t.test("happy paths", () => { assert.deepEqual( { a: 1, b: 2 }, keys(["a", "b"], { a: 1, b: 2, c: 3 }), ); }); - t.test("stress scenarios", () => { + await t.test("stress scenarios", () => { assert.deepEqual( {}, keys([], {}), @@ -49,10 +49,10 @@ const test_keys = t => { }); }; -const test_difference = t => { +const test_difference = async t => { t.start("difference()"); - t.test("empty values", () => { + await t.test("empty values", () => { assert.deepEqual( difference(new Set(), new Set()), new Set(), @@ -69,7 +69,7 @@ const test_difference = t => { ); }); - t.test("different subsets", () => { + await t.test("different subsets", () => { assert.deepEqual( difference(new Set([1, 2]), new Set([3, 4])), new Set([1, 2]), @@ -92,22 +92,22 @@ const test_difference = t => { }); }; -const test_assocIn = t => { +const test_assocIn = async t => { t.start("assocIn()"); - t.test("empty values", () => { + await t.test("empty values", () => { assert.deepEqual(assocIn({}, [], null), {}); assert.deepEqual(assocIn({ k: "v" }, [], null), { k: "v" }); }); - t.test("adding values", () => { + await t.test("adding values", () => { assert.deepEqual(assocIn({}, ["k"], "v"), { k: "v" }); assert.deepEqual(assocIn({}, ["k1", "k2"], "v"), { k1: { k2: "v" }}); assert.deepEqual(assocIn({}, ["k1", "k2", "k3"], "v"), { k1: { k2: { k3: "v" }}}); assert.deepEqual(assocIn({ k: "v" }, ["k1", "k2"], "v"), { k: "v", k1: { k2: "v" }}); }); - t.test("replacing values", () => { + await t.test("replacing values", () => { assert.deepEqual( assocIn( { k1: { k2: { k3: "before" }}}, @@ -119,34 +119,34 @@ const test_assocIn = t => { }); }; -const test_getIn = t => { +const test_getIn = async t => { t.start("getIn()"); - t.test("empty values", () => { + await t.test("empty values", () => { assert.deepEqual(getIn({}, []), {}); assert.deepEqual(getIn({ k: "v" }, []), { k: "v" }); }); - t.test("missing values", () => { + await t.test("missing values", () => { assert.deepEqual(getIn({}, ["a", "b", "c"]), undefined); assert.deepEqual(getIn({ a: {}}, ["a", "b", "c"]), undefined); assert.deepEqual(getIn({ a: { b: {}}}, ["a", "b", "c"]), undefined); assert.deepEqual(getIn({ a: { b: {}, c: {}}}, ["a", "b", "c"]), undefined); }); - t.test("nested valeues", () => { + await t.test("nested valeues", () => { assert.deepEqual(getIn({ a: { b: { c: { d: "e" }}}}, ["a", "b", "c", "d"]), "e"); }); }; -const test_findFirst = t => { +const test_findFirst = async t => { t.start("findFirst()"); - t.test("empty values", () => { + await t.test("empty values", () => { assert.equal(findFirst([], () => {}), null); }); - t.test("when function doesn't transform, it behaves similarly to [].find()", () => { + await t.test("when function doesn't transform, it behaves similarly to [].find()", () => { const arr1 = [ 0, null, undefined, "", 1, 2 ]; assert.equal(findFirst(arr1, x => x), 1); assert.equal(arr1.find(x => x), 1); @@ -156,7 +156,7 @@ const test_findFirst = t => { assert.equal(arr2.find(x => x), undefined); }); - t.test("when it does transform, we return the transformed value", () => { + await t.test("when it does transform, we return the transformed value", () => { const arr = [ 1, 3, 5, 6 ]; assert.equal( @@ -166,10 +166,10 @@ const test_findFirst = t => { }); }; -const test_partial = t => { +const test_partial = async t => { t.start("partial()"); - t.test("empty values", () => { + await t.test("empty values", () => { const adder = (a, b, c) => a + b + c; const adder1 = partial(adder); @@ -182,7 +182,7 @@ const test_partial = t => { assert.equal(partial(noargs)(), noargs()); }); - t.test("too few arguments", () => { + await t.test("too few arguments", () => { const threeArgs = (a, b, c) => { assert.notEqual(c, undefined); return a + b + c @@ -207,14 +207,14 @@ const test_partial = t => { ); }); - t.test("too many arguments", () => { + await t.test("too many arguments", () => { const twoArgs = (a, b) => a + b; assert.equal(partial(twoArgs, 1)(2, 3), 3); assert.equal(partial(twoArgs, 1, 2)(3), 3); }); - t.test("daily usage", () => { + await t.test("daily usage", () => { const twoArg = (a, b) => a + b; const numbers = [ 1, 2, 3, 4, 5 ]; @@ -224,7 +224,7 @@ const test_partial = t => { ); }); - t.test("nested partials", () => { + await t.test("nested partials", () => { const threeArgs = (a, b, c) => a + b + c; const add1 = partial(threeArgs, 1); @@ -234,14 +234,14 @@ const test_partial = t => { }); }; -const test_strSortFn = t => { +const test_strSortFn = async t => { t.start("strSortFn()"); - t.test("empty value", () => { + await t.test("empty value", () => { assert.equal(strSortFn("", ""), 0); }); - t.test("default sort", () => { + await t.test("default sort", () => { const arr = [ "a", "Z" ]; assert.deepEqual( [...arr].sort(strSortFn), @@ -250,15 +250,15 @@ const test_strSortFn = t => { }); }; -const test_undefinedAsNull = t => { +const test_undefinedAsNull = async t => { t.start("undefinedAsNull()"); - t.test("null for undefined or null", () => { + await t.test("null for undefined or null", () => { assert.equal(undefinedAsNull(undefined), null); assert.equal(undefinedAsNull(null), null); }); - t.test("identity otherwise", () => { + await t.test("identity otherwise", () => { const expected = [ " ", "", 0, 1, -1.1, true, false, [], [ "" ], {}, { k: "v" }, diff --git a/tests/runner.mjs b/tests/runner.mjs index fd5d167..c17c0d0 100644 --- a/tests/runner.mjs +++ b/tests/runner.mjs @@ -12,10 +12,10 @@ const t = { start: msg => { console.error(`${msg}:`); }, - test: (msg, fn) => { + test: async (msg, fn) => { process.stderr.write(`${yellow("testing")}: ${msg}... `); try { - fn(); + await fn(); } catch (e) { process.stderr.write(`${red("FAIL\n")}`); throw e; |