mirror of
https://github.com/zhigang1992/styled-components.git
synced 2026-04-29 09:45:54 +08:00
Add --tracing to benchmarks
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!')
|
||||
|
||||
Reference in New Issue
Block a user