|
| 1 | +import assert from 'node:assert/strict' |
| 2 | +import { describe, it } from 'node:test' |
| 3 | +import { createMessage } from './reportAsAPrComment.ts' |
| 4 | + |
| 5 | +void describe('reportAsAPrComment', () => { |
| 6 | + void describe('createMessage', () => { |
| 7 | + const TEST_BUNDLE = 'test' |
| 8 | + const PR_NUMBER = 123 |
| 9 | + |
| 10 | + const BASE_BUNDLE_SIZES = [{ name: TEST_BUNDLE, value: 100 }] |
| 11 | + const MEMORY_BASE_PERFORMANCE = [{ name: TEST_BUNDLE, value: 100 }] |
| 12 | + const CPU_BASE_PERFORMANCE = [{ name: TEST_BUNDLE, value: 100 }] |
| 13 | + |
| 14 | + const MEMORY_LOCAL_PERFORMANCE = [{ testProperty: TEST_BUNDLE, sdkMemoryBytes: 101, sdkMemoryPercentage: 10 }] |
| 15 | + const CPU_LOCAL_PERFORMANCE = [{ name: TEST_BUNDLE, value: 101 }] |
| 16 | + |
| 17 | + void it('should generate a report with performance results', () => { |
| 18 | + const localBundleSizes = { test: 101 } |
| 19 | + |
| 20 | + const message = createMessage( |
| 21 | + BASE_BUNDLE_SIZES, |
| 22 | + localBundleSizes, |
| 23 | + MEMORY_BASE_PERFORMANCE, |
| 24 | + MEMORY_LOCAL_PERFORMANCE, |
| 25 | + CPU_BASE_PERFORMANCE, |
| 26 | + CPU_LOCAL_PERFORMANCE, |
| 27 | + PR_NUMBER |
| 28 | + ) |
| 29 | + |
| 30 | + assert.equal( |
| 31 | + message, |
| 32 | + `| 📦 Bundle Name | Base Size | Local Size | 𝚫 | 𝚫% | Status | |
| 33 | +| --- | --- | --- | --- | --- | --- | |
| 34 | +| Test | 100 B | 101 B | 1 B | +1.00% | ✅ | |
| 35 | +</details> |
| 36 | +
|
| 37 | +<details> |
| 38 | +<summary>🚀 CPU Performance</summary> |
| 39 | +
|
| 40 | +| Action Name | Base Average Cpu Time (ms) | Local Average Cpu Time (ms) | 𝚫 | |
| 41 | +| --- | --- | --- | --- | |
| 42 | +| test | 100.000 | 101.000 | 1.000 | |
| 43 | +
|
| 44 | +</details> |
| 45 | +
|
| 46 | +<details> |
| 47 | +<summary>🧠 Memory Performance</summary> |
| 48 | +
|
| 49 | +| Action Name | Base Consumption Memory (bytes) | Local Consumption Memory (bytes) | 𝚫 (bytes) | |
| 50 | +| --- | --- | --- | --- | |
| 51 | +| test | 100 B | 101 B | 1 B | |
| 52 | +
|
| 53 | +</details> |
| 54 | +
|
| 55 | +🔗 [RealWorld](https://datadoghq.dev/browser-sdk-test-playground/realworld-scenario/?prNumber=123) |
| 56 | +
|
| 57 | +` |
| 58 | + ) |
| 59 | + }) |
| 60 | + |
| 61 | + void it('should add a warning when the size increase is above the threshold', () => { |
| 62 | + const localBundleSizes = { test: 150 } |
| 63 | + |
| 64 | + const message = createMessage( |
| 65 | + BASE_BUNDLE_SIZES, |
| 66 | + localBundleSizes, |
| 67 | + MEMORY_BASE_PERFORMANCE, |
| 68 | + MEMORY_LOCAL_PERFORMANCE, |
| 69 | + CPU_BASE_PERFORMANCE, |
| 70 | + CPU_LOCAL_PERFORMANCE, |
| 71 | + PR_NUMBER |
| 72 | + ) |
| 73 | + |
| 74 | + assertContains(message, '| Test | 100 B | 150 B | 50 B | +50.00% | ⚠️ |') |
| 75 | + assertContains(message, '⚠️ The increase is particularly high and exceeds 5%. Please check the changes.') |
| 76 | + }) |
| 77 | + }) |
| 78 | +}) |
| 79 | + |
| 80 | +function assertContains(actual: string, expected: string) { |
| 81 | + assert.ok( |
| 82 | + actual.includes(expected), |
| 83 | + ['Expected string to contain:', ` expected: "${expected}"`, ` actual: "${actual}"`].join('\n') |
| 84 | + ) |
| 85 | +} |
0 commit comments