Add --tracing to benchmarks

This commit is contained in:
Maximilian Stoiber
2018-07-05 15:35:42 +02:00
parent 81df325526
commit 904a7f6d48
3 changed files with 16 additions and 2 deletions

3
.gitignore vendored
View File

@@ -8,3 +8,6 @@ lib
sandbox/node_modules
*.log
test-results.json
mount-deep-tree-trace.json
mount-wide-tree-trace.json
update-dynamic-styles-trace.json

View File

@@ -9,5 +9,8 @@ lib
sandbox/node_modules
*.log
test-results.json
mount-deep-tree-trace.json
mount-wide-tree-trace.json
update-dynamic-styles-trace.json
benchmarks

View File

@@ -2,26 +2,34 @@ const path = require('path');
const puppeteer = require('puppeteer');
const tests = ['Mount deep tree', 'Mount wide tree', 'Update dynamic styles'];
const tracing = process.argv.some(arg => arg.indexOf('tracing') > -1);
if (tracing) {
console.log('\nTracing enabled. (note that this might impact benchmark results, we recommend leaving this turned off unless you need a trace)')
}
(async () => {
console.log('\nStarting headless browser...')
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.tracing.start({ path: 'benchmark-trace.json' });
console.log('Opening benchmark app...')
await page.goto(`file://${path.join(__dirname, './dist/index.html')}`);
console.log('Running benchmarks... (this may take a minute; do not use your machine while these are running!)')
console.log('Running benchmarks... (this may take a minute or two; do not use your machine while these are running!)')
for (var i = 0; i < tests.length; i++) {
const test = tests[i];
const traceFile = `${test.toLowerCase().replace(/\s/g, '-')}-trace.json`;
// styled-components is auto-selected, so all we gotta do is select the benchmark and press "Run"
await page.select('[data-testid="benchmark-picker"]', test);
await page.waitForSelector('[data-testid="run-button"]')
if (tracing) await page.tracing.start({ path: traceFile });
await page.click('[data-testid="run-button"]')
await page.waitForSelector(`[data-testid="${test} results"]`)
if (tracing) await page.tracing.stop();
const result = await page.$eval(`[data-testid="${test} results"]`, node => node.innerText)
console.log(`\n---${test}---`)
console.log(result)
console.log('Trace written to', traceFile)
}
console.log('Done!')