# Run all tests
npm test
# Run a specific test
node tests/singleton-reinit.test.jsThe test suite validates all critical functionality and bug fixes discovered during integration with the macOS setup script project.
singleton-reinit.test.js- Singleton reinitializationglobal-level.test.js- Global log level configurationcontext-data.test.js- Context data displayverbosity-modes.test.js- Log level filteringpino-wrapper.test.js- Pino argument transformationredaction.test.js- Sensitive data redaction
Test: singleton-reinit.test.js
When the module was imported, it called getInstanceSync() with no options, creating a singleton. Subsequent calls with options were ignored.
Fix: Modified getInstanceSync() to reinitialize when new options are provided.
Validation:
- ✅ First init uses default options
- ✅ Reinit with new options updates config
- ✅ Component loggers reflect new levels
Test: global-level.test.js
Two issues prevented globalLevel from working:
- Component-specific levels in default config overrode globalLevel
- Loggers weren't recreated on reinit, keeping old levels
Fix:
- Removed component-specific level from default config
- Fixed logger recreation in
initSync()to use_createLoggerOriginal
Validation:
- ✅ All components respect globalLevel
- ✅ Changing globalLevel updates all loggers
- ✅ Component overrides still work when specified
Test: context-data.test.js
Pino expects logger.info({context}, 'message') but intuitive usage is logger.info('message', {context}). Context data wasn't being passed to the formatter.
Fix: Created _wrapPinoLogger() to transform both argument orders.
Validation:
- ✅ Message-first syntax works
- ✅ Context-first syntax works
- ✅ Context displayed in tree format
- ✅ Nested objects handled correctly
- ✅ All log levels support context
Test: verbosity-modes.test.js
Log levels weren't properly filtering messages based on globalLevel setting.
Fix: Combination of fixes for singleton reinit and globalLevel application.
Validation:
- ✅
trace: Shows all logs - ✅
debug: Shows debug+ - ✅
info: Shows info+ (default) - ✅
warn: Shows warn+ - ✅
error: Shows error+
Test: pino-wrapper.test.js
Pino's native API signature differs from intuitive usage patterns.
Fix: _wrapPinoLogger() method handles both argument orders.
Validation:
- ✅ Both syntax orders work
- ✅ Message-only works
- ✅ Context-only works
- ✅ Multiple properties passed
- ✅ Nested objects preserved
Test: redaction.test.js
Configurable redaction of sensitive keys in logged objects to prevent accidental exposure of passwords, API keys, tokens, and other sensitive data.
Features:
- ✅ Exact match patterns (
password,token) - ✅ Wildcard suffix patterns (
*key,*secret) - ✅ Case-insensitive matching
- ✅ Recursive redaction through nested objects
- ✅ Array redaction support
- ✅ Custom censor text
- ✅ File-specific overrides
- ✅ Works across all formatters (browser, CLI, server)
Validation:
- ✅ Basic redaction with exact matches
- ✅ Wildcard patterns match correctly (
*keymatchesapiKey,googleApiKey, etc.) - ✅ Case-insensitive matching works
- ✅ Nested objects redacted recursively
- ✅ Arrays redacted correctly
- ✅ Custom censor text applied
- ✅ Empty paths array disables redaction
- ✅ Config manager returns correct structure
- ✅ Default config has correct structure
- Zero Dependencies: Uses Node.js built-in
assertmodule - Fast Execution: All tests complete in <10 seconds
- CI-Friendly: Clear exit codes and console output
- Isolated: Each test resets singleton for clean state
See tests/README.md for detailed guide on adding new tests.
# GitHub Actions example
- name: Run tests
run: npm testTests automatically run as part of the npm run check command before publishing.