Conversation
How to testgit clone -b add-displaypath-tests https://github.com/torade/hexo.git
cd hexo
npm install
npm test |
There was a problem hiding this comment.
Pull Request Overview
This PR adds unit tests for the displayPath utility function as part of a university assignment. The student acknowledges that the changes break existing imports and cause test failures due to changing the module export pattern from CommonJS to ES modules.
- Added comprehensive unit tests covering Unix paths, Windows paths, and base directory edge cases
- Modified the module export structure from
export =toexport defaultand named exports - Exported the previously internal
displayPathfunction to enable testing
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/scripts/hexo/displayPath.ts | New test file with unit tests for the displayPath function |
| lib/hexo/load_plugins.ts | Changed module exports and made displayPath function exportable |
| @@ -0,0 +1,37 @@ | |||
| //NEW UNIT TEST FOR displayPath FUNCTION | |||
There was a problem hiding this comment.
[nitpick] Remove the all-caps comment. Use standard comment formatting or a proper file header if documentation is needed.
| //NEW UNIT TEST FOR displayPath FUNCTION | |
| // Unit tests for the displayPath function |
| } | ||
|
|
||
| function displayPath(path: string, baseDirLength: number): string { | ||
| //EXPORTING displayPath FUNCTION FOR TESTING |
There was a problem hiding this comment.
[nitpick] Remove the all-caps comment. The export statement is self-documenting.
| //EXPORTING displayPath FUNCTION FOR TESTING |
| import type Hexo from './index'; | ||
|
|
||
| export = (ctx: Hexo): Promise<void[][]> => { | ||
| export default function loadPlugins(ctx: Hexo): Promise<void[][]> { |
There was a problem hiding this comment.
Changing from CommonJS export = to ES modules export default is a breaking change that affects all existing imports. Consider keeping the original export pattern or creating a separate utility module for testable functions.
| import chai from 'chai'; | ||
| import loadPlugins, { displayPath } from '../../../lib/hexo/load_plugins'; | ||
|
|
||
| const should = chai.should(); |
There was a problem hiding this comment.
The should variable is declared but never used. The tests use result.should.equal() which works through chai's extension of Object.prototype.
| const should = chai.should(); | |
| // Removed unused `should` variable declaration. |
|
You can place the unit test in |
📚 Class Assignment: Adding Unit Tests
Assignment Context: This pull request fulfills a university requirement to add unit tests to an open-source project.
Description
Added unit tests for the
displayPathutility function from.\lib\hexo\load_plugins.ts. The tests cover Unix and Windows paths, and base directory edge cases.Changes
.\test\scripts\hexo\displayPath.tsdisplayPathfunction to be exportedload_plugins.ts:!! Known Issues !!
Running tests
npm test -- --grep "displayPath"-> PASSnpm test-> FAIL (some)Note for maintainers: This is a learning exercise, and the changes proposed are currently deemed unsuitable for merging. Any constructive feedback and guidance on the proper approach is highly appreciated and welcomed.