@@ -3,47 +3,12 @@ import { readFile } from 'node:fs/promises';
33import { join } from 'node:path' ;
44import { test } from 'vitest' ;
55import { formatMarkdown } from '../size-report.mjs' ;
6- import {
7- assertPublishPackageContents ,
8- classifyNpmPackEntry ,
9- summarizeNpmPackComponents ,
10- } from '../size-report-package.mjs' ;
6+ import { assertPublishPackageContents } from '../size-report-package.mjs' ;
117
128const fixturePack = JSON . parse (
139 await readFile ( join ( import . meta. dirname , 'fixtures' , 'size-report-npm-pack.json' ) , 'utf8' ) ,
1410) ;
1511
16- test ( 'classifies every shipped entry into one named component' , ( ) => {
17- const classified = fixturePack . files . map ( classifyNpmPackEntry ) ;
18-
19- assert . deepEqual (
20- classified . map ( ( entry ) => [ entry . path , entry . component ] ) ,
21- [
22- [ 'dist/src/index.js' , 'js' ] ,
23- [ 'dist/src/index.d.ts' , 'js' ] ,
24- [ 'dist/apple/runner/RunnerTests.swift' , 'apple-runner' ] ,
25- [ 'dist/apple/snapshot-presentation/Package.swift' , 'apple-snapshot-presentation' ] ,
26- [ 'apple/snapshot-bridge/SnapshotBridge.m' , 'apple-snapshot-bridge' ] ,
27- [ 'apple/snapshot-bridge/SnapshotBridgeRuntime.m' , 'apple-snapshot-bridge' ] ,
28- [ 'apple/snapshot-bridge/SnapshotBridgeRuntime.h' , 'apple-snapshot-bridge' ] ,
29- [ 'apple/macos-helper/Sources/main.swift' , 'macos-helper' ] ,
30- [ 'android/snapshot-helper/dist/helper.apk' , 'android-helpers' ] ,
31- [ 'android/snapshot-helper/dist/helper.manifest.json' , 'android-helpers' ] ,
32- [ 'android/ime-helper/dist/helper.apk' , 'android-helpers' ] ,
33- [ 'android/ime-helper/dist/helper.manifest.json' , 'android-helpers' ] ,
34- [ 'package.json' , 'other' ] ,
35- [ 'vendor/unknown.bin' , 'other' ] ,
36- ] ,
37- ) ;
38- } ) ;
39-
40- test ( 'unknown package paths fall into other' , ( ) => {
41- assert . equal (
42- classifyNpmPackEntry ( { path : 'new/future-package-file' , size : 13 } ) . component ,
43- 'other' ,
44- ) ;
45- } ) ;
46-
4712test ( 'publish package requires both Android helpers and excludes benchmark scripts' , ( ) => {
4813 assert . doesNotThrow ( ( ) => assertPublishPackageContents ( fixturePack . files ) ) ;
4914 assert . throws (
@@ -78,65 +43,34 @@ test('publish package requires both Android helpers and excludes benchmark scrip
7843 ) ;
7944} ) ;
8045
81- test ( 'component bytes sum exactly to npm pack unpackedSize' , ( ) => {
82- const components = summarizeNpmPackComponents ( fixturePack ) ;
83-
84- assert . equal (
85- components . reduce ( ( total , component ) => total + component . unpackedBytes , 0 ) ,
86- fixturePack . unpackedSize ,
87- ) ;
88- assert . deepEqual (
89- Object . fromEntries ( components . map ( ( component ) => [ component . id , component . unpackedBytes ] ) ) ,
90- {
91- js : 503 ,
92- 'apple-runner' : 503 ,
93- 'apple-snapshot-presentation' : 113 ,
94- 'apple-snapshot-bridge' : 0 ,
95- 'macos-helper' : 211 ,
96- 'android-helpers' : 812 ,
97- other : 177 ,
98- } ,
99- ) ;
100- assert . throws (
101- ( ) => summarizeNpmPackComponents ( { ...fixturePack , unpackedSize : 2318 } ) ,
102- / d o e s n o t m a t c h n p m p a c k u n p a c k e d S i z e / ,
103- ) ;
104- } ) ;
105-
106- test ( 'Markdown reports component diffs and changed packed files' , ( ) => {
46+ test ( 'Markdown emphasizes total install size and startup without duplicate breakdowns' , ( ) => {
10747 const current = {
108- js : { rawBytes : 10 , gzipBytes : 8 } ,
48+ bundled : { rawBytes : 300 , gzipBytes : 100 } ,
10949 npmPack : {
11050 tarballBytes : 100 ,
111- unpackedBytes : 2319 ,
112- components : summarizeNpmPackComponents ( fixturePack ) ,
51+ unpackedBytes : 300 ,
11352 entries : fixturePack . files ,
11453 } ,
115- chunks : [ ] ,
54+ cleanInstalled : { packageBytes : 300 , totalBytes : 350 , files : 3 } ,
55+ startup : { runs : 7 , benchmarks : [ { name : 'CLI --help' , medianMs : 20 } ] } ,
11656 } ;
117- const baseEntries = fixturePack . files . map ( ( entry ) =>
118- entry . path === 'dist/src/index.js' ? { ...entry , size : 300 } : entry ,
119- ) ;
12057 const base = {
121- js : { rawBytes : 10 , gzipBytes : 8 } ,
122- npmPack : {
123- tarballBytes : 100 ,
124- unpackedBytes : 2218 ,
125- components : summarizeNpmPackComponents ( {
126- ...fixturePack ,
127- unpackedSize : 2218 ,
128- files : baseEntries ,
129- } ) ,
130- entries : baseEntries ,
131- } ,
132- chunks : [ ] ,
58+ ...current ,
59+ npmPack : { ...current . npmPack , tarballBytes : 90 , unpackedBytes : 200 } ,
60+ cleanInstalled : { packageBytes : 200 , totalBytes : 900 , files : 8 } ,
61+ startup : { runs : 7 , benchmarks : [ { name : 'CLI --help' , medianMs : 25 } ] } ,
13362 } ;
13463
13564 const markdown = formatMarkdown ( current , base ) ;
13665
137- assert . match ( markdown , / # # # n p m u n p a c k e d c o m p o n e n t s / ) ;
138- assert . match ( markdown , / \| J S \/ d i s t s o u r c e \| 4 0 2 B \| 5 0 3 B \| \+ 1 0 1 B \| / ) ;
139- assert . match ( markdown , / \| O t h e r p a c k a g e f i l e s \| 1 7 7 B \| 1 7 7 B \| 0 B \| / ) ;
140- assert . match ( markdown , / # # # T o p c h a n g e d p a c k e d f i l e s / ) ;
141- assert . match ( markdown , / ` d i s t \/ s r c \/ i n d e x \. j s ` \| 3 0 0 B \| 4 0 1 B \| \+ 1 0 1 B / ) ;
66+ assert . match ( markdown , / < ! - - a g e n t - d e v i c e - s i z e - r e p o r t - - > / ) ;
67+ assert . match ( markdown , / \| I n s t a l l e d \( i n c l u d i n g d e p e n d e n c i e s \) \| 9 0 0 B \| 3 5 0 B \| - 5 5 0 B \| / ) ;
68+ assert . match ( markdown , / \| P a c k a g e \( u n p a c k e d \) \| 2 0 0 B \| 3 0 0 B \| \+ 1 0 0 B \| / ) ;
69+ assert . match ( markdown , / \| P a c k a g e \( d o w n l o a d \) \| 9 0 B \| 1 0 0 B \| \+ 1 0 B \| / ) ;
70+ assert . match ( markdown , / \| C L I - - h e l p \| 2 5 .0 m s \| 2 0 .0 m s \| - 5 .0 m s \| / ) ;
71+ assert . doesNotMatch ( markdown , / J S r a w | J S g z i p | n p m b u n d l e d | c o m p o n e n t s | T o p .* c h u n k s | p a c k e d f i l e s / ) ;
72+ assert . match (
73+ formatMarkdown ( current , null ) ,
74+ / \| I n s t a l l e d \( i n c l u d i n g d e p e n d e n c i e s \) \| - \| 3 5 0 B \| - \| / ,
75+ ) ;
14276} ) ;
0 commit comments