Skip to content

Commit

Permalink
test(benchmark): optimize for local & render post support (#4428)
Browse files Browse the repository at this point in the history
* test(benchmark): speed up local benchmark
* test(benchmark): add hook for post rendering
  • Loading branch information
SukkaW authored Jul 23, 2020
1 parent 850ffbc commit 3a56d29
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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'),
Expand Down

0 comments on commit 3a56d29

Please sign in to comment.