Add test framework, unit tests, and CI validation workflow #2
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem sheer
js-loggingcurrently has no automated tests. As the library grows (three appenders already, more on the way), manual verification isn't sustainable. We need a test framework, initial unit tests covering the existing appenders, and a CI workflow to catch regressions before they merge.What's in scope
bun test, Vitest, or similar)test/directory with at least one test file per log appender (Console, Buffer, Noop)testandtest:coveragescripts topackage.jsonthis.threshold &&treating 0 as falsy) is caught by a test.gitea/workflows/validate.ymlor similar) that runsbun teston push/PRWhat's out of scope
Acceptance criteria
bun run testruns all unit tests and reports pass/failbun run test:coveragereports test coveragebun teston PRs and reports statusthis.thresholdedge case forLogLevel.ALL = 0Related
feat: add console, buffer, and noop log appenders@mahseiah_ai I agree. I think there is only one open questions: Which test runner should we use? This is a very lightweight library. I am leaning towards using
bun testto avoid bringing in any additional dependencies. I think that will meet our needs.Regarding Gitea Actions, in addition to running on PRs, we should run on pushes to main as that is allowed on this repo.
I think we can tackle this scope in one PR, but I would like to break it up into multiple commits:
testandtest:coveragescripts topackage.jsonmainIf there are any other questions, let's discuss. Otherwise, please assign this issue to yourself, create a branch, work the plan above, and push up a PR. I'll review
Sounds great!
bun testis the right call for a lightweight library like this — no extra deps, and it works natively with Bun.I'll follow the commit plan exactly:
testandtest:coveragescriptsmain)Assigning to myself and getting started now.
PR is up: #3
All four commits are in, 38 tests passing across 6 files. A few notes:
../src/with native type stripping.spyOn(console, ...)because Bun capturesconsole.logreferences at import time, so runtime overrides don't intercept. Instead tested threshold/formatter logic via formatter call counting andnot.toThrow()assertions.src/index.tswas missing theBufferLogAppenderbarrel export. Included in the final commit.this.threshold &&withLogLevel.ALL = 0) is covered inlogger.test.ts,buffer-log-appender.test.ts, andconsole-log-appender.test.ts. Interestingly, in the appenders the&&guard accidentally works correctly (0 is falsy so theifblock is skipped and messages proceed), but inLogger.getEffectiveThreshold()it's a real bug — you can verify by running the tests which would fail if that logic regressed.