Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to test JavaScript minification output
    primarykey
    data
    text
    <p>We recently upgraded to a newer build of a JavaScript minification library.</p> <p>After a significant amount of quality assurance work by the testing team, it was discovered that the new version of our minifier had an issue that changed the intention and meaning behind a block of code.</p> <p>(Life lesson: don't upgrade JS minifiers unless you are really convinced you need the new version.)</p> <p>The minifier is used for client side JavaScript code with a heavy emphasis on DOM related activity, not nearly as much "business logic".</p> <p>A simplified example of what was broken by the minifier upgrade:</p> <pre><code>function process(count) { var value = ""; value += count; //1. Two consecutive += statements value += count; count++; //2. Some other statement return value; //3. Return } </code></pre> <p>Was minified incorrectly to the following:</p> <pre><code>function process(n){var t="";return t+n+n,n++,t} </code></pre> <p>While we could write some unit tests to catch some of the issues potentially, given that the JavaScript is heavy on DOM interactions (data input, etc.), it's very difficult to test thoroughly without user testing (non-automated). We'd pondered using a JS to AST library like Esprima, but given the nature of the changes that could be done to the minified code, it would produce far too many false positives. </p> <p>We also considered trying to write representative tests, but that seems like a never-ending task (and likely to miss cases).</p> <p>FYI: This is a very sophisticated web application with several hundred thousand lines of JavaScript code.</p> <p>We're looking for a methodology for testing the minification process short of "just test everything again, thoroughly, and repeat." We'd like to apply a bit more rigor/science to the process. </p> <p>Ideally, we could try multiple minifiers without fear of each breaking our code in new subtle ways if we had a better scientific method for testing.</p> <p>Update: </p> <p>One idea we had was to: </p> <ol> <li>take minification with old version</li> <li>beautify it</li> <li>minify with new version, </li> <li>beautify, and </li> <li>visually diff. </li> </ol> <p>It did seem like a good idea, however the differences were so common that the diff tool flagged nearly every line as being different.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload