AgentSkillsCN

Performance Testing Best Practices

性能测试最佳实践

SKILL.md
--- frontmatter
description: Performance Testing Best Practices
globs: *.performance.ts
alwaysApply: false

Performance Testing Best Practices

Performance tests help prevent regressions in bundle size and render time performance.

Commands

bash
# Run performance tests (warn slow to complete)
pnpm run test:performance

# Run single file performance test
pnpm run test:performance -- src/COMPONENT_DIR/element.performance.ts

Test File Structure

  • Performance test files should be named element.performance.ts
  • Place them alongside the component file in the same directory

Test Template

typescript
import { testBundleSize, testRenderTime, html } from 'web-test-runner-performance/browser.js';
import '@blueprintui/components/include/component-name.js';

describe('bp-component-name performance', () => {
  const element = html`<bp-component-name>content</bp-component-name>`;

  it(`should bundle and treeshake under Xkb`, async () => {
    expect(
      (await testBundleSize('@blueprintui/components/include/component-name.js', { optimize: true })).kb
    ).toBeLessThan(X);
  });

  it(`should render under Xms`, async () => {
    expect((await testRenderTime(element)).duration).toBeLessThan(X);
  });
});