Add a test for SVG minification
authorThomas Genin <tgenin@expensify.com>
Tue, 17 Nov 2015 23:45:20 +0000 (15:45 -0800)
committerThomas Genin <tgenin@expensify.com>
Tue, 17 Nov 2015 23:45:20 +0000 (15:45 -0800)
tests/minifier.js

index accf8bf..834107f 100644 (file)
     equal(minify('<div class="bar">foo</div>', { quoteCharacter: 'm' }), '<div class="bar">foo</div>');
   });
 
+  test('minify SVG', function() {
+    input = '<html><body>\n' +
+      '  <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\n' +
+      '     width="612px" height="502.174px" viewBox="0 65.326 612 502.174" enable-background="new 0 65.326 612 502.174"\n' +
+      '     xml:space="preserve" class="logo">' +
+      '' +
+      '    <ellipse class="ground" cx="283.5" cy="487.5" rx="259" ry="80"/>' +
+      '    <polygon points="100,10 40,198 190,78 10,78 160,198"\n' +
+      '      style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />\n' +
+      '    <filter id="pictureFilter">\n' +
+      '      <feGaussianBlur stdDeviation="15" />\n' +
+      '    </filter>\n' +
+      '  </svg>\n' +
+      '</body></html>';
+
+    output = '<html><body>' +
+      '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="612px" height="502.174px" viewBox="0 65.326 612 502.174" enable-background="new 0 65.326 612 502.174" xml:space="preserve" class="logo"><ellipse class="ground" cx="283.5" cy="487.5" rx="259" ry="80"/><path fill="#0f0" stroke="purple" stroke-width="5" fill-rule="evenodd" d="M100 10L40 198 190 78H10l150 120z"/></svg>' +
+      '</body></html>';
+
+    // Should preserve case-sensitivity and closing slashes within svg tags
+    equal(minify(input, { collapseWhitespace: true, minifySVG: { cleanupIDs: true } }), output);
+  });
+
 })(typeof exports === 'undefined' ? window : exports);