diff --git a/lib/hexo/load_plugins.ts b/lib/hexo/load_plugins.ts index b4b7b62c44..7f8bf1df3a 100644 --- a/lib/hexo/load_plugins.ts +++ b/lib/hexo/load_plugins.ts @@ -4,7 +4,7 @@ import Promise from 'bluebird'; import { magenta } from 'picocolors'; import type Hexo from './index'; -export = (ctx: Hexo): Promise => { +export default function loadPlugins(ctx: Hexo): Promise { if (!ctx.env.init || ctx.env.safe) return; return loadModules(ctx).then(() => loadScripts(ctx)); @@ -77,6 +77,7 @@ function loadScripts(ctx: Hexo): Promise { })); } -function displayPath(path: string, baseDirLength: number): string { +//EXPORTING displayPath FUNCTION FOR TESTING +export function displayPath(path: string, baseDirLength: number): string { return magenta(path.substring(baseDirLength)); } diff --git a/test/scripts/hexo/displayPath.ts b/test/scripts/hexo/displayPath.ts new file mode 100644 index 0000000000..8d60f95183 --- /dev/null +++ b/test/scripts/hexo/displayPath.ts @@ -0,0 +1,37 @@ +//NEW UNIT TEST FOR displayPath FUNCTION +import { magenta } from 'picocolors'; +import chai from 'chai'; +import loadPlugins, { displayPath } from '../../../lib/hexo/load_plugins'; + +const should = chai.should(); + +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); + }); + }); +}); \ No newline at end of file