From a59d6dc3c7e555ba7e5fec6097a9e1401079d486 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 10 Sep 2012 20:35:27 -0700 Subject: [PATCH] Add minify.js Underscore unit test. Former-commit-id: 1db7b19709ef953dd1996a082e73a2ba542f29f7 --- test/test-build.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/test/test-build.js b/test/test-build.js index d3c280d14..96ccbf165 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -5,18 +5,15 @@ /** Load modules */ var fs = require('fs'), path = require('path'), - vm = require('vm'); + vm = require('vm'), + build = require('../build.js'), + minify = require('../build/minify'), + _ = require('../lodash.js'); /** The unit testing framework */ var QUnit = global.QUnit = require('../vendor/qunit/qunit/qunit.js'); require('../vendor/qunit-clib/qunit-clib.js'); - /** The `lodash` function to test */ - var _ = require('../lodash.js'); - - /** The `build` module */ - var build = require('../build.js'); - /** Used to associate aliases with their real names */ var aliasToRealMap = { 'all': 'every', @@ -672,4 +669,32 @@ }); }()); + /*--------------------------------------------------------------------------*/ + + QUnit.module('minify underscore'); + + (function() { + var start = _.once(QUnit.start); + + asyncTest('`minify underscore.js`', function() { + var source = fs.readFileSync(path.join(__dirname, '..', 'vendor', 'underscore', 'underscore.js'), 'utf8'); + minify(source, { + 'silent': true, + 'workingName': 'underscore.min', + 'onComplete': function(result) { + var context = createContext(); + + try { + vm.runInContext(result, context); + } catch(e) { } + + var underscore = context._ || {}; + ok(_.isString(underscore.VERSION)); + ok(result.match(/\n/g).length < source.match(/\n/g).length); + start(); + } + }); + }); + }()); + }());