|
2 | 2 |
|
3 | 3 | import { MetricBudget } from 'calibre'
|
4 | 4 |
|
| 5 | +// Returns a list of metric budgets for a site, including: |
| 6 | +// - The budget threshold value, e.g. 2500 |
| 7 | +// - Budget status, e.g. "met", "unmet", "at_risk" |
| 8 | +// - Metric, e.g. "largestContentfulPaint" |
| 9 | +// - Each page and test profile associated with the budget, with: |
| 10 | +// - Last observed value |
| 11 | +// - Whether the budget is within the threshold |
5 | 12 | const listMetricBudgets = async () => {
|
6 | 13 | const site = 'calibre' // site slug
|
7 |
| - const count = 20 // number of metric budgets to return, maximum 500 |
| 14 | + const count = 1 // number of metric budgets to return (maximum=5) |
| 15 | + const metric = 'largestContentfulPaint' // specify a metric (default=budgets for all metrics are returned) |
8 | 16 |
|
9 |
| - // Optional |
10 |
| - const metric = 'consistently-interactive' // pass a metric to limit results |
| 17 | + try { |
| 18 | + const metricBudgets = await MetricBudget.list({ |
| 19 | + site, |
| 20 | + metric, |
| 21 | + count |
| 22 | + }) |
11 | 23 |
|
12 |
| - // List the metric budgets |
13 |
| - const metricBudgets = await MetricBudget.list({ |
14 |
| - site, |
15 |
| - metric, |
16 |
| - count |
17 |
| - }) |
18 |
| - |
19 |
| - // Output the formatted JSON response |
20 |
| - console.log(JSON.stringify(metricBudgets, null, 2)) |
| 24 | + console.log(JSON.stringify(metricBudgets, null, 2)) |
| 25 | + } catch (error) { |
| 26 | + console.error(error) |
| 27 | + } |
21 | 28 | }
|
22 | 29 |
|
23 | 30 | listMetricBudgets()
|
0 commit comments