From: Tim Wood Date: Mon, 20 Aug 2012 20:02:12 +0000 (-0700) Subject: Switching to grunt #406 X-Git-Tag: 2.0.0~77^2^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15384062a84bc94d6249002fb24006f70600404e;p=thirdparty%2Fmoment.git Switching to grunt #406 --- diff --git a/grunt.js b/grunt.js new file mode 100644 index 000000000..4d1b9efd2 --- /dev/null +++ b/grunt.js @@ -0,0 +1,32 @@ +module.exports = function(grunt) { + + grunt.initConfig({ + test : { + files : ["test/**/*.js"] + }, + lint : { + files: [ + 'moment.js', + 'lang/**/*.js' + ] + }, + watch : { + test : { + files : [ + 'moment.js', + 'test/**/*.js' + ], + tasks: 'test' + }, + lint : { + files : '', + tasks: 'lint' + } + } + }); + + grunt.loadTasks("tasks"); + + // Default task. + grunt.registerTask('default', 'test'); +}; \ No newline at end of file diff --git a/tasks/history.js b/tasks/history.js new file mode 100644 index 000000000..c46296077 --- /dev/null +++ b/tasks/history.js @@ -0,0 +1,123 @@ +var https = require("https"), + zlib = require('zlib'), + path = require('path'), + fs = require('fs'); + +var count = 0; +var resolved = 0; + +var outputs = []; + +var done; + +function check() { + if (resolved === count) { + normalize(); + display(); + } +} + +function makeBar(length) { + var i = ''; + while (i.length < length) { + i += '='; + } + return i; +} + +function normalize() { + var i, + max = 0, + max2 = 0; + for (i = 0; i < count; i ++) { + max = Math.max(max, outputs[i].gzip); + max2 = Math.max(max2, outputs[i].original); + } + for (i = 0; i < count; i ++) { + outputs[i].bargraph = makeBar((outputs[i].gzip / max) * 80); + outputs[i].bargraph2 = makeBar((outputs[i].original / max2) * 80); + } +} + +function display() { + var i; + for (i = 0; i < count; i ++) { + console.log(outputs[i].version + ' ' + outputs[i].gzip + ' ' + outputs[i].original); + console.log('gzip ' + outputs[i].bargraph); + console.log('orig ' + outputs[i].bargraph2); + } + done(); +} + +function getSizeAtVersion(version, path) { + var data = '', + op = {}, + + req = https.request({ + host: 'raw.github.com', + port: 443, + path: '/timrwood/moment/' + version + path + }, function (res) { + res.setEncoding('utf8'); + res.on('data', function (chunk) { + data += chunk; + }); + res.on('end', function (e) { + zlib.gzip(data, function (error, result) { + op.version = version; + op.gzip = result.length; + op.original = data.length; + resolved ++; + check(); + }); + }); + }); + + req.on('error', function (e) { + console.log('problem with request: ' + e.message); + }); + req.end(); + count++; + outputs.push(op); +} + +function getRemote() { + var old_versions = '1.0.1 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.4.0'.split(' '), + new_versions = '1.5.0 1.5.1 1.6.0 1.6.1 1.7.0'.split(' '), + i; + + for (i = 0; i < old_versions.length; i++) { + getSizeAtVersion(old_versions[i], '/moment.min.js'); + } + for (i = 0; i < new_versions.length; i++) { + getSizeAtVersion(new_versions[i], '/min/moment.min.js'); + } +} + +function getLocal() { + count ++; + var op = {}; + outputs.push(op); + fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function (err, data) { + if (err) { + throw err; + } + zlib.gzip(data, function (error, result) { + op.version = '.next'; + op.gzip = result.length; + op.original = data.length; + resolved ++; + check(); + }); + }); +} + + + +module.exports = function (grunt) { + grunt.registerTask('history', 'Check the codebase filesize over different releases.', function () { + done = this.async(); + getRemote(); + getLocal(); + }); +}; \ No newline at end of file diff --git a/tasks/size.js b/tasks/size.js new file mode 100644 index 000000000..90feb2e54 --- /dev/null +++ b/tasks/size.js @@ -0,0 +1,60 @@ +var https = require("https"), + zlib = require('zlib'), + path = require('path'), + fs = require('fs'); + +var stable = '1.7.0', + done; + +function getVersion(path, cb) { + var data = '', + + req = https.request({ + host: 'raw.github.com', + port: 443, + path: '/timrwood/moment/' + path + }, function (res) { + res.setEncoding('utf8'); + res.on('data', function (chunk) { + data += chunk; + }); + res.on('end', function (e) { + zlib.gzip(data, function (error, result) { + cb(data.length, result.length); + }); + }); + }); + req.on('error', function (e) { + console.log('problem with request: ' + e.message); + }); + req.end(); +} + +function printDiffs(stableLen, stableGzip, currentLen, currentGzip) { + var diff = currentLen - stableLen, + gzipDiff = currentGzip - stableGzip; + + console.log("Filesize difference from current branch to " + stable); + console.log(stable + " " + stableLen + ' / ' + stableGzip); + console.log("curr " + currentLen + ' / ' + currentGzip); + console.log("diff " + (diff > 0 ? '+' : '') + diff); + console.log("gzip " + (gzipDiff > 0 ? '+' : '') + gzipDiff); +} + + +module.exports = function (grunt) { + grunt.registerTask('size', 'Check the codebase filesize against the latest stable version.', function () { + done = this.async(); + fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function (err, data) { + if (err) { + throw err; + } + zlib.gzip(data, function (error, result) { + getVersion(stable + '/min/moment.min.js', function (stableLength, stableGzipLength) { + printDiffs(stableLength, stableGzipLength, data.length, result.length); + done(); + }); + }); + }); + }); +}; \ No newline at end of file diff --git a/tasks/zones.js b/tasks/zones.js new file mode 100644 index 000000000..d50aaf5a0 --- /dev/null +++ b/tasks/zones.js @@ -0,0 +1,180 @@ +var terminal = require('child_process').spawn('bash'), + path = require('path'), + util = require('util'), + nodeunit = require('nodeunit'); + + +module.exports = function (grunt) { + var ZONES; + + + /****************************** + Get Timezone + ******************************/ + + var currentTimezone = ''; + + function getTimezone() { + var term = require('child_process').spawn('bash'); + + term.stdout.on('data', function (data) { + currentTimezone = data.toString().replace('Time Zone: ', ''); + getTimezoneList(); + }); + + term.stdin.write('systemsetup gettimezone'); + term.stdin.end(); + + done = this.async() + } + + function getTimezoneList() { + var term = require('child_process').spawn('bash'), + data = ''; + + term.stdout.on('data', function (d) { + data += d; + }); + + term.stdout.on('end', function () { + data = data.replace('Time Zones:', ''); + ZONES = data.match(/\S+/g); + // console.log(ZONES); + startTests(); + }); + + term.stdin.write('systemsetup listtimezones'); + term.stdin.end(); + + } + + + + /****************************** + Set Timezone + ******************************/ + + var currentTimezone = ''; + + function setTimezone() { + terminal.stdin.write('systemsetup settimezone ' + currentTimezone); + terminal.stdin.end(); + } + + + /****************************** + Tests + ******************************/ + + + var files = ['test/moment'], + paths = files.map(function (p) { + return path.join(process.cwd(), p); + }); + + var globalfailures = ''; + + var f = 0; + var p = 0; + + var done; + + function errorLog(assertion) { + if (!assertion.error) { + return assertion; + } + + var e = assertion.error; + if (e.actual && e.expected) { + var actual = util.inspect(e.actual, false, 10).replace(/\n$/, ''), + expected = util.inspect(e.expected, false, 10).replace(/\n$/, ''), + multiline = (actual.indexOf('\n') !== -1 || expected.indexOf('\n') !== -1), + spacing = (multiline ? '\n' : ' '); + e._message = e.message; + e.stack = ( + e.name + ':' + spacing + + actual + spacing + e.operator + spacing + + expected + '\n' + + e.stack.split('\n').slice(1).join('\n') + ); + } + return assertion; + } + + var zone = '', + nextZone = ''; + + function runTestIfNeeded() { + if (zone === nextZone) { + return; + } + nextZone = zone; + + nodeunit.runFiles(paths, { + testDone: function (name, assertions) { + if (assertions.failures()) { + console.log('\nFAILURE: ' + name); + assertions.forEach(function (a) { + if (a.failed()) { + a = errorLog(a); + if (a.error && a.message) { + console.log('Assertion Message: ' + a.message); + } + console.log(a.error.stack); + } + }); + } + }, + done: function (assertions) { + if (assertions.failures()) { + grunt.log.error(zone + ' had ' + assertions.failures() + ' failures'); + globalfailures += zone + ' had ' + assertions.failures() + ' failures\n'; + f++; + } else { + grunt.log.ok(zone + ' passed ' + assertions.length + ' tests'); + p++; + } + nextTest(); + } + }); + } + + function runTest(zoned) { + zone = zoned; + terminal.stdin.write('systemsetup settimezone ' + zone + '\n'); + } + + terminal.stdout.on('data', function(d) { + setTimeout(runTestIfNeeded, 100); + }); + + + var i = 0; + + function startTests() { + nextTest(); + //setTimezone(); + } + + function nextTest() { + if (i < ZONES.length) { + runTest(ZONES[i]); + } else { + console.log("----------------------"); + console.log("----------------------"); + console.log(globalfailures); + console.log("----------------------"); + console.log("----------------------"); + console.log("--- Total Failing " + f); + console.log("----------------------"); + console.log("--- Total Passing " + p); + console.log("----------------------"); + console.log("----------------------"); + setTimezone(); + done(); + } + i++; + } + + grunt.registerTask('zones', 'Run the unit tests in different timezones.', getTimezone); +}; \ No newline at end of file diff --git a/test/filesize-diff.js b/test/filesize-diff.js deleted file mode 100644 index 6c18e3ea0..000000000 --- a/test/filesize-diff.js +++ /dev/null @@ -1,55 +0,0 @@ -var https = require("https"), - zlib = require('zlib'), - path = require('path'), - fs = require('fs'); - - -var stable = '1.6.2'; - -function getVersion(path, cb) { - var data = '', - - req = https.request({ - host: 'raw.github.com', - port: 443, - path: '/timrwood/moment/' + path - }, function(res) { - res.setEncoding('utf8'); - res.on('data', function (chunk) { - data += chunk; - }); - res.on('end', function(e) { - zlib.gzip(data, function(error, result) { - cb(data.length, result.length); - }); - }); - }); - req.on('error', function(e) { - console.log('problem with request: ' + e.message); - }); - req.end(); -} - -function printDiffs(stableLen, stableGzip, currentLen, currentGzip) { - var diff = currentLen - stableLen, - gzipDiff = currentGzip - stableGzip; - - console.log("Filesize difference from current branch to " + stable); - console.log(stable + " " + stableLen + ' / ' + stableGzip); - console.log("curr " + currentLen + ' / ' + currentGzip); - console.log("diff " + (diff > 0 ? '+' : '') + diff); - console.log("gzip " + (gzipDiff > 0 ? '+' : '') + gzipDiff); -} - -(function(){ - fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function(err, data){ - if (err) { - throw err; - } - zlib.gzip(data, function(error, result) { - getVersion(stable + '/min/moment.min.js', function (stableLength, stableGzipLength) { - printDiffs(stableLength, stableGzipLength, data.length, result.length); - }); - }); - }); -}()); \ No newline at end of file diff --git a/test/filesize-history.js b/test/filesize-history.js deleted file mode 100644 index f78f1fb89..000000000 --- a/test/filesize-history.js +++ /dev/null @@ -1,108 +0,0 @@ -var https = require("https"), - zlib = require('zlib'), - path = require('path'), - fs = require('fs'); - -var count = 0; -var resolved = 0; - -var outputs = []; - -function check() { - if (resolved === count) { - normalize(); - display(); - } -} - -function makeBar(length) { - var i = ''; - while (i.length < length) { - i += '='; - } - return i; -} - -function normalize() { - var i, - max = 0, - max2 = 0; - for (i = 0; i < count; i ++) { - max = Math.max(max, outputs[i].gzip); - max2 = Math.max(max2, outputs[i].original); - } - for (i = 0; i < count; i ++) { - outputs[i].bargraph = makeBar((outputs[i].gzip / max) * 80); - outputs[i].bargraph2 = makeBar((outputs[i].original / max2) * 80); - } -} - -function display() { - var i; - for (i = 0; i < count; i ++) { - console.log(outputs[i].version + ' ' + outputs[i].gzip + ' ' + outputs[i].original); - console.log('gzip ' + outputs[i].bargraph); - console.log('orig ' + outputs[i].bargraph2); - } -} - -function getSizeAtVersion(version, path) { - var data = ''; - var op = {}; - - var req = https.request({ - host: 'raw.github.com', - port: 443, - path: '/timrwood/moment/' + version + path - }, function(res) { - res.setEncoding('utf8'); - res.on('data', function (chunk) { - data += chunk; - }); - res.on('end', function(e) { - zlib.gzip(data, function(error, result) { - op.version = version; - op.gzip = result.length; - op.original = data.length; - resolved ++; - check(); - }); - }); - }); - - req.on('error', function(e) { - console.log('problem with request: ' + e.message); - }); - req.end(); - count++; - outputs.push(op); -} - -(function(){ - var old_versions = '1.0.1 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.4.0'.split(' '); - var new_versions = '1.5.0 1.5.1 1.6.0 1.6.1'.split(' '); - var i; - - for (i = 0; i < old_versions.length; i++) { - getSizeAtVersion(old_versions[i], '/moment.min.js'); - } - for (i = 0; i < new_versions.length; i++) { - getSizeAtVersion(new_versions[i], '/min/moment.min.js'); - } -}()); - -(function(){ - count ++; - var op = {}; - outputs.push(op); - fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function(err, data){ - if (err) throw err; - zlib.gzip(data, function(error, result) { - op.version = '.next'; - op.gzip = result.length; - op.original = data.length; - resolved ++; - check(); - }); - }); -}()); \ No newline at end of file diff --git a/test/zone.js b/test/zone.js deleted file mode 100644 index 5813fbc7e..000000000 --- a/test/zone.js +++ /dev/null @@ -1,181 +0,0 @@ -var terminal = require('child_process').spawn('bash'), - path = require('path'), - util = require('util'), - nodeunit = require('nodeunit'); - -var ZONES; - - -/****************************** - Get Timezone -******************************/ - -var currentTimezone = ''; - -function getTimezone() { - var term = require('child_process').spawn('bash'); - - term.stdout.on('data', function (data) { - currentTimezone = data.toString().replace('Time Zone: ', ''); - getTimezoneList(); - }); - - term.stdin.write('systemsetup gettimezone'); - term.stdin.end(); -} - -function getTimezoneList() { - var term = require('child_process').spawn('bash'), - data = ''; - - term.stdout.on('data', function (d) { - data += d; - }); - - term.stdout.on('end', function () { - data = data.replace('Time Zones:', ''); - ZONES = data.match(/\S+/g); - // console.log(ZONES); - startTests(); - }); - - term.stdin.write('systemsetup listtimezones'); - term.stdin.end(); - -} - - - -/****************************** - Set Timezone -******************************/ - -var currentTimezone = ''; - -function setTimezone() { - terminal.stdin.write('systemsetup settimezone ' + currentTimezone); - terminal.stdin.end(); -} - - -/****************************** - Tests -******************************/ - - -var files = ['test/moment'], - paths = files.map(function (p) { - return path.join(process.cwd(), p); - }); - -var globalfailures = ''; - -var f = 0; -var p = 0; - -function errorLog(assertion) { - if (!assertion.error) { - return assertion; - } - - var e = assertion.error; - if (e.actual && e.expected) { - var actual = util.inspect(e.actual, false, 10).replace(/\n$/, ''), - expected = util.inspect(e.expected, false, 10).replace(/\n$/, ''), - multiline = (actual.indexOf('\n') !== -1 || expected.indexOf('\n') !== -1), - spacing = (multiline ? '\n' : ' '); - e._message = e.message; - e.stack = ( - e.name + ':' + spacing + - actual + spacing + e.operator + spacing + - expected + '\n' + - e.stack.split('\n').slice(1).join('\n') - ); - } - return assertion; -} - -var zone = '', - nextZone = ''; - -function runTestIfNeeded() { - if (zone === nextZone) { - return; - } - nextZone = zone; - - console.log("-----------------------"); - console.log(zone + " testing started..."); - nodeunit.runFiles(paths, { - testDone: function (name, assertions) { - if (assertions.failures()) { - console.log('\nFAILURE: ' + name); - assertions.forEach(function (a) { - if (a.failed()) { - a = errorLog(a); - if (a.error && a.message) { - console.log('Assertion Message: ' + a.message); - } - console.log(a.error.stack); - } - }); - } - }, - done: function (assertions) { - if (assertions.failures()) { - console.log('\n' + zone + ' had ' + assertions.failures() + ' failures'); - globalfailures += zone + ' had ' + assertions.failures() + ' failures\n'; - f++; - } else { - console.log(zone + ' passed all tests!'); - p++; - } - console.log("-----------------------"); - nextTest(); - } - }); -} - -function runTest(zoned) { - zone = zoned; - terminal.stdin.write('systemsetup settimezone ' + zone + '\n'); -} - -terminal.stdout.on('data', function(d) { - setTimeout(runTestIfNeeded, 100); -}); - - -var i = 0; - -function startTests() { - nextTest(); - //setTimezone(); -} - -function nextTest() { - if (i < ZONES.length) { - runTest(ZONES[i]); - } else { - console.log("----------------------"); - console.log("----------------------"); - console.log(globalfailures); - console.log("----------------------"); - console.log("----------------------"); - console.log("--- Total Failing " + f); - console.log("----------------------"); - console.log("--- Total Passing " + p); - console.log("----------------------"); - console.log("----------------------"); - setTimezone(); - } - i++; -} - - -/****************************** - Start it off -******************************/ - - -getTimezone(); \ No newline at end of file