mirror of
https://github.com/videojs/video.js.git
synced 2026-11-20 06:29:27 +01:00
84 lines
2.7 KiB
JavaScript
84 lines
2.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { describe, it } from 'node:test';
|
|
|
|
import { generateComparisonReport } from '../bundle-size-report.js';
|
|
|
|
function entry(name, size, extra = {}) {
|
|
return {
|
|
name,
|
|
size,
|
|
type: 'subpath',
|
|
format: 'js',
|
|
...extra,
|
|
};
|
|
}
|
|
|
|
describe('generateComparisonReport', () => {
|
|
it('reports byte-level initial size changes', () => {
|
|
const base = [entry('@videojs/core/dom', 100)];
|
|
const current = [entry('@videojs/core/dom', 101)];
|
|
|
|
const report = generateComparisonReport(current, base);
|
|
|
|
assert.match(
|
|
report,
|
|
/\| `\/dom` \| 100 B \| 101 B \| \+1 B \(\+1\.0%\) \| — \|/,
|
|
);
|
|
assert.match(report, /1 small size change/);
|
|
assert.doesNotMatch(report, /@videojs\/core<\/b> — no changes/);
|
|
});
|
|
|
|
it('reports lazy-only changes', () => {
|
|
const base = [entry('@videojs/core/dom', 100, { lazySize: 10 })];
|
|
const current = [entry('@videojs/core/dom', 100, { lazySize: 20 })];
|
|
|
|
const report = generateComparisonReport(current, base);
|
|
|
|
assert.match(
|
|
report,
|
|
/\| `\/dom` \| 100 B \| 100 B \| 0 B \(0%\) \| \+10 B \|/,
|
|
);
|
|
});
|
|
|
|
it('reports added and removed entries', () => {
|
|
const base = [entry('@videojs/utils/removed', 50)];
|
|
const current = [entry('@videojs/utils/added', 25)];
|
|
|
|
const report = generateComparisonReport(current, base);
|
|
|
|
assert.match(report, /\| `\/added` \| — \| 25 B \| new \| — \|/);
|
|
assert.match(
|
|
report,
|
|
/\| `\/removed` \| 50 B \| — \| removed \| — \|/,
|
|
);
|
|
});
|
|
|
|
it('highlights changes whose combined initial and lazy delta exceeds the threshold', () => {
|
|
const base = [entry('@videojs/core/dom', 1000, { lazySize: 1000 })];
|
|
const current = [entry('@videojs/core/dom', 1200, { lazySize: 1200 })];
|
|
|
|
const report = generateComparisonReport(current, base);
|
|
|
|
assert.match(report, /## 🧩 @videojs\/core/);
|
|
assert.doesNotMatch(report, /small size change/);
|
|
});
|
|
|
|
it('collapses packages only when their measurements are identical', () => {
|
|
const measurements = [entry('@videojs/store', 200)];
|
|
|
|
const report = generateComparisonReport(measurements, measurements);
|
|
|
|
assert.match(report, /@videojs\/store<\/b> — no changes/);
|
|
});
|
|
|
|
it('groups extension entries in their own category', () => {
|
|
const base = [entry('@videojs/react/extensions/mux-data', 100, { category: 'extension' })];
|
|
const current = [entry('@videojs/react/extensions/mux-data', 101, { category: 'extension' })];
|
|
|
|
const report = generateComparisonReport(current, base);
|
|
|
|
assert.match(report, /<summary><b>Extensions \(1\)<\/b><\/summary>/);
|
|
assert.match(report, /`\/extensions\/mux-data`/);
|
|
});
|
|
});
|