Files
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

122 lines
3.6 KiB
JavaScript

#!/usr/bin/env node
/**
* Test the stats action comment formatting locally
*
* Usage: node test-local.js [--with-history]
*
* This generates a sample PR comment using mock data so you can
* quickly verify formatting changes without running the full action.
*
* Options:
* --with-history Simulate KV history data to test trend sparklines
*/
const addComment = require('./src/add-comment')
const withHistory = process.argv.includes('--with-history')
// Mock data simulating real benchmark results
const mockResults = [
{
title: 'Default Build',
mainRepoStats: {
General: {
nextDevColdListenDurationTurbo: 280,
nextDevColdReadyDurationTurbo: 450,
nextDevWarmListenDurationTurbo: 180,
nextDevWarmReadyDurationTurbo: 320,
nextDevColdListenDurationWebpack: 350,
nextDevColdReadyDurationWebpack: 1200,
nextDevWarmListenDurationWebpack: 250,
nextDevWarmReadyDurationWebpack: 800,
nextStartReadyDuration: 150,
buildDurationTurbo: 4500,
buildDurationCachedTurbo: 4200,
buildDurationWebpack: 14000,
buildDurationCachedWebpack: 13500,
nodeModulesSize: 250000000,
},
},
diffRepoStats: {
General: {
nextDevColdListenDurationTurbo: 290, // +10ms (insignificant)
nextDevColdReadyDurationTurbo: 520, // +70ms at 15% (significant regression)
nextDevWarmListenDurationTurbo: 175, // -5ms (insignificant)
nextDevWarmReadyDurationTurbo: 280, // -40ms at 12% (significant improvement)
nextDevColdListenDurationWebpack: 360,
nextDevColdReadyDurationWebpack: 1180,
nextDevWarmListenDurationWebpack: 245,
nextDevWarmReadyDurationWebpack: 790,
nextStartReadyDuration: 145,
buildDurationTurbo: 4400,
buildDurationCachedTurbo: 4250,
buildDurationWebpack: 13800,
buildDurationCachedWebpack: 13600,
nodeModulesSize: 251000000,
},
},
diffs: null,
},
]
const mockActionInfo = {
isRelease: false,
commitId: 'abc123',
issueId: 12345,
}
const mockStatsConfig = {
commentHeading: 'Stats from current PR',
}
// Run with LOCAL_STATS to output to file instead of posting
process.env.LOCAL_STATS = 'true'
// Mock the KV module to provide fake history if --with-history is passed
if (withHistory) {
// Generate mock history entries showing a trend
const mockHistory = []
for (let i = 0; i < 10; i++) {
mockHistory.push({
commitId: `commit-${i}`,
timestamp: new Date(Date.now() - i * 86400000).toISOString(),
metrics: {
nextDevColdReadyDurationTurbo: 400 + Math.random() * 100, // varies 400-500
nextDevWarmReadyDurationTurbo: 300 + Math.random() * 50,
buildDurationTurbo: 4000 + Math.random() * 1000,
},
})
}
// Inject mock KV client
process.env.KV_REST_API_URL = 'mock://kv'
process.env.KV_REST_API_TOKEN = 'mock-token'
// Patch the require to intercept @vercel/kv
const Module = require('module')
const originalRequire = Module.prototype.require
Module.prototype.require = function (id) {
if (id === '@vercel/kv') {
return {
createClient: () => ({
lrange: async () => mockHistory,
rpush: async () => {},
ltrim: async () => {},
}),
}
}
return originalRequire.apply(this, arguments)
}
console.log('Running with mock history data (10 entries)')
}
addComment(mockResults, mockActionInfo, mockStatsConfig)
.then(() =>
console.log(
'\nGenerated pr-stats.md - open it to see the comment' +
(withHistory ? ' (with trend sparklines)' : '')
)
)
.catch(console.error)