From 3a56d29e59598dd14c5b62efb3edd16b43944c5e Mon Sep 17 00:00:00 2001 From: Sukka Date: Thu, 23 Jul 2020 16:21:28 +0800 Subject: [PATCH] test(benchmark): optimize for local & render post support (#4428) * test(benchmark): speed up local benchmark * test(benchmark): add hook for post rendering --- test/benchmark.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/benchmark.js b/test/benchmark.js index 8ad9ac8020..6916e69a9a 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -10,6 +10,7 @@ const { red } = require('chalk'); const hooks = [ { regex: /Hexo version/, tag: 'hexo-begin' }, { regex: /Start processing/, tag: 'processing' }, + { regex: /Rendering post/, tag: 'render-post' }, { regex: /Files loaded/, tag: 'file-loaded' }, { regex: /generated in/, tag: 'generated' }, { regex: /Database saved/, tag: 'database-saved' } @@ -61,7 +62,8 @@ async function run_benchmark(name) { hexo.on('close', () => { performance.measure('Load Plugin/Scripts/Database', 'hexo-begin', 'processing'); - performance.measure('Process Source', 'processing', 'file-loaded'); + performance.measure('Process Source', 'processing', 'render-post'); + performance.measure('Render Posts', 'render-post', 'file-loaded'); performance.measure('Render Files', 'file-loaded', 'generated'); performance.measure('Save Database', 'generated', 'database-saved'); performance.measure('Total time', 'hexo-begin', 'database-saved'); @@ -83,16 +85,17 @@ async function gitClone(repo, dir, depth = 1) { async function init() { if (await exists(testDir)) { - log.info(`"${testDir}" already exists, deleting`); - await rmdir(testDir); + log.info(`"${testDir}" already exists. Skipping benchmark environment setup.`); + } else { + log.info('Setting up a dummy hexo site with 500 posts'); + await gitClone('https://github.com/hexojs/hexo-theme-unit-test.git', testDir); + await gitClone('https://github.com/hexojs/hexo-theme-landscape', resolve(testDir, 'themes', 'landscape')); + await gitClone('https://github.com/SukkaLab/hexo-many-posts.git', resolve(testDir, 'source', '_posts', 'hexo-many-posts')); } - log.info('Setting up a dummy hexo site with 500 posts'); - await gitClone('https://github.com/hexojs/hexo-theme-unit-test.git', testDir); - await gitClone('https://github.com/hexojs/hexo-theme-landscape', resolve(testDir, 'themes', 'landscape')); - await gitClone('https://github.com/SukkaLab/hexo-many-posts.git', resolve(testDir, 'source', '_posts', 'hexo-many-posts')); - log.info('Installing dependencies'); + // Always re-install dependencies + if (await exists(resolve(testDir, 'node_modules'))) await rmdir(resolve(testDir, 'node_modules')); await spawnAsync(npmScript, ['install', '--silent'], { cwd: testDir }); log.info('Replacing hexo'); @@ -104,6 +107,9 @@ async function init() { resolve(testDir, 'node_modules', 'hexo'), resolve(__dirname, '..') ]); + + await rmdir(resolve(testDir, 'node_modules', 'hexo-cli')); + await spawnAsync('cmd', [ '/s', '/c', 'mklink', '/D', resolve(testDir, 'node_modules', 'hexo-cli'),