| title | Utility Module Test Suite | ||||
|---|---|---|---|---|---|
| description | Comprehensive Jest tests for labelling agent utility modules | ||||
| tags |
|
This directory contains comprehensive Jest unit tests for the utility modules used by the labelling agents.
These CommonJS modules have comprehensive unit test coverage:
-
build-label-alias-map.test.js (19 tests)
- Tests label alias mapping from labels.yml
- Edge cases: null entries, empty arrays, mixed formats
- YAML parsing and file reading validation
-
build-labeling-report.test.js (21 tests)
- Tests Markdown audit report generation
- Missing/extra label detection
- Markdown structure and formatting
-
fetch-canonical-labels.test.js (25 tests)
- Tests canonical label extraction from YAML
- Mixed string/object format handling
- Special character and emoji support
-
update-readme.test.js (8 tests)
- Tests shim file delegation pattern
- Backwards compatibility validation
- Shim architecture documentation
-
yaml-parser.test.js (9 tests)
- Tests module re-export shim pattern
- Path resolution validation
- Cross-platform compatibility
The following modules use ES module syntax (import/export) which is not compatible with the current Jest/Babel configuration:
- badges.js - ES module for badge generation
- header-footer.js - ES module for header/footer insertion
- en-gb-normalise.js - Self-executing script for UK English normalisation
The project uses:
"type": "module"in package.json for ES module support- Jest with Babel transformation for CommonJS tests
- Mixed module formats (CommonJS and ES modules)
Jest's current configuration transforms CommonJS modules but doesn't handle ES modules when they're imported via require(). The Babel transformation would need:
- Custom
transformIgnorePatternsto includescripts/directory - Babel preset configuration for ES module transformation
- Module resolution updates to handle
.jsextensions as ES modules
For ES modules, consider:
- Integration Tests: Test the complete workflow rather than individual functions
- Module Conversion: Convert ES modules to CommonJS for testing
- Native ES Module Support: Update Jest to use Node's native ES module support
- Dual Module Format: Maintain both CommonJS and ES module versions
For new utility modules:
- Use CommonJS (
require/module.exports) for testability - Reserve ES modules for application code where integration tests are more appropriate
- See badgeUtils.js as an example of a testable CommonJS utility
npm test -- scripts/agents/includes/__tests__/npm test -- scripts/agents/includes/__tests__/build-label-alias-map.test.jsnpm test -- --coverage scripts/agents/includes/__tests__/All tests follow this structure:
const module = require("../module-name");
// Mock dependencies
jest.mock("fs");
jest.mock("js-yaml");
describe("module-name.js", () => {
beforeEach(() => {
jest.clearAllMocks();
// Setup mocks
});
describe("functionName", () => {
it("should handle normal case", () => {
// Arrange
// Act
// Assert
});
it("should handle edge case", () => {
// Test edge cases
});
it("should handle error case", () => {
// Test error handling
});
});
});- ✅ Comprehensive coverage: Test all code paths
- ✅ Edge cases: null, undefined, empty arrays, invalid input
- ✅ Error handling: file not found, parse errors
- ✅ Real-world scenarios: actual data structures from production
- ✅ Isolated tests: Proper mocking of dependencies
- ✅ Clear descriptions: BDD-style test names
- ✅ Cleanup: beforeEach/afterEach hooks for test isolation
When adding new utility modules:
- Create corresponding test file in this directory
- Follow the existing test structure and naming conventions
- Aim for 100% code coverage
- Test edge cases and error conditions
- Document any known limitations
- Use CommonJS format for better testability
Need help? Say hi—work with us.