Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/hexo/load_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Promise from 'bluebird';
import { magenta } from 'picocolors';
import type Hexo from './index';

export = (ctx: Hexo): Promise<void[][]> => {
export default function loadPlugins(ctx: Hexo): Promise<void[][]> {
Copy link

Copilot AI Jul 24, 2025

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.

Copilot uses AI. Check for mistakes.
if (!ctx.env.init || ctx.env.safe) return;

return loadModules(ctx).then(() => loadScripts(ctx));
Expand Down Expand Up @@ -77,6 +77,7 @@ function loadScripts(ctx: Hexo): Promise<void[][]> {
}));
}

function displayPath(path: string, baseDirLength: number): string {
//EXPORTING displayPath FUNCTION FOR TESTING
Copy link

Copilot AI Jul 24, 2025

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.

Suggested change
//EXPORTING displayPath FUNCTION FOR TESTING

Copilot uses AI. Check for mistakes.
export function displayPath(path: string, baseDirLength: number): string {
return magenta(path.substring(baseDirLength));
}
37 changes: 37 additions & 0 deletions test/scripts/hexo/displayPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//NEW UNIT TEST FOR displayPath FUNCTION
Copy link

Copilot AI Jul 24, 2025

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.

Suggested change
//NEW UNIT TEST FOR displayPath FUNCTION
// Unit tests for the displayPath function

Copilot uses AI. Check for mistakes.
import { magenta } from 'picocolors';
import chai from 'chai';
import loadPlugins, { displayPath } from '../../../lib/hexo/load_plugins';

const should = chai.should();
Copy link

Copilot AI Jul 24, 2025

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.

Suggested change
const should = chai.should();
// Removed unused `should` variable declaration.

Copilot uses AI. Check for mistakes.

describe('load_plugins', () => {
describe('displayPath', () => {
it('should return relative path with magenta formatting', () => {
const fullPath = '/home/user/project/scripts/test.js';
const baseDirLength = '/home/user/project/'.length;
const expected = magenta('scripts/test.js');

const result = displayPath(fullPath, baseDirLength);
result.should.equal(expected);
});

it('should handle Windows paths', () => {
const fullPath = 'C:\\project\\scripts\\test.js';
const baseDirLength = 'C:\\project\\'.length;
const expected = magenta('scripts\\test.js');

const result = displayPath(fullPath, baseDirLength);
result.should.equal(expected);
});

it('should handle paths at base directory level', () => {
const fullPath = '/project/config.js';
const baseDirLength = '/project/'.length;
const expected = magenta('config.js');

const result = displayPath(fullPath, baseDirLength);
result.should.equal(expected);
});
});
});