@@ -2,17 +2,21 @@ import {
22 stripLineComment ,
33 minifyRaw ,
44 minifyCooked ,
5- compressSymbols
5+ compressSymbols ,
66} from '../../src/minify'
77
8+ import { makePlaceholder } from '../../src/css/placeholderUtils'
9+
810describe ( 'minify utils' , ( ) => {
911 describe ( 'stripLineComment' , ( ) => {
1012 it ( 'splits a line by potential comment starts and joins until one is an actual comment' , ( ) => {
1113 expect ( stripLineComment ( 'abc def//ghi//jkl' ) ) . toBe ( 'abc def' )
1214 } )
1315
1416 it ( 'ignores comment markers that are inside strings' , ( ) => {
15- expect ( stripLineComment ( 'abc def"//"ghi\'//\'jkl//the end' ) ) . toBe ( 'abc def"//"ghi\'//\'jkl' )
17+ expect ( stripLineComment ( 'abc def"//"ghi\'//\'jkl//the end' ) ) . toBe (
18+ 'abc def"//"ghi\'//\'jkl'
19+ )
1620 expect ( stripLineComment ( 'abc def"//"' ) ) . toBe ( 'abc def"//"' )
1721 } )
1822
@@ -21,67 +25,89 @@ describe('minify utils', () => {
2125 } )
2226
2327 it ( 'ignores even unescaped URLs' , ( ) => {
24- expect ( stripLineComment ( 'https://test.com// comment//' ) ) . toBe ( 'https://test.com' )
28+ expect ( stripLineComment ( 'https://test.com// comment//' ) ) . toBe (
29+ 'https://test.com'
30+ )
2531 } )
2632 } )
2733
2834 describe ( 'minify(Raw|Cooked)' , ( ) => {
2935 it ( 'Removes multi-line comments' , ( ) => {
3036 const input = 'this is a/* ignore me please */test'
3137 const expected = 'this is a test' // NOTE: They're replaced with newlines, and newlines are joined
32- const actual = minifyRaw ( input )
38+ const [ actual ] = minifyRaw ( input )
3339
3440 expect ( actual ) . toBe ( expected )
35- expect ( actual ) . toBe ( minifyCooked ( input ) )
41+ expect ( actual ) . toBe ( minifyCooked ( input ) [ 0 ] )
3642 } )
3743
3844 it ( 'Joins all lines of code' , ( ) => {
3945 const input = 'this\nis\na/* ignore me \n please */\ntest'
4046 const expected = 'this is a test'
41- const actual = minifyRaw ( input )
47+ const [ actual ] = minifyRaw ( input )
4248
4349 expect ( actual ) . toBe ( expected )
44- expect ( actual ) . toBe ( minifyCooked ( input ) )
50+ expect ( actual ) . toBe ( minifyCooked ( input ) [ 0 ] )
4551 } )
4652
4753 it ( 'Removes line comments filling an entire line' , ( ) => {
4854 const input = 'line one\n// remove this comment\nline two'
4955 const expected = 'line one line two'
50- const actual = minifyRaw ( input )
56+ const [ actual ] = minifyRaw ( input )
5157
5258 expect ( actual ) . toBe ( expected )
53- expect ( actual ) . toBe ( minifyCooked ( input ) )
59+ expect ( actual ) . toBe ( minifyCooked ( input ) [ 0 ] )
5460 } )
5561
5662 it ( 'Removes line comments at the end of lines of code' , ( ) => {
5763 const input = 'valid line with // a comment\nout comments'
5864 const expected = 'valid line with out comments'
59- const actual = minifyRaw ( input )
65+ const [ actual ] = minifyRaw ( input )
6066
6167 expect ( actual ) . toBe ( expected )
62- expect ( actual ) . toBe ( minifyCooked ( input ) )
68+ expect ( actual ) . toBe ( minifyCooked ( input ) [ 0 ] )
6369 } )
6470
6571 it ( 'Preserves multi-line comments starting with /*!' , ( ) => {
66- const input = 'this is a /*! dont ignore me please */ test/* but you can ignore me */'
72+ const input =
73+ 'this is a /*! dont ignore me please */ test/* but you can ignore me */'
6774 const expected = 'this is a /*! dont ignore me please */ test'
68- const actual = minifyRaw ( input )
75+ const [ actual ] = minifyRaw ( input )
76+
77+ expect ( actual ) . toBe ( expected )
78+ expect ( actual ) . toBe ( minifyCooked ( input ) [ 0 ] )
79+ } )
80+
81+ it ( 'Returns the indices of removed placeholders (expressions)' , ( ) => {
82+ const placeholder1 = makePlaceholder ( 0 )
83+ const placeholder2 = makePlaceholder ( 1 )
84+ const input = `this is some\ninput with ${ placeholder1 } and // ignored ${ placeholder2 } `
85+ const expected = `this is some input with ${ placeholder1 } and `
86+ const [ actual , indices ] = minifyRaw ( input )
6987
7088 expect ( actual ) . toBe ( expected )
71- expect ( actual ) . toBe ( minifyCooked ( input ) )
89+ expect ( indices ) . toEqual ( [ 1 ] )
90+ expect ( minifyCooked ( input ) ) . toEqual ( [ actual , [ 1 ] ] )
7291 } )
7392 } )
7493
7594 describe ( 'minifyRaw' , ( ) => {
7695 it ( 'works with raw escape codes' , ( ) => {
7796 const input = 'this\\nis\\na/* ignore me \\n please */\\ntest'
7897 const expected = 'this is a test'
79- const actual = minifyRaw ( input )
98+ const [ actual ] = minifyRaw ( input )
99+
100+ expect ( actual ) . toBe ( expected )
101+ } )
102+ } )
80103
81- expect ( minifyRaw ( input ) ) . toBe ( expected )
104+ describe ( 'minifyCooked' , ( ) => {
105+ it ( 'works with raw escape codes' , ( ) => {
106+ const input = 'this\\nis\\na/* ignore me \\n please */\\ntest'
107+ const expected = 'this\\nis\\na \\ntest'
108+ const [ actual ] = minifyCooked ( input )
82109
83- // NOTE: This is just a sanity check
84- expect ( minifyCooked ( input ) ) . toBe ( 'this\\nis\\na \\ntest' )
110+ expect ( actual ) . toBe ( expected )
85111 } )
86112 } )
87113
0 commit comments