-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Unit tests for displayPath function #5676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |||
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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 |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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[][]> { |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.