@@ -21,3 +21,49 @@ test('simple range at end', () => {})
2121test ( 'atrule at start' , ( ) => { } )
2222test ( 'atrule at middle' , ( ) => { } )
2323test ( 'atrule at end' , ( ) => { } )
24+
25+ test ( 'prettified.text is the formatted output, not the original' , ( ) => {
26+ let original = 'a{color:red}'
27+ let chunked = chunkify ( {
28+ text : original ,
29+ ranges : [ { start : 0 , end : original . length } ] ,
30+ url : 'https://example.com' ,
31+ } )
32+ let result = prettify ( chunked )
33+
34+ // The formatted output differs from the minified original
35+ expect ( result . text ) . not . toBe ( original )
36+ // It contains proper whitespace that was absent in the original
37+ expect ( result . text ) . toContain ( 'color: red' )
38+ } )
39+
40+ test ( 'offsets in prettified result are based on formatted CSS length, not original byte positions' , ( ) => {
41+ let original = 'a{color:red}'
42+ let chunked = chunkify ( {
43+ text : original ,
44+ ranges : [ { start : 0 , end : original . length } ] ,
45+ url : 'https://example.com' ,
46+ } )
47+ let result = prettify ( chunked )
48+ let chunk = result . chunks [ 0 ]
49+
50+ // The formatted CSS is longer than the original, so offsets must differ
51+ expect ( result . text . length ) . toBeGreaterThan ( original . length )
52+ expect ( chunk . end_offset ) . toBeGreaterThan ( original . length - 1 )
53+ } )
54+
55+ test ( 'offsets index into prettified.text and yield formatted CSS, not original CSS' , ( ) => {
56+ let original = 'a{color:red}'
57+ let chunked = chunkify ( {
58+ text : original ,
59+ ranges : [ { start : 0 , end : original . length } ] ,
60+ url : 'https://example.com' ,
61+ } )
62+ let result = prettify ( chunked )
63+ let chunk = result . chunks [ 0 ]
64+
65+ // Substring with prettified offsets returns formatted CSS, not the original
66+ let recovered = result . text . substring ( chunk . start_offset , chunk . end_offset + 1 )
67+ expect ( recovered ) . not . toBe ( original )
68+ expect ( recovered ) . toContain ( 'color: red' )
69+ } )
0 commit comments