This PR adds comprehensive unit test coverage for design-system/src/utils/token-loader.ts, addressing the lack of automated testing for token loading operations.
The added tests ensure that regressions in token loading—such as missing files, malformed JSON, or merge collisions—are detected. The tests utilize jest.mock('fs') to maintain hermetic behavior, independent of the actual file system state.
- Created
design-system/src/__tests__/token-loader.test.ts. - Implemented tests for
loadTokens:- Valid JSON parsing.
- Error handling for missing files.
- Error handling for malformed JSON.
- Implemented tests for
getAllTokens:- Successful merging of all token files.
- Resilient handling of failed file loads (ensuring the function continues and logs a warning).
- Resilient handling of malformed JSON in a single file (ensuring the function continues and logs a warning).
- Ran
npm test -- --coveragewithin thedesign-system/directory. - Confirmed that all new tests pass.
- Verified test coverage requirements (>95%) are met for
token-loader.ts.
- Hermetic tests using
jest.mock - Coverage for valid and failure paths
- Console.warn verified in failure cases
- >95% test coverage achieved