├── README.md ├── conf.js ├── config └── mysql.js ├── core ├── cfgload.js ├── child_mng.js ├── date_format.js ├── debug.js ├── env.js ├── log.js ├── parse │ ├── lexter.js │ └── select.js ├── tcpMaster.js ├── tcpWorker.js └── watcher.js ├── itier_developerclub_2012_beijing.pdf ├── node_modules ├── .bin │ ├── jake │ └── nodeunit ├── generic-pool │ ├── .gitignore │ ├── README.md │ ├── fabfile.py │ ├── lib │ │ └── generic-pool.js │ ├── package.json │ └── test │ │ └── generic-pool.test.js ├── jake │ ├── Jakefile │ ├── Makefile │ ├── README.md │ ├── bin │ │ └── cli.js │ ├── lib │ │ ├── api.js │ │ ├── file_list.js │ │ ├── jake.js │ │ ├── loader.js │ │ ├── npm_publish_task.js │ │ ├── package_task.js │ │ ├── parseargs.js │ │ ├── program.js │ │ ├── task │ │ │ ├── directory_task.js │ │ │ ├── file_task.js │ │ │ ├── index.js │ │ │ └── task.js │ │ └── utils.js │ ├── package.json │ └── tests │ │ ├── Jakefile │ │ ├── file_task.js │ │ ├── helpers.js │ │ ├── parseargs.js │ │ └── task_base.js ├── mcskin │ ├── index.js │ ├── mcskin.js │ ├── mctest.js │ └── node_modules │ │ └── memcache │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── README.md │ │ ├── example.js │ │ ├── index.js │ │ ├── lib │ │ └── memcache.js │ │ ├── mm.js │ │ ├── package.json │ │ └── test │ │ └── test-memcache.js ├── mysql │ ├── .gitignore │ ├── License │ ├── Makefile │ ├── Readme.md │ ├── benchmark │ │ ├── node-mysql │ │ │ ├── insert.js │ │ │ └── select.js │ │ └── php │ │ │ └── insert-select.php │ ├── index.js │ ├── lib │ │ ├── auth.js │ │ ├── client.js │ │ ├── constants.js │ │ ├── mysql.js │ │ ├── outgoing_packet.js │ │ ├── parser.js │ │ └── query.js │ ├── package.json │ ├── test │ │ ├── common.js │ │ ├── config.template.js │ │ ├── fast │ │ │ ├── test-client.js │ │ │ └── test-mysql.js │ │ ├── fixture │ │ │ ├── columnia.sql │ │ │ └── libmysql_password.c │ │ ├── legacy │ │ │ ├── common.js │ │ │ └── simple │ │ │ │ ├── test-auth.js │ │ │ │ ├── test-client.js │ │ │ │ ├── test-outgoing-packet.js │ │ │ │ ├── test-parser.js │ │ │ │ └── test-query.js │ │ ├── run.js │ │ └── slow │ │ │ ├── test-client-commands.js │ │ │ ├── test-client-connect.js │ │ │ ├── test-client-max-connections.js │ │ │ ├── test-client-query-column-ordering.js │ │ │ ├── test-client-query-error-handling.js │ │ │ └── test-client-query.js │ └── tool │ │ └── pcap-mysql.js └── nodeunit │ ├── .npmignore │ ├── CONTRIBUTORS.md │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── bin │ ├── nodeunit │ └── nodeunit.json │ ├── deps │ ├── async.js │ ├── console.log.js │ ├── ejs │ │ ├── History.md │ │ ├── Makefile │ │ ├── Readme.md │ │ ├── benchmark.js │ │ ├── ejs.js │ │ ├── ejs.min.js │ │ ├── examples │ │ │ ├── client.html │ │ │ ├── list.ejs │ │ │ └── list.js │ │ ├── index.js │ │ ├── lib │ │ │ ├── ejs.js │ │ │ ├── filters.js │ │ │ └── utils.js │ │ ├── package.json │ │ ├── support │ │ │ └── compile.js │ │ └── test │ │ │ └── ejs.test.js │ └── json2.js │ ├── dist │ └── nodeunit │ │ ├── bin │ │ ├── nodeunit │ │ └── nodeunit.json │ │ ├── deps │ │ ├── async.js │ │ ├── console.log.js │ │ ├── ejs.js │ │ └── json2.js │ │ ├── index.js │ │ ├── lib │ │ ├── .swp │ │ ├── assert.js │ │ ├── core.js │ │ ├── nodeunit.js │ │ ├── reporters │ │ │ ├── browser.js │ │ │ ├── default.js │ │ │ ├── eclipse.js │ │ │ ├── html.js │ │ │ ├── index.js │ │ │ ├── junit.js │ │ │ ├── machineout.js │ │ │ ├── minimal.js │ │ │ ├── nested.js │ │ │ ├── skip_passed.js │ │ │ ├── tap.js │ │ │ └── verbose.js │ │ ├── track.js │ │ ├── types.js │ │ └── utils.js │ │ ├── package.json │ │ └── share │ │ ├── junit.xml.ejs │ │ ├── license.js │ │ └── nodeunit.css │ ├── doc │ └── nodeunit.md │ ├── examples │ ├── browser │ │ ├── nodeunit.js │ │ ├── suite1.js │ │ ├── suite2.js │ │ ├── suite3.js │ │ └── test.html │ └── nested │ │ └── nested_reporter_test.unit.js │ ├── img │ ├── example_fail.png │ ├── example_machineout.png │ └── example_pass.png │ ├── index.js │ ├── lib │ ├── assert.js │ ├── core.js │ ├── nodeunit.js │ ├── reporters │ │ ├── browser.js │ │ ├── default.js │ │ ├── eclipse.js │ │ ├── html.js │ │ ├── index.js │ │ ├── junit.js │ │ ├── machineout.js │ │ ├── minimal.js │ │ ├── nested.js │ │ ├── skip_passed.js │ │ ├── tap.js │ │ └── verbose.js │ ├── track.js │ ├── types.js │ └── utils.js │ ├── man1 │ └── nodeunit.1 │ ├── node_modules │ ├── tap-assert │ │ ├── AUTHORS │ │ ├── LICENSE │ │ ├── README.md │ │ ├── assert.js │ │ └── package.json │ └── tap-producer │ │ ├── README.md │ │ ├── node_modules │ │ ├── inherits │ │ │ ├── README.md │ │ │ ├── inherits.js │ │ │ └── package.json │ │ ├── tap-results │ │ │ ├── README.md │ │ │ ├── package.json │ │ │ └── results.js │ │ └── yamlish │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── package.json │ │ │ └── yamlish.js │ │ ├── package.json │ │ └── tap-producer.js │ ├── nodelint.cfg │ ├── package.json │ ├── share │ ├── junit.xml.ejs │ ├── license.js │ └── nodeunit.css │ └── test │ ├── fixtures │ ├── coffee │ │ └── mock_coffee_module.coffee │ ├── dir │ │ ├── mock_module3.js │ │ └── mock_module4.js │ ├── mock_module1.js │ ├── mock_module2.js │ ├── raw_jscode1.js │ ├── raw_jscode2.js │ └── raw_jscode3.js │ ├── test-base.js │ ├── test-failing-callbacks.js │ ├── test-httputil.js │ ├── test-runfiles.js │ ├── test-runmodule.js │ ├── test-runtest.js │ ├── test-sandbox.js │ ├── test-testcase-legacy.js │ ├── test-testcase.js │ └── test.html ├── resources └── test │ └── sources │ └── test.json ├── run.sh ├── sample └── service.js ├── sql.txt ├── src ├── data.js ├── data │ ├── join.js │ ├── prototype.js │ ├── tmpSql.js │ ├── union.js │ └── wjoin.js ├── dispatch.js ├── dispatch.js.bake ├── hotcfg.js ├── parse │ └── url.js ├── plugin.js ├── plugin │ └── sumPlugin.js ├── source │ ├── _http_cache.js │ ├── _loader_base.js │ ├── mysql.js │ ├── service_a.js │ ├── service_b.js │ ├── sql.js │ └── sqlParser.js └── sqlcache.js └── test ├── benchmark ├── ajoin.js ├── ijoin.js ├── join-test.js └── sql.js └── unit ├── resource └── test │ └── sources │ └── test.json ├── suite.DataTest.js ├── suite.JoinTest.js ├── suite.LexterTest.js ├── suite.SelectTest.js ├── suite.SqlCache.js ├── suite.SqlTest.js ├── suite.SumPluginTest.js └── suite.UrlTest.js /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xianbei/itier/04a11d3515f2186e35ec527aed6453fde3719f2c/README.md -------------------------------------------------------------------------------- /conf.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | version : '1.0', 4 | //run_mode : 'release', 5 | //logDirectory : __dirname + "/log/", 6 | run_mode : 'test', 7 | 8 | resourcesDirectory : __dirname + "/resources/", 9 | 10 | workerNumber : 1, 11 | 12 | port : 3459 13 | 14 | } 15 | -------------------------------------------------------------------------------- /config/mysql.js: -------------------------------------------------------------------------------- 1 | /* 2 | module.exports = { 3 | serverlist : "127.0.0.1", 4 | port : 3306, 5 | user : "root", 6 | password : "root", 7 | database : "db", 8 | maxSockets : 200, 9 | timeout : 1, 10 | cache :{ 11 | enable : false, 12 | timeout: 60 13 | } 14 | }; 15 | */ 16 | -------------------------------------------------------------------------------- /core/child_mng.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | require('./env'); 9 | 10 | var childs = []; 11 | var childStatus = []; 12 | var lastChildPos = -1; 13 | 14 | exports.push = function(c){ 15 | c.on('message', msgCtrlFactory(childs.length)); 16 | childs.push(c); 17 | } 18 | 19 | exports.getStatus = function(){ 20 | return childStatus; 21 | } 22 | 23 | /* 24 | *param [object] handle 25 | *dispatch the handle to childs by round-robin 26 | */ 27 | exports.disHandle = function(handle){ 28 | lastChildPos++; 29 | if(lastChildPos >= childs.length){ 30 | lastChildPos = 0; 31 | } 32 | childs[lastChildPos].send({'handle' : true}, handle); 33 | } 34 | 35 | exports.kill = function(pos){ 36 | pos = pos || -1; 37 | pos = parseInt(pos); 38 | if(pos < 0){ 39 | childs.forEach(function(c){ 40 | process.kill(c.pid); 41 | }); 42 | }else if(pos > 0 && pos < childs.length){ 43 | process.kill(childs[pos].pid); 44 | } 45 | } 46 | 47 | exports.updateStatus = function(){ 48 | childs.forEach(function(c){ 49 | c.send({status : 'update'}); 50 | }) 51 | } 52 | 53 | function simpleHash(str){ 54 | var sum = 0; 55 | for(var i=0; i 7 | 8 | var Debug = function(){ 9 | // 10 | } 11 | 12 | Debug.info = {}; 13 | 14 | /* 15 | *设置 16 | */ 17 | Debug.set = function(k, v){ 18 | Debug.info[k] = v; 19 | } 20 | 21 | /* 22 | *获取 23 | */ 24 | Debug.get = function(){ 25 | 26 | var k = ''; 27 | 28 | if(arguments.length == 1){ 29 | k = arguments[0]; 30 | } 31 | 32 | if(k && typeof Debug.info[k] != 'undefined'){ 33 | return Debug.info[k]; 34 | } 35 | 36 | return Debug.info; 37 | } 38 | 39 | /* 40 | *全部清空 41 | */ 42 | Debug.clean = function(){ 43 | Debug.info = {}; 44 | } 45 | 46 | exports.init=Debug; 47 | -------------------------------------------------------------------------------- /core/env.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | global.os = require('os'); 9 | global.fs = require('fs'); 10 | global.net = require('net'); 11 | global.http = require('http'); 12 | global.util = require('util'); 13 | //global.log = require('./log'); 14 | //global.App = require('./app_ctrl'); 15 | 16 | global.mode = 'DEBUG'; 17 | //global.mode = 'DEBUG'; 18 | 19 | global.debug = function(str){ 20 | if(mode == 'DEBUG') 21 | console.log(str); 22 | } 23 | 24 | global.output = function(str){ 25 | console.log(str); 26 | } 27 | 28 | global.inspect = function(obj){ 29 | if(mode == 'DEBUG') 30 | debug(util.inspect(obj)); 31 | } 32 | 33 | global.main = function(fn){ 34 | fn(); 35 | } 36 | 37 | global.isEmpty = function(obj){ 38 | for(var i in obj){ 39 | return false; 40 | } 41 | return true; 42 | } 43 | 44 | //shallow extend 45 | global.extend = function(des, src){ 46 | for(var key in src){ 47 | if(src.hasOwnProperty(key)) 48 | des[key] = src[key]; 49 | } 50 | } 51 | 52 | //shallow clone 53 | global.clone = function(obj){ 54 | var ret = {}; 55 | for(var key in obj){ 56 | if(obj.hasOwnProperty(key)) 57 | ret[key] = obj[key]; 58 | } 59 | return ret; 60 | } 61 | 62 | // the member function to be used as callback 63 | // and set 'this' as the context 64 | global.memcb = function(context, mem){ 65 | return function(){ 66 | context[mem].apply(context, arguments); 67 | } 68 | } 69 | 70 | /*this function will throw an exception , 71 | **so it will end the request ,I use this way to 72 | substitute the combination of : 73 | ** #1 send_error 74 | ** #2 return 75 | */ 76 | global.replyError = function(req, res, code ,info){ 77 | var map = { 78 | 404 : 'Not Found', 79 | 400 : 'Bad Request', 80 | 500 : 'Internal Server Error' 81 | } 82 | var err_str = map[code] || 'error occurred'; 83 | var body = info || err_str; 84 | res.writeHead(code , {'Content-Type' : 'text/plain'}); 85 | res.end(body.toString()); 86 | } 87 | 88 | //we throw this type of exception to 89 | //stop the process 90 | global.SExcp = function(err){ 91 | this.err = err; 92 | } 93 | 94 | //empty exception,just for jump out of process 95 | //maybe throwed by controllers 96 | global.NullExcp = function(){ 97 | this.type = 'null'; 98 | } 99 | 100 | //default we send http 500 error 101 | /* 102 | process.on('uncaughtException', function(obj) { 103 | if(obj instanceof NullExcp){ 104 | //log.error(obj.info); 105 | }else if(obj instanceof SExcp){ 106 | log.error(obj.err); 107 | process.exit(-1); 108 | }else{ 109 | log.excp(obj.stack + '\n'); 110 | } 111 | delete obj; 112 | }); 113 | */ 114 | //test the file's accessibility 115 | global.access = function(filepath){ 116 | var ok = true; 117 | try{ 118 | fs.readFileSync(filepath); 119 | }catch(e){ 120 | ok =false; 121 | } 122 | return ok; 123 | } 124 | 125 | //would be reset when require log.js 126 | 127 | global.log = { 128 | access : function(str){ 129 | console.log('[access]\t' + str + '\t'+ new Date()); 130 | }, 131 | excp : function(str){ 132 | console.log('[Excp]\t' + str + '\t'+ new Date()); 133 | }, 134 | error : function(str){ 135 | console.log('[Error]\t' + str + '\t'+ new Date()); 136 | }, 137 | warning : function(str){ 138 | console.log('[Warning]\t' + str + '\t' + new Date()); 139 | }, 140 | info : function(str){ 141 | console.log('[Info]\t' + str + '\t' + new Date()); 142 | } 143 | }; 144 | 145 | 146 | -------------------------------------------------------------------------------- /core/tcpMaster.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | require('./env'); 9 | var cp = require('child_process'); 10 | var TCP = process.binding('tcp_wrap').TCP; 11 | var childMng = require("./child_mng"); 12 | var conf = require('../conf'); 13 | 14 | //user settings 15 | //var ADDRESS = '0.0.0.0'; 16 | var PORT = conf.port; 17 | var WORKER_NUMBER = conf.workerNumber; 18 | 19 | var GRACE_EXIT_TIME = 2000;//2s 20 | var WORKER_PATH = __dirname + '/tcpWorker.js'; 21 | var WORKER_HEART_BEAT = 10*1000;//10s, update memory ,etc 22 | 23 | function startWorker(){ 24 | for(var i = 0; i < WORKER_NUMBER; i++){ 25 | var c = cp.fork(WORKER_PATH); 26 | childMng.push(c); 27 | } 28 | output('start workers: ' + WORKER_NUMBER); 29 | /* 30 | setInterval(function(){ 31 | inspect(childMng.getStatus()); 32 | childMng.updateStatus(); 33 | },WORKER_HEART_BEAT); 34 | */ 35 | } 36 | 37 | var server = null; 38 | var exitTimer = null; 39 | function aboutExit(){ 40 | if(exitTimer) return; 41 | 42 | server.close(); 43 | childMng.kill(); 44 | 45 | exitTimer = setTimeout(function(){ 46 | output('master exit...'); 47 | 48 | //log.destroy(); 49 | process.exit(0); 50 | }, GRACE_EXIT_TIME); 51 | } 52 | 53 | //var ADDRESS = '127.0.0.1'; 54 | var ADDRESS = '0.0.0.0'; 55 | var BACK_LOG = 128; 56 | 57 | function onconnection(handle){ 58 | //output('master on connection'); 59 | childMng.disHandle(handle); 60 | handle.close(); 61 | } 62 | 63 | function startServer(){ 64 | output('will bind port'); 65 | server = new TCP(); 66 | 67 | server.bind(ADDRESS, PORT); 68 | server.onconnection = onconnection; 69 | server.listen(BACK_LOG); 70 | output('bind ok'); 71 | } 72 | 73 | void main(function(){ 74 | 75 | startServer(); 76 | startWorker(); 77 | 78 | output('master is running...'); 79 | process.on('SIGINT' , aboutExit); 80 | process.on('SIGTERM' , aboutExit); 81 | 82 | }); 83 | -------------------------------------------------------------------------------- /core/tcpWorker.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | require('./env'); 9 | var dispatch = require('../src/dispatch').fn; 10 | var net = require('net'); 11 | var http = require('http'); 12 | 13 | var GRACE_EXIT_TIME = 1500; 14 | 15 | var server = null; 16 | var exitTimer = null; 17 | var childReqCount = 0; 18 | 19 | function aboutExit(){ 20 | if(exitTimer) return; 21 | 22 | //server.close(); 23 | exitTimer = setTimeout(function(){ 24 | output('worker will exit...'); 25 | output('child req total : ' + childReqCount); 26 | 27 | process.exit(0); 28 | },GRACE_EXIT_TIME); 29 | } 30 | 31 | function onhandle(self, handle){ 32 | if(self.maxConnections && self.connections >= self.maxConnections){ 33 | handle.close(); 34 | return; 35 | } 36 | var socket = new net.Socket({ 37 | handle : handle, 38 | allowHalfOpen : self.allowHalfOpen 39 | }); 40 | socket.readable = socket.writable = true; 41 | socket.resume(); 42 | self.connections++; 43 | socket.server = self; 44 | self.emit('connection', socket); 45 | socket.emit('connect'); 46 | //output('get a connection'); 47 | } 48 | 49 | function processInit(){ 50 | output('worker init now...'); 51 | process.on("SIGINT" ,aboutExit); 52 | process.on("SIGTERM" ,aboutExit); 53 | 54 | var conf = require('../conf'); 55 | var loadCfg = require("../src/hotcfg").Cfg3; 56 | loadCfg(conf.resourcesDirectory, 'ActionLoader'); 57 | 58 | //init memcache socket pool 59 | var MCfg = conf.mcskin; 60 | if(MCfg){ 61 | global.MCSkin = require("mcskin"); 62 | global.MCSkin.init(MCfg.host, MCfg.port, MCfg.maxSockets); 63 | } 64 | if(conf.run_mode == 'release'){ 65 | global.log = require('./log'); 66 | } 67 | 68 | process.on('message',function(m ,handle){ 69 | if(handle){ 70 | onhandle(server, handle); 71 | } 72 | if(m.status == 'update'){ 73 | process.send({'status' : process.memoryUsage()}); 74 | } 75 | }); 76 | } 77 | 78 | void main(function(){ 79 | 80 | processInit(); 81 | 82 | server = http.createServer(function(req, res){ 83 | var dis = dispatch(req, res); 84 | dis.load(); 85 | childReqCount++; 86 | }); 87 | 88 | 89 | output('worker is running...'); 90 | }); 91 | -------------------------------------------------------------------------------- /core/watcher.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | 9 | var SqlCache = require("../src/sqlcache"); 10 | 11 | function debug(str){ 12 | console.log(str); 13 | } 14 | 15 | function inspect(obj){ 16 | console.log(require("util").inspect(obj)); 17 | } 18 | 19 | exports.notify = function(jobId, path, jsonData){ 20 | 21 | //check is action/config directory 22 | //debug(path); 23 | if(jobId == "ActionLoader"){ 24 | var parr = path.split("/"); 25 | var len = parr.length; 26 | if(len >= 3){ 27 | var key = parr[len-3] + "/" + parr[len-2] +"/" + parr[len-1]; 28 | key = key.substr(0, key.lastIndexOf(".")); 29 | 30 | var obj = { 31 | path : key, 32 | actions : jsonData 33 | }; 34 | try{ 35 | SqlCache.set(obj); 36 | }catch(e){ 37 | log.excp(e.stack); 38 | } 39 | //inspect(obj); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /itier_developerclub_2012_beijing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xianbei/itier/04a11d3515f2186e35ec527aed6453fde3719f2c/itier_developerclub_2012_beijing.pdf -------------------------------------------------------------------------------- /node_modules/.bin/jake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | * Jake JavaScript build tool 4 | * Copyright 2112 Matthew Eernisse (mde@fleegix.org) 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | var args = process.argv.slice(2) 21 | , libPath = __dirname + '/../lib' 22 | , fs = require('fs') 23 | , jake = require(libPath + '/jake.js') 24 | , api = require(libPath + '/api.js') 25 | , utils = require(libPath + '/utils.js') 26 | , Program = require(libPath + '/program.js').Program 27 | , program = new Program() 28 | , Loader = require(libPath + '/loader.js').Loader 29 | , loader = new Loader() 30 | , pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString()) 31 | , opts 32 | , envVars 33 | , taskNames; 34 | 35 | jake.version = pkg.version; 36 | 37 | global.jake = jake; 38 | 39 | process.addListener('uncaughtException', function (err) { 40 | program.handleErr(err); 41 | }); 42 | 43 | program.parseArgs(args); 44 | 45 | if (!program.preemptiveOption()) { 46 | opts = program.opts 47 | envVars = program.envVars; 48 | 49 | // Globalize top-level API methods (e.g., `task`, `desc`) 50 | for (var p in api) { 51 | global[p] = api[p]; 52 | } 53 | 54 | // Convenience aliases 55 | jake.opts = opts; 56 | for (var p in utils) { 57 | jake[p] = utils[p]; 58 | } 59 | jake.FileList = require(libPath + '/file_list').FileList; 60 | jake.PackageTask = require(libPath + '/package_task').PackageTask; 61 | jake.NpmPublishTask = require(libPath + '/npm_publish_task').NpmPublishTask; 62 | 63 | // Enhance env with any env vars passed in 64 | for (var p in envVars) { process.env[p] = envVars[p]; } 65 | 66 | loader.load(opts.jakefile); 67 | 68 | // Set working dir 69 | var dirname = opts.directory; 70 | if (dirname) { 71 | process.chdir(dirname); 72 | } 73 | 74 | taskNames = program.taskNames; 75 | taskNames = taskNames.length ? taskNames : ['default']; 76 | task('__root__', taskNames, function () {}); 77 | 78 | if (opts.tasks) { 79 | jake.showAllTaskDescriptions(opts.tasks); 80 | } 81 | else { 82 | jake.Task['__root__'].invoke(); 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /node_modules/generic-pool/.gitignore: -------------------------------------------------------------------------------- 1 | fabfile.pyc 2 | node-pool.iml 3 | node-pool.tmproj 4 | -------------------------------------------------------------------------------- /node_modules/generic-pool/fabfile.py: -------------------------------------------------------------------------------- 1 | # 2 | # dependencies: 3 | # fabric (apt-get install fabric) 4 | # node-jslint (http://github.com/reid/node-jslint) 5 | # expresso (or replace with whatever node.js test tool you're using) 6 | # 7 | 8 | from fabric.api import local 9 | import os, os.path 10 | 11 | def test(): 12 | local('expresso -I lib test/*', capture=False) 13 | 14 | def jslint(): 15 | ignore = [ "/lib-cov/" ] 16 | for root, subFolders, files in os.walk("."): 17 | for file in files: 18 | if file.endswith(".js"): 19 | filename = os.path.join(root,file) 20 | processFile = True 21 | for i in ignore: 22 | if filename.find(i) != -1: 23 | processFile = False 24 | if processFile: 25 | print filename 26 | local('jslint %s' % filename, capture=False) 27 | 28 | -------------------------------------------------------------------------------- /node_modules/generic-pool/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generic-pool", 3 | "description": "Generic resource pooling for Node.JS", 4 | "version": "1.0.7", 5 | "author": "James Cooper ", 6 | "contributors": [ 7 | { "name": "James Cooper", "email": "james@bitmechanic.com" }, 8 | { "name": "Peter Galiba", "email": "poetro@poetro.hu", "url": "http://poetro.hu/" }, 9 | { "name": "Gary Dusbabek" }, 10 | { "name": "Tom MacWright", "url" : "http://www.developmentseed.org/" } 11 | ], 12 | "keywords": ["pool", "pooling", "throttle"], 13 | "main": "lib/generic-pool.js", 14 | "repository": { 15 | "type": "git", 16 | "url": "http://github.com/coopernurse/node-pool.git" 17 | }, 18 | "engines": { "node": ">= 0.2.0" } 19 | } 20 | -------------------------------------------------------------------------------- /node_modules/jake/Jakefile: -------------------------------------------------------------------------------- 1 | 2 | desc('Runs the Jake tests.'); 3 | task('test', function () { 4 | cmds = [ 5 | 'node ./tests/parseargs.js' 6 | , 'node ./tests/task_base.js' 7 | , 'node ./tests/file_task.js' 8 | ]; 9 | jake.exec(cmds, function () { 10 | console.log('All tests passed.'); 11 | complete(); 12 | }, {stdout: true}); 13 | }); 14 | 15 | var p = new jake.NpmPublishTask('jake', [ 16 | 'Makefile' 17 | , 'Jakefile' 18 | , 'README.md' 19 | , 'package.json' 20 | , 'lib/*' 21 | , 'bin/*' 22 | , 'tests/*' 23 | ]); 24 | 25 | jake.Task['npm:definePackage'].invoke(); 26 | 27 | -------------------------------------------------------------------------------- /node_modules/jake/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Jake JavaScript build tool 3 | # Copyright 2112 Matthew Eernisse (mde@fleegix.org) 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | .PHONY: all build install clean uninstall 19 | 20 | PREFIX=/usr/local 21 | DESTDIR= 22 | 23 | all: build 24 | 25 | build: 26 | @echo 'Jake built.' 27 | 28 | install: 29 | @mkdir -p $(DESTDIR)$(PREFIX)/bin \ 30 | mkdir -p $(DESTDIR)$(PREFIX)/lib/node_modules/jake && \ 31 | cp -R ./* $(DESTDIR)$(PREFIX)/lib/node_modules/jake/ && \ 32 | ln -snf $(DESTDIR)$(PREFIX)/lib/node_modules/jake/bin/cli.js $(DESTDIR)$(PREFIX)/bin/jake && \ 33 | chmod 755 $(DESTDIR)$(PREFIX)/lib/node_modules/jake/bin/cli.js && \ 34 | echo 'Jake installed.' 35 | 36 | clean: 37 | @true 38 | 39 | uninstall: 40 | @rm -f $(DESTDIR)$(PREFIX)/bin/jake && \ 41 | rm -fr $(DESTDIR)$(PREFIX)/lib/node_modules/jake/ && \ 42 | echo 'Jake uninstalled.' 43 | -------------------------------------------------------------------------------- /node_modules/jake/bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /* 3 | * Jake JavaScript build tool 4 | * Copyright 2112 Matthew Eernisse (mde@fleegix.org) 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | var args = process.argv.slice(2) 21 | , libPath = __dirname + '/../lib' 22 | , fs = require('fs') 23 | , jake = require(libPath + '/jake.js') 24 | , api = require(libPath + '/api.js') 25 | , utils = require(libPath + '/utils.js') 26 | , Program = require(libPath + '/program.js').Program 27 | , program = new Program() 28 | , Loader = require(libPath + '/loader.js').Loader 29 | , loader = new Loader() 30 | , pkg = JSON.parse(fs.readFileSync(__dirname + '/../package.json').toString()) 31 | , opts 32 | , envVars 33 | , taskNames; 34 | 35 | jake.version = pkg.version; 36 | 37 | global.jake = jake; 38 | 39 | process.addListener('uncaughtException', function (err) { 40 | program.handleErr(err); 41 | }); 42 | 43 | program.parseArgs(args); 44 | 45 | if (!program.preemptiveOption()) { 46 | opts = program.opts 47 | envVars = program.envVars; 48 | 49 | // Globalize top-level API methods (e.g., `task`, `desc`) 50 | for (var p in api) { 51 | global[p] = api[p]; 52 | } 53 | 54 | // Convenience aliases 55 | jake.opts = opts; 56 | for (var p in utils) { 57 | jake[p] = utils[p]; 58 | } 59 | jake.FileList = require(libPath + '/file_list').FileList; 60 | jake.PackageTask = require(libPath + '/package_task').PackageTask; 61 | jake.NpmPublishTask = require(libPath + '/npm_publish_task').NpmPublishTask; 62 | 63 | // Enhance env with any env vars passed in 64 | for (var p in envVars) { process.env[p] = envVars[p]; } 65 | 66 | loader.load(opts.jakefile); 67 | 68 | // Set working dir 69 | var dirname = opts.directory; 70 | if (dirname) { 71 | process.chdir(dirname); 72 | } 73 | 74 | taskNames = program.taskNames; 75 | taskNames = taskNames.length ? taskNames : ['default']; 76 | task('__root__', taskNames, function () {}); 77 | 78 | if (opts.tasks) { 79 | jake.showAllTaskDescriptions(opts.tasks); 80 | } 81 | else { 82 | jake.Task['__root__'].invoke(); 83 | } 84 | } 85 | 86 | -------------------------------------------------------------------------------- /node_modules/jake/lib/api.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Jake JavaScript build tool 3 | * Copyright 2112 Matthew Eernisse (mde@fleegix.org) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | var exec = require('child_process').exec; 19 | 20 | var api = new (function () { 21 | this.task = function (name, prereqs, action, async) { 22 | var args = Array.prototype.slice.call(arguments) 23 | , type; 24 | args.unshift('task'); 25 | jake.createTask.apply(global, args); 26 | jake.currentTaskDescription = null; 27 | }; 28 | 29 | this.directory = function (name) { 30 | var args = Array.prototype.slice.call(arguments); 31 | args.unshift('directory'); 32 | jake.createTask.apply(global, args); 33 | jake.currentTaskDescription = null; 34 | }; 35 | 36 | this.file = function (name, prereqs, action, async) { 37 | var args = Array.prototype.slice.call(arguments); 38 | args.unshift('file'); 39 | jake.createTask.apply(global, args); 40 | jake.currentTaskDescription = null; 41 | }; 42 | 43 | this.desc = function (str) { 44 | jake.currentTaskDescription = str; 45 | }; 46 | 47 | this.namespace = function (name, nextLevelDown) { 48 | var curr = jake.currentNamespace 49 | , ns = new jake.Namespace(name, curr); 50 | curr.childNamespaces[name] = ns; 51 | jake.currentNamespace = ns; 52 | nextLevelDown(); 53 | jake.currentNamespace = curr; 54 | jake.currentTaskDescription = null; 55 | }; 56 | 57 | this.complete = function () { 58 | var current = jake._invocationChain.pop(); 59 | if (current) { 60 | current.complete(); 61 | } 62 | }; 63 | 64 | this.fail = function (err, code) { 65 | if (code) { 66 | jake.errorCode = code; 67 | } 68 | if (err) { 69 | if (typeof err == 'string') { 70 | throw new Error(err); 71 | } 72 | else if (err instanceof Error) { 73 | throw err; 74 | } 75 | else { 76 | throw new Error(err.toString()); 77 | } 78 | } 79 | else { 80 | throw new Error(); 81 | } 82 | }; 83 | 84 | })(); 85 | 86 | module.exports = api; 87 | -------------------------------------------------------------------------------- /node_modules/jake/lib/loader.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Jake JavaScript build tool 3 | * Copyright 2112 Matthew Eernisse (mde@fleegix.org) 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | var path = require('path') 20 | , Loader; 21 | 22 | 23 | Loader = function () { 24 | this.load = function (file) { 25 | var jakefile = file ? 26 | file.replace(/\.js$/, '').replace(/\.coffee$/, '') : 'Jakefile' 27 | , fileSpecified = !!file 28 | // Dear God, why? 29 | , isCoffee = false 30 | // Warning, recursive 31 | , exists = function () { 32 | var cwd = process.cwd(); 33 | if (path.existsSync(jakefile) || path.existsSync(jakefile + '.js') || 34 | path.existsSync(jakefile + '.coffee')) { 35 | return true; 36 | } 37 | if (!fileSpecified) { 38 | process.chdir(".."); 39 | if (cwd === process.cwd()) { 40 | return false; 41 | } 42 | return exists(); 43 | } 44 | }; 45 | 46 | if (!exists()) { 47 | fail('No Jakefile. Specify a valid path with -f/--jakefile, or place one in the current directory.'); 48 | } 49 | 50 | isCoffee = path.existsSync(jakefile + '.coffee'); 51 | if (isCoffee) { 52 | try { 53 | CoffeeScript = require('coffee-script'); 54 | } 55 | catch (e) { 56 | fail('CoffeeScript is missing! Try `npm install coffee-script`'); 57 | } 58 | } 59 | if (jakefile.indexOf('/') != 0) { 60 | jakefile = path.join(process.cwd(), jakefile); 61 | } 62 | require(jakefile); 63 | }; 64 | 65 | }; 66 | 67 | module.exports.Loader = Loader; 68 | -------------------------------------------------------------------------------- /node_modules/jake/lib/task/directory_task.js: -------------------------------------------------------------------------------- 1 | var DirectoryTask 2 | , FileTask = require('./file_task').FileTask; 3 | 4 | DirectoryTask = function (name, prereqs, action, opts) { 5 | this.modTime = null; 6 | this.constructor.prototype.initialize.apply(this, arguments); 7 | }; 8 | DirectoryTask.prototype = new FileTask(); 9 | DirectoryTask.prototype.constructor = DirectoryTask; 10 | 11 | exports.DirectoryTask = DirectoryTask; 12 | -------------------------------------------------------------------------------- /node_modules/jake/lib/task/file_task.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs') 2 | , Task = require('./task').Task 3 | , FileTask 4 | , FileBase 5 | , DirectoryTask 6 | , utils = require('../utils'); 7 | 8 | FileBase = new (function () { 9 | var isFileOrDirectory = function (t) { 10 | return (t instanceof FileTask || 11 | t instanceof DirectoryTask); 12 | } 13 | , isFile = function (t) { 14 | return (t instanceof FileTask && !(t instanceof DirectoryTask)); 15 | }; 16 | 17 | this.shouldRunAction = function () { 18 | var runAction = false 19 | , prereqs = this.prereqs 20 | , prereqName 21 | , prereqTask; 22 | 23 | // No repeatsies 24 | if (this.done) { 25 | return false; 26 | } 27 | // The always-make override 28 | else if (jake.opts['always-make']) { 29 | // Run if there actually is an action 30 | if (typeof this.action == 'function') { 31 | return true; 32 | } 33 | else { 34 | return false; 35 | } 36 | } 37 | // Default case 38 | else { 39 | // We need either an existing file, or an action to create one. 40 | // First try grabbing the actual mod-time of the file 41 | try { 42 | this.updateModTime(); 43 | } 44 | // Then fall back to looking for an action 45 | catch(e) { 46 | if (typeof this.action == 'function') { 47 | return true; 48 | } 49 | else { 50 | throw new Error('File-task ' + this.fullName + ' has no ' + 51 | 'existing file, and no action to create one.'); 52 | } 53 | } 54 | 55 | // Compare mod-time of all the prereqs with its mod-time 56 | // If any prereqs are newer, need to run the action to update 57 | if (prereqs && prereqs.length) { 58 | for (var i = 0, ii = prereqs.length; i < ii; i++) { 59 | prereqName = prereqs[i]; 60 | prereqTask = jake.Task[prereqName]; 61 | // Run the action if: 62 | // 1. The prereq is a normal task (not file/dir) 63 | // 2. The prereq is a file-task with a mod-date more recent than 64 | // the one for this file/dir 65 | if (prereqTask) { 66 | if (!isFileOrDirectory(prereqTask) || 67 | (isFile(prereqTask) && prereqTask.modTime > this.modTime)) { 68 | return true; 69 | } 70 | } 71 | } 72 | } 73 | // File/dir has no prereqs, and exists -- no need to run 74 | else { 75 | return false; 76 | } 77 | } 78 | }; 79 | 80 | this.updateModTime = function () { 81 | var stats = fs.statSync(this.name); 82 | this.modTime = stats.mtime; 83 | }; 84 | 85 | this.complete = function () { 86 | this.updateModTime(); 87 | this.done = true; 88 | this.emit('complete'); 89 | }; 90 | 91 | })(); 92 | 93 | FileTask = function (name, prereqs, action, opts) { 94 | this.modTime = null; 95 | this.constructor.prototype.initialize.apply(this, arguments); 96 | }; 97 | FileTask.prototype = new Task(); 98 | FileTask.prototype.constructor = FileTask; 99 | utils.mixin(FileTask.prototype, FileBase); 100 | 101 | exports.FileTask = FileTask; 102 | 103 | // DirectoryTask is a subclass of FileTask, depends on it 104 | // being defined 105 | DirectoryTask = require('./directory_task').DirectoryTask; 106 | 107 | -------------------------------------------------------------------------------- /node_modules/jake/lib/task/index.js: -------------------------------------------------------------------------------- 1 | 2 | var Task = require('./task').Task 3 | , FileTask = require('./file_task').FileTask 4 | , DirectoryTask = require('./directory_task').DirectoryTask; 5 | 6 | exports.Task = Task; 7 | exports.FileTask = FileTask; 8 | exports.DirectoryTask = DirectoryTask; 9 | 10 | -------------------------------------------------------------------------------- /node_modules/jake/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jake", 3 | "version": "0.2.10", 4 | "author": "Matthew Eernisse (http://fleegix.org)", 5 | "bin": { 6 | "jake": "./bin/cli.js" 7 | }, 8 | "main": "./lib", 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/mde/jake.git" 12 | }, 13 | "preferGlobal": true, 14 | "dependencies": {}, 15 | "devDependencies": {}, 16 | "engines": { 17 | "node": "*" 18 | } 19 | } -------------------------------------------------------------------------------- /node_modules/jake/tests/file_task.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert') 2 | , fs = require('fs') 3 | , exec = require('child_process').exec 4 | , h = require('./helpers'); 5 | 6 | process.chdir('./tests'); 7 | 8 | var cleanUpAndNext = function () { 9 | exec('rm -fr ./foo', function (err, stdout, stderr) { 10 | if (err) { throw err } 11 | if (stderr || stdout) { 12 | console.log (stderr || stdout); 13 | } 14 | h.next(); 15 | }); 16 | }; 17 | 18 | var tests = new (function () { 19 | this.testConcatTwoFiles = function () { 20 | h.exec('../bin/cli.js fileTest:foo/concat.txt', function (out) { 21 | var data; 22 | assert.equal('fileTest:foo/src1.txt task\ndefault task\nfileTest:foo/src2.txt task\n' + 23 | 'fileTest:foo/concat.txt task', out); 24 | // Check to see the two files got concat'd 25 | data = fs.readFileSync(process.cwd() + '/foo/concat.txt'); 26 | assert.equal('src1src2', data.toString()); 27 | cleanUpAndNext(); 28 | }); 29 | }; 30 | 31 | this.testNoPrereqChange = function () { 32 | h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) { 33 | assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task', 34 | out); 35 | h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) { 36 | // Second time should be a no-op 37 | assert.equal('', out); 38 | cleanUpAndNext(); 39 | }); 40 | }); 41 | }; 42 | 43 | this.testNoPrereqChangeAlwaysMake = function () { 44 | h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) { 45 | assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task', 46 | out); 47 | h.exec('../bin/cli.js -B fileTest:foo/from-src1.txt', function (out) { 48 | assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task', 49 | out); 50 | cleanUpAndNext(); 51 | }); 52 | }); 53 | }; 54 | 55 | this.testPreexistingFile = function () { 56 | var prereqData = 'howdy'; 57 | h.exec('mkdir -p foo', function (out) { 58 | fs.writeFileSync('foo/prereq.txt', prereqData); 59 | h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) { 60 | var data; 61 | assert.equal('fileTest:foo/from-prereq.txt task', out); 62 | data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt'); 63 | assert.equal(prereqData, data.toString()); 64 | cleanUpAndNext(); 65 | }); 66 | }); 67 | }; 68 | 69 | this.testPreexistingFileAlwaysMake = function () { 70 | var prereqData = 'howdy'; 71 | h.exec('mkdir -p foo', function (out) { 72 | fs.writeFileSync('foo/prereq.txt', prereqData); 73 | h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) { 74 | var data; 75 | assert.equal('fileTest:foo/from-prereq.txt task', out); 76 | data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt'); 77 | assert.equal(prereqData, data.toString()); 78 | h.exec('../bin/cli.js -B fileTest:foo/from-prereq.txt', function (out) { 79 | assert.equal('fileTest:foo/from-prereq.txt task', out); 80 | cleanUpAndNext(); 81 | }); 82 | }); 83 | }); 84 | }; 85 | 86 | })(); 87 | 88 | h.run(tests, function () { 89 | process.chdir('../'); 90 | }); 91 | 92 | 93 | -------------------------------------------------------------------------------- /node_modules/jake/tests/helpers.js: -------------------------------------------------------------------------------- 1 | var exec = require('child_process').exec; 2 | 3 | var helpers = new (function () { 4 | var _tests 5 | , _names = [] 6 | , _name 7 | , _callback 8 | , _runner = function () { 9 | if (!!(_name = _names.shift())) { 10 | console.log('Running ' + _name); 11 | _tests[_name](); 12 | } 13 | else { 14 | _callback(); 15 | } 16 | }; 17 | 18 | this.exec = function (cmd, callback) { 19 | exec(cmd, function (err, stdout, stderr) { 20 | var out = helpers.trim(stdout); 21 | if (err) { 22 | throw err; 23 | } 24 | if (stderr) { 25 | callback(stderr); 26 | } 27 | else { 28 | callback(out); 29 | } 30 | }); 31 | }; 32 | 33 | this.trim = function (s) { 34 | var str = s || ''; 35 | return str.replace(/^\s*|\s*$/g, ''); 36 | }; 37 | 38 | this.parse = function (s) { 39 | var str = s || ''; 40 | str = helpers.trim(str); 41 | str = str.replace(/'/g, '"'); 42 | return JSON.parse(str); 43 | }; 44 | 45 | this.run = function (tests, callback) { 46 | _tests = tests; 47 | _names = Object.keys(tests); 48 | _callback = callback; 49 | _runner(); 50 | }; 51 | 52 | this.next = function () { 53 | _runner(); 54 | }; 55 | 56 | })(); 57 | 58 | module.exports = helpers; 59 | -------------------------------------------------------------------------------- /node_modules/jake/tests/task_base.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert') 2 | , h = require('./helpers'); 3 | 4 | process.chdir('./tests'); 5 | 6 | var tests = new (function () { 7 | this.testDefault = function () { 8 | h.exec('../bin/cli.js', function (out) { 9 | assert.equal('default task', out); 10 | }); 11 | 12 | h.exec('../bin/cli.js default', function (out) { 13 | assert.equal('default task', out); 14 | }); 15 | h.next(); 16 | }; 17 | 18 | this.testNoAction = function () { 19 | h.exec('../bin/cli.js noAction', function (out) { 20 | assert.equal('default task', out); 21 | }); 22 | h.next(); 23 | }; 24 | 25 | this.testNoActionNoPrereqs = function () { 26 | h.exec('../bin/cli.js noActionNoPrereqs', function () {}); 27 | h.next(); 28 | }; 29 | 30 | this.testWithArgs = function () { 31 | h.exec('../bin/cli.js argsEnvVars[foo,bar]', function (out) { 32 | var parsed = h.parse(out) 33 | , args = parsed.args; 34 | assert.equal(args[0], 'foo'); 35 | assert.equal(args[1], 'bar'); 36 | }); 37 | h.next(); 38 | }; 39 | 40 | this.testWithEnvVars = function () { 41 | h.exec('../bin/cli.js argsEnvVars foo=bar baz=qux', function (out) { 42 | var parsed = h.parse(out) 43 | , env = parsed.env; 44 | assert.equal(env.foo, 'bar'); 45 | assert.equal(env.baz, 'qux'); 46 | }); 47 | h.next(); 48 | }; 49 | 50 | this.testWithArgsAndEnvVars = function () { 51 | h.exec('../bin/cli.js argsEnvVars[foo,bar] foo=bar baz=qux', function (out) { 52 | var parsed = h.parse(out) 53 | , args = parsed.args 54 | , env = parsed.env; 55 | assert.equal(args[0], 'foo'); 56 | assert.equal(args[1], 'bar'); 57 | assert.equal(env.foo, 'bar'); 58 | assert.equal(env.baz, 'qux'); 59 | }); 60 | h.next(); 61 | }; 62 | 63 | this.testPrereq = function () { 64 | h.exec('../bin/cli.js foo:baz', function (out) { 65 | assert.equal('foo:bar task\nfoo:baz task', out); 66 | }); 67 | h.next(); 68 | }; 69 | 70 | this.testPrereqWithCmdlineArgs = function () { 71 | h.exec('../bin/cli.js foo:qux', function (out) { 72 | assert.equal('foo:bar[asdf,qwer] task\nfoo:qux task', out); 73 | }); 74 | h.next(); 75 | }; 76 | 77 | this.testPrereqWithArgsViaInvoke = function () { 78 | h.exec('../bin/cli.js foo:frang[zxcv,uiop]', function (out) { 79 | assert.equal('foo:bar[zxcv,uiop] task\nfoo:frang task', out); 80 | }); 81 | h.next(); 82 | }; 83 | 84 | this.testPrereqOrdering = function () { 85 | h.exec('../bin/cli.js hoge:fuga', function (out) { 86 | assert.equal('hoge:hoge task\nhoge:piyo task\nhoge:fuga task', out); 87 | }); 88 | h.next(); 89 | }; 90 | 91 | this.testAsync = function () { 92 | h.exec('../bin/cli.js bar:bar', function (out) { 93 | assert.equal('bar:foo task\nbar:bar task', out); 94 | }); 95 | h.next(); 96 | }; 97 | 98 | })(); 99 | 100 | h.run(tests, function () { 101 | process.chdir('../'); 102 | }); 103 | 104 | -------------------------------------------------------------------------------- /node_modules/mcskin/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./mcskin'); 2 | -------------------------------------------------------------------------------- /node_modules/mcskin/mctest.js: -------------------------------------------------------------------------------- 1 | var MCSkin = require("./mcskin.js"); 2 | 3 | var util = require("util"); 4 | function debug(obj){ 5 | console.log(util.inspect(obj)); 6 | } 7 | //debug(MCSkin); 8 | var MCfg = require("../../config/mcskin"); 9 | MCSkin.init(MCfg.host, MCfg.port, MCfg.maxSockets); 10 | 11 | const TEST_NUMBER = 1; 12 | var count = 0; 13 | /* 14 | MCSkin.set("helo", "asd", function(err ,data){ 15 | if(err){ 16 | console.log(err); 17 | }else{ 18 | console.log("set " + data); 19 | } 20 | 21 | }); 22 | */ 23 | var obj = { ti: '宝贝2, BEGIN{c81e728d9d4c2f636f067f89cc14862c} END', 24 | id: '2', 25 | pu: 'i2/3e0/610/T127pdXeqQA0JXXXXX.jpg' }; 26 | 27 | var val_str = JSON.stringify(obj); 28 | 29 | function benchGet(){ 30 | var start = new Date(); 31 | var end; 32 | for(var i=0;i= TEST_NUMBER){ 41 | end = new Date(); 42 | console.log("time : " + (new Date() - start)); 43 | console.log(data); 44 | 45 | MCSkin.delete("helo", function(err, data){ 46 | MCSkin.destroy(); 47 | if(err){ 48 | console.log(err); 49 | } 50 | 51 | }); 52 | } 53 | }) 54 | } 55 | } 56 | 57 | /* 58 | setInterval(function(){ 59 | if(count <= TEST_NUMBER){ 60 | console.log("count : " + count); 61 | } 62 | console.log( "rss : " + process.memoryUsage().rss); 63 | }, 10000); 64 | */ 65 | 66 | var key_str = "mysql:select * from meta_user_info where id =1"; 67 | key_str = key_str.replace(/ /g, "%20"); 68 | console.log(key_str); 69 | setTimeout(function(){ 70 | MCSkin.set(key_str ,val_str ,function(err ,data){ 71 | if(err) 72 | console.log(err); 73 | else 74 | console.log("set ok"); 75 | }); 76 | 77 | 78 | benchGet(); 79 | 80 | }, 1000); 81 | -------------------------------------------------------------------------------- /node_modules/mcskin/node_modules/memcache/.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.swp 3 | -------------------------------------------------------------------------------- /node_modules/mcskin/node_modules/memcache/Makefile: -------------------------------------------------------------------------------- 1 | NODE = node 2 | TEST = expresso 3 | TESTS ?= test/*.js 4 | 5 | test: 6 | @CONNECT_ENV=test $(TEST) \ 7 | -I lib \ 8 | $(TEST_FLAGS) $(TESTS) 9 | 10 | test-cov: 11 | @$(MAKE) test TEST_FLAGS="--cov" 12 | 13 | .PHONY: test test-cov 14 | -------------------------------------------------------------------------------- /node_modules/mcskin/node_modules/memcache/README.md: -------------------------------------------------------------------------------- 1 | node.js memcached client 2 | ======================== 3 | 4 | A pure-JavaScript memcached library for node. 5 | 6 | 7 | Tests 8 | ----- 9 | 10 | To run the test suite, first insall expresso, 11 | then run make test. 12 | 13 | If you have node-jscoverage you can 14 | also make test-cov for coverage, but that's pretty nerdy. 15 | 16 | 17 | Usage 18 | ----- 19 | 20 | Create a Client object to start working. 21 | Host and port can be passed to the constructor or set afterwards. 22 | They have sensible defaults. 23 | 24 | var memcache = require('./memcache'); 25 | 26 | var client = new memcache.Client(port, host); 27 | client.port = 11211; 28 | client.host = 'localhost'; 29 | 30 | The Client object emits 4 important events - connect, close, timeout and error. 31 | 32 | client.on('connect', function(){ 33 | // no arguments - we've connected 34 | }); 35 | 36 | client.on('close', function(){ 37 | // no arguments - connection has been closed 38 | }); 39 | 40 | client.on('timeout', function(){ 41 | // no arguments - socket timed out 42 | }); 43 | 44 | client.on('error', function(e){ 45 | // there was an error - exception is 1st argument 46 | }); 47 | 48 | After connecting, you can start to make requests. 49 | 50 | client.get('key', function(result, error){ 51 | 52 | // all of the callbacks have two arguments. 53 | // 'result' may contain things which aren't great, but 54 | // aren't really errors, like 'NOT_STORED' 55 | 56 | }); 57 | 58 | client.set('key', 'value', function(result, error){ 59 | 60 | // lifetime is optional. the default is 61 | // to never expire (0) 62 | 63 | }, lifetime); 64 | 65 | client.delete('key', function(result, error){ 66 | 67 | // delete a key from cache. 68 | }); 69 | 70 | client.version(function(result, error)){ 71 | 72 | // grab the server version 73 | }); 74 | 75 | 76 | There are all the commands you would expect. 77 | 78 | // all of the different "store" operations 79 | // (lifetime & flags are both optional) 80 | client.set(key, value, callback, lifetime, flags); 81 | client.add(key, value, callback, lifetime, flags); 82 | client.replace(key, value, callback, lifetime, flags); 83 | client.append(key, value, callback, lifetime, flags); 84 | client.prepend(key, value, callback, lifetime, flags); 85 | client.cas(key, value, unique, callback, lifetime, flags); 86 | 87 | // increment and decrement (named differently to the server commands - for now!) 88 | // (value is optional, defaults to 1) 89 | client.increment('key', value, callback); 90 | client.decrement('key', value, callback); 91 | 92 | // statistics. the success argument to the callback 93 | // is a key=>value object 94 | client.stats(callback); 95 | client.stats('settings', callback); 96 | client.stats('items', callback); 97 | client.stats('mongeese', callback); 98 | 99 | Once you're done, close the connection. 100 | 101 | client.close(); 102 | 103 | There might be bugs. I'd like to know about them. 104 | 105 | I bet you also want to read the memcached 106 | protocol doc. It's exciting! It also explains possible error messages. 107 | -------------------------------------------------------------------------------- /node_modules/mcskin/node_modules/memcache/example.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); 2 | var memcache = require('./lib/memcache'); 3 | 4 | function microtime(get_as_float) { 5 | var now = new Date().getTime() / 1000; 6 | var s = parseInt(now); 7 | return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s; 8 | } 9 | 10 | var onConnect = function() { 11 | mcClient.get('test', function(err, data) { 12 | util.debug(data); 13 | mcClient.close(); 14 | }); 15 | }; 16 | 17 | var benchmark = function() { 18 | var count = 100000; 19 | start = microtime(true); 20 | var x = 0; 21 | 22 | for (var i=0; i<=count; i++) { 23 | mcClient.get('test', function(err, data) { 24 | x += 1; 25 | if (x == count) { 26 | end = microtime(true); 27 | util.debug("get count : " + count + "total time: " + (end - start)); 28 | } 29 | }); 30 | } 31 | 32 | mcClient.close(); 33 | }; 34 | 35 | var setKey = function() { 36 | mcClient.set('test', 'hello \r\n node-memcache', function(err, response) { 37 | mcClient.get('test', function(err, data) { 38 | util.debug(data); 39 | mcClient.close(); 40 | }); 41 | }); 42 | }; 43 | 44 | var version = function() { 45 | mcClient.version(function(err, version) { 46 | util.debug(version); 47 | mcClient.close(); 48 | }); 49 | }; 50 | 51 | var incr = function() { 52 | mcClient.increment('x', 2, function(err, new_value) { 53 | util.debug(new_value); 54 | mcClient.close(); 55 | }); 56 | }; 57 | 58 | var decr = function() { 59 | mcClient.decrement('x', 1, function(err, new_value) { 60 | util.debug(new_value); 61 | mcClient.close(); 62 | }); 63 | }; 64 | 65 | mcClient = new memcache.Client(); 66 | mcClient.connect(); 67 | //mcClient.addHandler(onConnect); 68 | //mcClient.addHandler(setKey); 69 | //mcClient.addHandler(version); 70 | mcClient.addHandler(benchmark); 71 | 72 | -------------------------------------------------------------------------------- /node_modules/mcskin/node_modules/memcache/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/memcache'); -------------------------------------------------------------------------------- /node_modules/mcskin/node_modules/memcache/mm.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); 2 | var memcache = require('./lib/memcache'); 3 | 4 | function output(str){ 5 | console.log(str); 6 | } 7 | 8 | function microtime(get_as_float) { 9 | var now = new Date().getTime() / 1000; 10 | var s = parseInt(now); 11 | return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s; 12 | } 13 | 14 | 15 | var benchmark = function() { 16 | var count = 100000; 17 | start = microtime(true); 18 | var x = 0; 19 | 20 | for (var i=0; i<=count; i++) { 21 | mcClient.get('test', function(err, data) { 22 | x += 1; 23 | if (x == count) { 24 | end = microtime(true); 25 | util.debug("get count : " + count + "total time: " + (end - start)); 26 | } 27 | }); 28 | } 29 | 30 | mcClient.close(); 31 | }; 32 | 33 | var setKey = function() { 34 | mcClient.set('test', 'hello \r\n node-memcache', function(err, response) { 35 | mcClient.get('test', function(err, data) { 36 | util.debug(data); 37 | mcClient.close(); 38 | }); 39 | }); 40 | }; 41 | 42 | var version = function() { 43 | mcClient.version(function(err, version) { 44 | util.debug(version); 45 | mcClient.close(); 46 | }); 47 | }; 48 | 49 | var incr = function() { 50 | mcClient.increment('x', 2, function(err, new_value) { 51 | util.debug(new_value); 52 | mcClient.close(); 53 | }); 54 | }; 55 | 56 | var decr = function() { 57 | mcClient.decrement('x', 1, function(err, new_value) { 58 | util.debug(new_value); 59 | mcClient.close(); 60 | }); 61 | }; 62 | 63 | var MultiBench = function() { 64 | var count = 100000; 65 | start = microtime(true); 66 | var x = 0; 67 | 68 | for (var i=0; i<=count; i++) { 69 | mcClient.get('test', function(err, data) { 70 | x += 1; 71 | if (x == count) { 72 | end = microtime(true); 73 | util.debug("get count : " + count + "total time: " + (end - start)); 74 | } 75 | }); 76 | } 77 | for (var i=0; i<=count; i++) { 78 | mcClientB.get('test', function(err, data) { 79 | x += 1; 80 | if (x == count) { 81 | end = microtime(true); 82 | util.debug("get count : " + count + "total time: " + (end - start)); 83 | } 84 | }); 85 | } 86 | 87 | mcClient.close(); 88 | } 89 | var mcClient = new memcache.Client(); 90 | //var mc_free = false; 91 | mcClient.on("connect", function() { 92 | output("memcache connected ..."); 93 | // mc_free = true; 94 | // if(mc_free_b) MultiBench(); 95 | 96 | }); 97 | 98 | /* 99 | var mcClientB = new memcache.Client(); 100 | var mc_free_b = false; 101 | mcClientB.on("connect", function() { 102 | output("memcache connected ..."); 103 | mc_flag_b = true; 104 | if(mc_free) MultiBench(); 105 | }); 106 | 107 | mcClientB.connect(); 108 | */ 109 | 110 | mcClient.connect(); 111 | //mcClient.addHandler(onConnect); 112 | //mcClient.addHandler(setKey); 113 | //mcClient.addHandler(version); 114 | mcClient.addHandler(benchmark); 115 | 116 | -------------------------------------------------------------------------------- /node_modules/mcskin/node_modules/memcache/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "memcache", 3 | "description": "simple memcache client", 4 | "version": "0.2.0", 5 | "homepage": "https://github.com/elbart/node-memcache", 6 | "repository": "git://github.com/elbart/node-memcache.git", 7 | "author": "Tim Eggert ", 8 | "main": "./lib/memcache", 9 | "devDependencies": { 10 | "expresso": ">=0.7.0" 11 | }, 12 | "directories": { 13 | "lib": "lib", 14 | "test": "test" 15 | }, 16 | "scripts": { 17 | "test": "make test", 18 | "test-cov": "make test-cov" 19 | }, 20 | "engines": { 21 | "node": "*" 22 | }, 23 | "keywords": [ "memcache", "memcached" ] 24 | } 25 | -------------------------------------------------------------------------------- /node_modules/mysql/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /test/config.js 3 | *.swo 4 | *.un~ 5 | -------------------------------------------------------------------------------- /node_modules/mysql/License: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Felix Geisendörfer (felix@debuggable.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /node_modules/mysql/Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | test: 4 | @./test/run.js 5 | benchmark-node-mysql: 6 | @find benchmark/node-mysql/*.js | xargs -n 1 -t node 7 | benchmark-php: 8 | @find benchmark/php/*.php | xargs -n 1 -t php 9 | benchmark-all: benchmark-node-mysql benchmark-php 10 | benchmark: benchmark-node-mysql 11 | 12 | .PHONY: test benchmark 13 | -------------------------------------------------------------------------------- /node_modules/mysql/benchmark/node-mysql/insert.js: -------------------------------------------------------------------------------- 1 | require('../../test/common'); 2 | var Client = require('mysql/client'), 3 | client = Client(TEST_CONFIG); 4 | 5 | client.connect(); 6 | 7 | client.query('CREATE DATABASE '+TEST_DB, function(err) { 8 | if (err && err.number != Client.ERROR_DB_CREATE_EXISTS) { 9 | throw err; 10 | } 11 | }); 12 | client.query('USE '+TEST_DB); 13 | client.query('DROP TABLE IF EXISTS '+TEST_TABLE); 14 | client.query( 15 | 'CREATE TABLE '+TEST_TABLE+' ('+ 16 | 'id INT(11) AUTO_INCREMENT, '+ 17 | 'title VARCHAR(255), '+ 18 | 'text TEXT, '+ 19 | 'created DATETIME, '+ 20 | 'PRIMARY KEY (id));', 21 | function(err) { 22 | if (err) throw err; 23 | 24 | var start = +new Date, inserts = 0, total = 10000; 25 | function insertOne() { 26 | client.query('INSERT INTO '+TEST_TABLE+' SET title = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"', function() { 27 | inserts++; 28 | if (inserts < total) { 29 | insertOne(); 30 | } else { 31 | var duration = (+new Date - start) / 1000, 32 | insertsPerSecond = inserts / duration; 33 | 34 | console.log('%d inserts / second', insertsPerSecond.toFixed(2)); 35 | console.log('%d ms', +new Date - start); 36 | client.end(); 37 | } 38 | }); 39 | } 40 | insertOne(); 41 | } 42 | ); 43 | -------------------------------------------------------------------------------- /node_modules/mysql/benchmark/node-mysql/select.js: -------------------------------------------------------------------------------- 1 | // Last v8 profile when running this test for 500k rows: 2 | // https://gist.github.com/f85c38010c038e5efe2e 3 | require('../../test/common'); 4 | var Client = require('mysql/client'), 5 | client = Client(TEST_CONFIG), 6 | rows = 0; 7 | 8 | client.typeCast = false; 9 | 10 | client.connect(); 11 | client.query('CREATE DATABASE '+TEST_DB, function(err) { 12 | if (err && err.number != Client.ERROR_DB_CREATE_EXISTS) { 13 | throw err; 14 | } 15 | }); 16 | 17 | client.query('USE '+TEST_DB); 18 | var selectStart = +new Date; 19 | 20 | function query() { 21 | client 22 | .query('SELECT * FROM '+TEST_TABLE) 23 | .on('row', function(row) { 24 | rows++; 25 | }) 26 | .on('end', function() { 27 | if (rows < 10000) { 28 | query(); 29 | return; 30 | } 31 | 32 | var duration = (+new Date - selectStart) / 1000, 33 | rowsPerSecond = rows / duration; 34 | console.log('%d rows / second', rowsPerSecond.toFixed(2)); 35 | console.log('%d ms', +new Date - selectStart); 36 | client.end(); 37 | }); 38 | } 39 | 40 | query(); 41 | -------------------------------------------------------------------------------- /node_modules/mysql/benchmark/php/insert-select.php: -------------------------------------------------------------------------------- 1 | 'localhost', 6 | 'port' => 3306, 7 | 'user' => 'root', 8 | 'password' => 'root', 9 | 'db' => 'node_mysql_test', 10 | 'table' => 'post', 11 | ); 12 | extract($config); 13 | 14 | $connection = mysql_connect($host, $user, $password); 15 | mysql_query('USE '.$db, $connection); 16 | mysql_query('CREATE TEMPORARY TABLE '.$table.' ('. 17 | 'id INT(11) AUTO_INCREMENT, '. 18 | 'title VARCHAR(255), '. 19 | 'text TEXT, '. 20 | 'created DATETIME, '. 21 | 'PRIMARY KEY (id));', $connection); 22 | 23 | $start = microtime(true); 24 | for ($i = 0; $i < $INSERTS; $i++) { 25 | mysql_query('INSERT INTO '.$table.' SET title = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";', $connection); 26 | } 27 | $duration = (microtime(true) - $start); 28 | $insertsPerSecond = $INSERTS / $duration; 29 | echo sprintf("%d inserts / second\n", $insertsPerSecond); 30 | echo sprintf("%d ms\n", $duration * 1000); 31 | 32 | $start = microtime(true); 33 | $q = mysql_query('SELECT * FROM '.$table); 34 | while ($a = mysql_fetch_assoc($q)) { 35 | } 36 | $duration = (microtime(true) - $start); 37 | $rowsPerSecond = $INSERTS / $duration; 38 | echo sprintf("%d rows / second\n", $rowsPerSecond); 39 | echo sprintf("%d ms\n", $duration * 1000); 40 | ?> 41 | -------------------------------------------------------------------------------- /node_modules/mysql/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/mysql'); 2 | -------------------------------------------------------------------------------- /node_modules/mysql/lib/mysql.js: -------------------------------------------------------------------------------- 1 | var mysql = exports; 2 | var hashish = require('hashish'); 3 | var Client = exports.Client = require('./client'); 4 | var constants = require('./constants'); 5 | var fs = require('fs'); 6 | 7 | mysql.PACKAGE = (function() { 8 | var json = fs.readFileSync(__dirname + '/../package.json', 'utf8'); 9 | return JSON.parse(json); 10 | })(); 11 | 12 | mysql.createClient = function(config) { 13 | var client = new Client(); 14 | hashish.update(client, config || {}); 15 | return client; 16 | }; 17 | 18 | hashish.update(exports, constants); 19 | -------------------------------------------------------------------------------- /node_modules/mysql/lib/outgoing_packet.js: -------------------------------------------------------------------------------- 1 | var Buffer = require('buffer').Buffer; 2 | 3 | function OutgoingPacket(size, num) { 4 | this.buffer = new Buffer(size + 3 + 1); 5 | this.index = 0; 6 | this.writeNumber(3, size); 7 | this.writeNumber(1, num || 0); 8 | }; 9 | module.exports = OutgoingPacket; 10 | 11 | OutgoingPacket.prototype.writeNumber = function(bytes, number) { 12 | for (var i = 0; i < bytes; i++) { 13 | this.buffer[this.index++] = (number >> (i * 8)) & 0xff; 14 | } 15 | }; 16 | 17 | OutgoingPacket.prototype.writeFiller = function(bytes) { 18 | for (var i = 0; i < bytes; i++) { 19 | this.buffer[this.index++] = 0; 20 | } 21 | }; 22 | 23 | OutgoingPacket.prototype.write = function(bufferOrString, encoding) { 24 | if (typeof bufferOrString == 'string') { 25 | this.index += this.buffer.write(bufferOrString, this.index, encoding); 26 | return; 27 | } 28 | 29 | bufferOrString.copy(this.buffer, this.index, 0); 30 | this.index += bufferOrString.length; 31 | }; 32 | 33 | OutgoingPacket.prototype.writeNullTerminated = function(bufferOrString, encoding) { 34 | this.write(bufferOrString, encoding); 35 | this.buffer[this.index++] = 0; 36 | }; 37 | 38 | OutgoingPacket.prototype.writeLengthCoded = function(bufferOrStringOrNumber, encoding) { 39 | if (bufferOrStringOrNumber === null) { 40 | this.buffer[this.index++] = 251; 41 | return; 42 | } 43 | 44 | if (typeof bufferOrStringOrNumber == 'number') { 45 | if (bufferOrStringOrNumber <= 250) { 46 | this.buffer[this.index++] = bufferOrStringOrNumber; 47 | return; 48 | } 49 | 50 | // @todo support 8-byte numbers and simplify this 51 | if (bufferOrStringOrNumber < 0xffff) { 52 | this.buffer[this.index++] = 252; 53 | this.buffer[this.index++] = (bufferOrStringOrNumber >> 0) & 0xff; 54 | this.buffer[this.index++] = (bufferOrStringOrNumber >> 8) & 0xff; 55 | } else if (bufferOrStringOrNumber < 0xffffff) { 56 | this.buffer[this.index++] = 253; 57 | this.buffer[this.index++] = (bufferOrStringOrNumber >> 0) & 0xff; 58 | this.buffer[this.index++] = (bufferOrStringOrNumber >> 8) & 0xff; 59 | this.buffer[this.index++] = (bufferOrStringOrNumber >> 16) & 0xff; 60 | } else { 61 | throw new Error('8 byte length coded numbers not supported yet'); 62 | } 63 | return; 64 | } 65 | 66 | if (bufferOrStringOrNumber instanceof Buffer) { 67 | this.writeLengthCoded(bufferOrStringOrNumber.length); 68 | this.write(bufferOrStringOrNumber); 69 | return; 70 | } 71 | 72 | if (typeof bufferOrStringOrNumber == 'string') { 73 | this.writeLengthCoded(Buffer.byteLength(bufferOrStringOrNumber, encoding)); 74 | this.write(bufferOrStringOrNumber, encoding); 75 | return; 76 | } 77 | 78 | throw new Error('passed argument not a buffer, string or number: '+bufferOrStringOrNumber); 79 | }; 80 | -------------------------------------------------------------------------------- /node_modules/mysql/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mysql", 3 | "version": "0.9.4", 4 | "author": "Felix Geisendörfer (http://debuggable.com/)", 5 | "description": "A pure node.js JavaScript Client implementing the MySQL protocol.", 6 | "homepage": "https://github.com/felixge/node-mysql", 7 | "repository": { 8 | "type": "git", 9 | "url": "git://github.com/felixge/node-mysql.git" 10 | }, 11 | "main": "./index", 12 | "scripts": { 13 | "test": "make test" 14 | }, 15 | "dependencies": { 16 | "hashish": "0.0.4" 17 | }, 18 | "devDependencies": { 19 | "gently": "0.8.0", 20 | "far": "0.0.6", 21 | "fast-or-slow": "0.0.5" 22 | }, 23 | "engines": { 24 | "node": "*" 25 | } 26 | } -------------------------------------------------------------------------------- /node_modules/mysql/test/common.js: -------------------------------------------------------------------------------- 1 | var mysql = require('..'); 2 | var path = require('path'); 3 | 4 | var root = path.join(__dirname, '../'); 5 | exports.dir = { 6 | root: root, 7 | lib: root + '/lib', 8 | fixture: root + '/test/fixture', 9 | }; 10 | 11 | exports.TEST_DB = 'node_mysql_test'; 12 | exports.TEST_TABLE = 'posts'; 13 | 14 | exports.createClient = function() { 15 | try { 16 | var config = require('./config'); 17 | } catch (e) { 18 | console.log('Skipping. See test/config.template.js for more information.'); 19 | process.exit(0); 20 | } 21 | 22 | return mysql.createClient(config); 23 | }; 24 | 25 | exports.fastOrSlow = require('fast-or-slow'); 26 | -------------------------------------------------------------------------------- /node_modules/mysql/test/config.template.js: -------------------------------------------------------------------------------- 1 | // Copy this file to test/config.js and fill in your own credentials in order 2 | // to run the system test suite. 3 | module.exports = { 4 | host: 'localhost', 5 | port: 3306, 6 | user: 'root', 7 | password: 'root' 8 | }; 9 | -------------------------------------------------------------------------------- /node_modules/mysql/test/fast/test-client.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var assert = require('assert'); 3 | var test = common.fastOrSlow.fast(); 4 | var Client = require(common.dir.lib + '/client'); 5 | 6 | var client; 7 | test.before(function() { 8 | client = new Client(); 9 | }); 10 | 11 | test('#format() does not manipulate params parameter', function() { 12 | var sql = '?'; 13 | var params = [1]; 14 | 15 | client.format(sql, params); 16 | assert.equal(params.length, 1); 17 | }); 18 | 19 | // https://github.com/felixge/node-mysql/issues/96 20 | test('Timeout reconnect works with empty queue', function() { 21 | // A non-error packet 22 | var packet = {}; 23 | 24 | // This must not throw an error 25 | client._handlePacket(packet); 26 | }); 27 | -------------------------------------------------------------------------------- /node_modules/mysql/test/fast/test-mysql.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var assert = require('assert'); 3 | var test = common.fastOrSlow.fast(); 4 | var mysql = require(common.dir.lib + '/mysql'); 5 | 6 | test('Package JSON is exported', function() { 7 | assert.strictEqual(mysql.PACKAGE.name, 'mysql'); 8 | }); 9 | -------------------------------------------------------------------------------- /node_modules/mysql/test/fixture/columnia.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `columnia` ( 2 | `f0` bigint(20) unsigned NOT NULL DEFAULT '0', 3 | `field0001` bigint(20) unsigned NOT NULL DEFAULT '0', 4 | `field002` bigint(20) unsigned NOT NULL DEFAULT '0', 5 | `field0000000003` bigint(20) unsigned DEFAULT NULL, 6 | `field00004` bigint(20) unsigned NOT NULL DEFAULT '0', 7 | `field000000000005` bigint(20) unsigned DEFAULT NULL, 8 | `field0000000000006` bigint(20) unsigned NOT NULL, 9 | `field000007` text NOT NULL, 10 | `field0000000008` text NOT NULL, 11 | `field009` int(10) NOT NULL DEFAULT '0', 12 | `field00010` text NOT NULL, 13 | `field000000000011` text NOT NULL, 14 | `field00000012` text NOT NULL, 15 | `field0000013` text NOT NULL, 16 | `field00000000000014` text NOT NULL, 17 | `field0000000015` text NOT NULL, 18 | `field000016` text NOT NULL, 19 | `field000000000017` text NOT NULL, 20 | `field0000000000000018` text NOT NULL, 21 | `field0000000000019` text NOT NULL, 22 | `field0000000000020` text NOT NULL, 23 | `field00000000000021` text NOT NULL, 24 | `field00000000022` text NOT NULL, 25 | `field000000000000000023` text NOT NULL, 26 | `field000000000000024` text NOT NULL, 27 | `field000000000000025` text NOT NULL, 28 | `field0000000000000026` text NOT NULL, 29 | `field0000000000027` text NOT NULL, 30 | `field00000028` bigint(20) unsigned NOT NULL, 31 | `field000000029` tinyint(1) NOT NULL, 32 | `field000030` tinyint(1) NOT NULL DEFAULT '0', 33 | `field31` text NOT NULL, 34 | `field00000032` bigint(20) unsigned NOT NULL, 35 | `fi33` int(11) NOT NULL DEFAULT '0', 36 | `field00000034` bigint(20) unsigned DEFAULT NULL, 37 | `field000035` text NOT NULL, 38 | `field0036` int(11) NOT NULL DEFAULT '0', 39 | `field0000000000000000000037` text NOT NULL, 40 | `field0000000000000000000038` text NOT NULL, 41 | `field0000000000000000000000000039` text NOT NULL, 42 | `field0000000000000000040` text NOT NULL, 43 | `field00000000000000000041` text NOT NULL, 44 | `field00000000000000000000042` text NOT NULL, 45 | `field00000000000000000043` text NOT NULL, 46 | `field00000000000000000044` text NOT NULL, 47 | `field00000000000000000000000045` text NOT NULL, 48 | `field00000000000000046` text NOT NULL, 49 | `field000000000000000047` text NOT NULL, 50 | `field000000000000000000048` text NOT NULL, 51 | `field49` text NOT NULL, 52 | `field50` int(11) NOT NULL, 53 | PRIMARY KEY (`f0`) 54 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1 55 | -------------------------------------------------------------------------------- /node_modules/mysql/test/legacy/common.js: -------------------------------------------------------------------------------- 1 | var newCommon = require('../common'); 2 | exports.dir = newCommon.dir; 3 | 4 | var path = require('path'); 5 | var util = require('util'); 6 | 7 | var parent = module.parent.filename; 8 | if (parent.match(/system/) || parent.match(/benchmark/)) { 9 | try { 10 | global.TEST_CONFIG = require('../config'); 11 | } catch (e) { 12 | console.log('Skipping. See test/config.template.js for more information.'); 13 | process.exit(0); 14 | } 15 | } 16 | 17 | global.TEST_DB = 'node_mysql_test'; 18 | global.TEST_TABLE = 'posts'; 19 | global.TEST_FIXTURES = path.join(__dirname, '../fixture'); 20 | 21 | global.Gently = require('gently'); 22 | global.assert = require('assert'); 23 | global.p = function(val) { 24 | util.error(util.inspect(val)); 25 | }; 26 | 27 | global.GENTLY = new Gently(); 28 | global.HIJACKED = GENTLY.hijacked; 29 | 30 | // Stupid new feature in node that complains about gently attaching too many 31 | // listeners to process 'exit'. This is a workaround until I can think of a 32 | // better way to deal with this. 33 | if (process.setMaxListeners) { 34 | process.setMaxListeners(Infinity); 35 | } 36 | -------------------------------------------------------------------------------- /node_modules/mysql/test/legacy/simple/test-auth.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var auth = require(common.dir.lib + '/auth'); 3 | 4 | function test(test) { 5 | gently = new Gently(); 6 | test(); 7 | gently.verify(test.name); 8 | } 9 | 10 | test(function sha1() { 11 | assert.deepEqual( 12 | auth.sha1('root'), 13 | new Buffer([ 14 | 220, 118, 233, 240, 192, 15 | 0, 110, 143, 145, 158, 16 | 12, 81, 92, 102, 219, 17 | 186, 57, 130, 247, 133 18 | ]).toString('binary') 19 | ); 20 | }); 21 | 22 | test(function xor() { 23 | var a = new Buffer([170, 220]), // 10101010 11011100 24 | b = new Buffer([220, 170]), // 11011100 10101010 25 | expected = new Buffer([118, 118]); // 01110110 01110110 26 | 27 | assert.deepEqual(auth.xor(a.toString('binary'), b.toString('binary')), expected); 28 | }); 29 | 30 | test(function token() { 31 | var SCRAMBLE = new Buffer([0, 1, 2, 3, 4, 5]); 32 | 33 | (function testRegular() { 34 | var PASS = 'root', 35 | STAGE_1 = auth.sha1(PASS), 36 | TOKEN = auth.xor( 37 | auth.sha1(new Buffer(SCRAMBLE + auth.sha1(STAGE_1), 'binary')), 38 | STAGE_1 39 | ); 40 | 41 | assert.deepEqual(auth.token('root', SCRAMBLE), TOKEN); 42 | })(); 43 | 44 | (function testNoPassword() { 45 | assert.deepEqual(auth.token(null, SCRAMBLE), new Buffer(0)); 46 | })(); 47 | }); 48 | 49 | test(function hashPassword() { 50 | function verify(password, bytes){ 51 | var expected = new Buffer(bytes); 52 | var actual = auth.hashPassword(password); 53 | 54 | assert.deepEqual(actual, expected); 55 | } 56 | 57 | verify('root', [0x67, 0x45, 0x7E, 0x22, 0x6a, 0x1a, 0x15, 0xbd]); 58 | verify('long password test', [0x6c, 0x24, 0x68, 0x41, 0x2c, 0xa6, 0x86, 0x56]); 59 | verify('saf789yasfbsd89f', [0x6c, 0x9b, 0x2f, 0x07, 0x17, 0xeb, 0x95, 0xc6]); 60 | }); 61 | 62 | 63 | test(function randomInit() { 64 | function verify(in1, in2, out1, out2){ 65 | var r = auth.randomInit(in1, in2); 66 | assert.equal(out1, r.seed1); 67 | assert.equal(out2, r.seed2); 68 | } 69 | 70 | verify(0x00000000, 0x00000000, 0x00000000, 0x00000000); 71 | verify(0x0000FFFF, 0x0000FFFF, 0x0000ffff, 0x0000ffff); 72 | verify(0x50000000, 0x50000000, 0x10000001, 0x10000001); 73 | verify(0xFFFFFFFF, 0xFFFFFFFF, 0x00000003, 0x00000003); 74 | verify(3252345, 7149734, 0x0031a079, 0x006d18a6); 75 | }); 76 | 77 | test(function myRnd() { 78 | function verifySequence(seed1, seed2, expected){ 79 | var r = auth.randomInit(seed1, seed2); 80 | for (var i = 0; i < expected.length; i++){ 81 | var n = auth.myRnd(r); 82 | 83 | // we will test to 14 digits, since 84 | // we only ever use this function mutliplied 85 | // by small numbers anyway 86 | 87 | var a = ':'+n; 88 | var b = ':'+expected[i]; 89 | 90 | assert.equal(a.substr(1, 16), b.substr(1, 16)); 91 | } 92 | } 93 | 94 | verifySequence(3252345, 7149734, [ 95 | 0.0157456556481734, 96 | 0.0696413620092360, 97 | 0.3009698738353047, 98 | 0.2959253138824602, 99 | 0.5767169786400320, 100 | 0.9958089822864243, 101 | 0.2488940062456708, 102 | 0.2570431151027261, 103 | 0.5385335875102631, 104 | 0.9215386229767824, 105 | ]); 106 | }); 107 | 108 | test(function scramble323() { 109 | function verify(message, password, bytes){ 110 | var expected = new Buffer(bytes); 111 | var actual = auth.scramble323(new Buffer(message), password); 112 | 113 | assert.deepEqual(actual, expected); 114 | } 115 | 116 | verify('8bytesofstuff', 'root', [0x5a, 0x4d, 0x46, 0x47, 0x43, 0x53, 0x58, 0x5f]); 117 | verify('e8cf00cec9ec825af22', 'saf789yasfbsd', [0x4d, 0x54, 0x5b, 0x47, 0x5f, 0x52, 0x4d, 0x45]); 118 | }); 119 | -------------------------------------------------------------------------------- /node_modules/mysql/test/legacy/simple/test-client.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var Parser = require(common.dir.lib + '/parser'); 3 | var constants = require(common.dir.lib + '/constants'); 4 | var Client = require(common.dir.lib + '/client'); 5 | 6 | function test(test) { 7 | client = new Client(); 8 | gently = new Gently(); 9 | test(); 10 | gently.verify(test.name); 11 | }; 12 | 13 | test(function write() { 14 | var PACKET = {buffer: []}, 15 | CONNECTION = client._socket = {}; 16 | 17 | gently.expect(CONNECTION, 'write', function(buffer) { 18 | assert.strictEqual(buffer, PACKET.buffer); 19 | }); 20 | 21 | client.write(PACKET); 22 | }); 23 | 24 | test(function format() { 25 | var sql = client.format('? + ? = ?', [1, 2, 'great']); 26 | assert.equal(sql, '1 + 2 = \'great\''); 27 | 28 | assert.throws(function() { 29 | var sql = client.format('? + ? = ?', [1, 2]); 30 | }); 31 | 32 | assert.throws(function() { 33 | var sql = client.format('? + ? = ?', [1, 2, 3, 4]); 34 | }); 35 | }); 36 | 37 | test(function escape() { 38 | assert.equal(client.escape(undefined), 'NULL'); 39 | assert.equal(client.escape(null), 'NULL'); 40 | assert.equal(client.escape(false), 'false'); 41 | assert.equal(client.escape(true), 'true'); 42 | assert.equal(client.escape(5), '5'); 43 | assert.equal(client.escape({foo:'bar'}), "'[object Object]'"); 44 | assert.equal(client.escape([1,2,3]), "'1,2,3'"); 45 | assert.equal(client.escape(new Date(Date.UTC(2011,6,6,6,6,6,6))), "'2011-07-06T06:06:06.006Z'"); 46 | 47 | assert.equal(client.escape('Super'), "'Super'"); 48 | assert.equal(client.escape('Sup\0er'), "'Sup\\0er'"); 49 | assert.equal(client.escape('Sup\ber'), "'Sup\\ber'"); 50 | assert.equal(client.escape('Sup\ner'), "'Sup\\ner'"); 51 | assert.equal(client.escape('Sup\rer'), "'Sup\\rer'"); 52 | assert.equal(client.escape('Sup\ter'), "'Sup\\ter'"); 53 | assert.equal(client.escape('Sup\\er'), "'Sup\\\\er'"); 54 | assert.equal(client.escape('Sup\u001aer'), "'Sup\\Zer'"); 55 | assert.equal(client.escape('Sup\'er'), "'Sup\\'er'"); 56 | assert.equal(client.escape('Sup"er'), "'Sup\\\"er'"); 57 | }); 58 | 59 | test(function _packetToUserObject() { 60 | (function testOkPacket() { 61 | var PACKET = { 62 | type: Parser.OK_PACKET, 63 | length: 65, 64 | received: 65, 65 | number: 92, 66 | foo: 'bar' 67 | }; 68 | 69 | var ok = Client._packetToUserObject(PACKET); 70 | 71 | assert.notStrictEqual(PACKET, ok); 72 | assert.ok(!(ok instanceof Error)); 73 | assert.equal(ok.foo, PACKET.foo); 74 | assert.equal(ok.type, undefined); 75 | assert.equal(ok.length, undefined); 76 | assert.equal(ok.received, undefined); 77 | })(); 78 | 79 | (function testErrorPacket() { 80 | var PACKET = { 81 | type: Parser.ERROR_PACKET, 82 | foo: 'bar', 83 | errorMessage: 'oh no', 84 | errorNumber: 1007 85 | }; 86 | 87 | var err = Client._packetToUserObject(PACKET); 88 | 89 | assert.ok(err instanceof Error); 90 | assert.equal(err.message, 'oh no'); 91 | assert.equal(err.errorMessage, undefined); 92 | assert.equal(err.number, 1007); 93 | assert.equal(err.errorNumber, undefined); 94 | })(); 95 | }); 96 | -------------------------------------------------------------------------------- /node_modules/mysql/test/legacy/simple/test-query.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var Query = require(common.dir.lib + '/query'); 3 | var EventEmitter = require('events').EventEmitter; 4 | var Parser = require(common.dir.lib + '/parser'); 5 | var query; 6 | var gently; 7 | 8 | function test(test) { 9 | query = new Query(); 10 | gently = new Gently(); 11 | test(); 12 | gently.verify(test.name); 13 | } 14 | 15 | test(function constructor() { 16 | assert.ok(query instanceof EventEmitter); 17 | assert.strictEqual(query.typeCast, true); 18 | assert.strictEqual(query.sql, null); 19 | assert.equal(new Query({foo: 'bar'}).foo, 'bar'); 20 | }); 21 | 22 | test(function _handlePacket() { 23 | function typeCast(type, strValue) { 24 | query._fields = [{name: 'my_field', fieldType: type}]; 25 | 26 | var PACKET = new EventEmitter(), r; 27 | PACKET.type = Parser.ROW_DATA_PACKET; 28 | 29 | gently.expect(PACKET, 'on', function (event, fn) { 30 | assert.equal(event, 'data'); 31 | 32 | gently.expect(query, 'emit', function (event, row) { 33 | assert.equal(event, 'row'); 34 | r = row.my_field; 35 | }); 36 | 37 | var val = (strValue === null) 38 | ? null 39 | : new Buffer(strValue); 40 | 41 | fn(val, 0); 42 | }); 43 | 44 | query._handlePacket(PACKET); 45 | return r; 46 | } 47 | 48 | assert.deepEqual(typeCast(Query.FIELD_TYPE_TIMESTAMP, '2010-10-05 06:23:42 UTC'), new Date('2010-10-05 06:23:42Z')); 49 | 50 | assert.deepEqual(typeCast(Query.FIELD_TYPE_TIMESTAMP, '2010-10-05 UTC'), new Date('2010-10-05Z')); 51 | assert.deepEqual(typeCast(Query.FIELD_TYPE_DATE, '2010-10-05 UTC'), new Date('2010-10-05Z')); 52 | assert.deepEqual(typeCast(Query.FIELD_TYPE_DATETIME, '2010-10-05 UTC'), new Date('2010-10-05Z')); 53 | assert.deepEqual(typeCast(Query.FIELD_TYPE_NEWDATE, '2010-10-05 UTC'), new Date('2010-10-05Z')); 54 | 55 | assert.strictEqual(typeCast(Query.FIELD_TYPE_TINY, '08'), 8); 56 | assert.strictEqual(typeCast(Query.FIELD_TYPE_SHORT, '08'), 8); 57 | assert.strictEqual(typeCast(Query.FIELD_TYPE_LONG, '08'), 8); 58 | assert.strictEqual(typeCast(Query.FIELD_TYPE_LONGLONG, '08'), 8); 59 | assert.strictEqual(typeCast(Query.FIELD_TYPE_INT24, '08'), 8); 60 | assert.strictEqual(typeCast(Query.FIELD_TYPE_YEAR, '08'), 8); 61 | 62 | assert.strictEqual(typeCast(Query.FIELD_TYPE_DECIMAL, '2.8'), '2.8'); 63 | assert.strictEqual(typeCast(Query.FIELD_TYPE_FLOAT, '2.8'), 2.8); 64 | assert.strictEqual(typeCast(Query.FIELD_TYPE_DOUBLE, '2.8'), 2.8); 65 | assert.strictEqual(typeCast(Query.FIELD_TYPE_NEWDECIMAL, '2.8'), '2.8'); 66 | 67 | assert.strictEqual(typeCast(Query.FIELD_TYPE_DATE, null), null); 68 | }); 69 | -------------------------------------------------------------------------------- /node_modules/mysql/test/run.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var far = require('far').create(); 3 | 4 | far.add(__dirname); 5 | far.include(/test-.*\.js$/); 6 | 7 | far.execute(); 8 | -------------------------------------------------------------------------------- /node_modules/mysql/test/slow/test-client-commands.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var assert = require('assert'); 3 | var test = common.fastOrSlow.slow(); 4 | var mysql = require(common.dir.lib + '/mysql'); 5 | 6 | test.before(function() { 7 | this.client = common.createClient(); 8 | }); 9 | 10 | test.after(function(done) { 11 | this.client.end(done); 12 | }); 13 | 14 | test('ping()', function(done) { 15 | this.client.ping(done); 16 | }); 17 | 18 | test('statistics()', function(done) { 19 | this.client.statistics(function(err, statistics) { 20 | assert.ok(statistics.extra.match(/time/i)); 21 | done(err); 22 | }); 23 | }); 24 | 25 | test('useDatabase()', function(done) { 26 | this.client.useDatabase(common.TEST_DB, function(err) { 27 | // The TEST_DB may not exist right now, so ignore errors related to that 28 | if (err && err.number === mysql.ERROR_BAD_DB_ERROR) { 29 | err = null; 30 | } 31 | 32 | done(err); 33 | }); 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /node_modules/mysql/test/slow/test-client-connect.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var assert = require('assert'); 3 | var test = common.fastOrSlow.slow(); 4 | 5 | test.before(function() { 6 | this.client = common.createClient(); 7 | }); 8 | 9 | test.after(function(done) { 10 | var connected = this.client.connected; 11 | this.client.end(function(err) { 12 | (connected) 13 | ? assert.equal(err, null) 14 | : assert.notEqual(err, null); 15 | 16 | done(); 17 | }); 18 | }); 19 | 20 | test('Client tries to connect automatically', function(done) { 21 | this.client.query('SELECT 1', function(err, results) { 22 | assert.deepEqual(results, [{1: 1}]); 23 | done(err); 24 | }); 25 | }); 26 | 27 | test('Connection errors are delegated to callback', function(done) { 28 | // Port number outside of range -> triggers connection error 29 | this.client.port = 999999999; 30 | 31 | var callbacks = []; 32 | this.client.query('SELECT 1', function(err) { 33 | assert.ok(err); 34 | callbacks.push(1); 35 | }); 36 | 37 | this.client.query('SELECT 2', function(err) { 38 | callbacks.push(2); 39 | assert.ok(err); 40 | 41 | assert.deepEqual(callbacks, [1, 2]); 42 | done(null); 43 | }); 44 | }); 45 | 46 | test('Bad credentials', function(done) { 47 | this.client.password = 'thispassworddoesnotreallywork'; 48 | 49 | var callbacks = []; 50 | this.client.query('SELECT 1', function(err) { 51 | assert.ok(err); 52 | callbacks.push(1); 53 | }); 54 | 55 | this.client.query('SELECT 2', function(err) { 56 | assert.ok(err); 57 | callbacks.push(2); 58 | 59 | assert.deepEqual(callbacks, [1, 2]); 60 | done(); 61 | }); 62 | }); 63 | 64 | test('Reconnecting a closed client works', function(done) { 65 | var cbs = []; 66 | this.client.query('SELECT 1', function() { 67 | cbs.push(1); 68 | }); 69 | 70 | this.client.end(function() { 71 | cbs.push(2); 72 | }); 73 | 74 | this.client.query('SELECT 1', function(err) { 75 | assert.deepEqual(cbs, [1, 2]); 76 | done(err); 77 | }); 78 | }); 79 | 80 | test('Reconnect on timeout', {timeout: 2000}, function(done) { 81 | // Not sure if we need all 3 of these, but they do the trick 82 | this.client.query('SET interactive_timeout = 1'); 83 | this.client.query('SET wait_timeout = 1'); 84 | this.client.query('SET net_read_timeout = 1'); 85 | 86 | var self = this; 87 | this.client._socket.on('end', function() { 88 | assert.equal(self.client.connected, false); 89 | 90 | self.client.query('SELECT 1', function(err) { 91 | done(err); 92 | }); 93 | }); 94 | }); 95 | -------------------------------------------------------------------------------- /node_modules/mysql/test/slow/test-client-max-connections.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var assert = require('assert'); 3 | var test = common.fastOrSlow.slow(); 4 | var mysql = require(common.dir.lib + '/mysql'); 5 | 6 | test.before(function() { 7 | this.client = common.createClient(); 8 | }); 9 | 10 | test.after(function(done) { 11 | this.client.end(done); 12 | }); 13 | 14 | 15 | test('max connection', function(done) { 16 | var originalMaxConnections; 17 | var self = this; 18 | 19 | function setMaxConnectionsToOne() { 20 | // First we figure out the current max_connections value, so we can restore that after the test 21 | self.client.query('SHOW VARIABLES WHERE Variable_name = ?', ['max_connections'], function(err, results) { 22 | if (err) throw err; 23 | 24 | originalMaxConnections = parseInt(results[0].Value); 25 | if (originalMaxConnections === 1) { 26 | console.log( 27 | 'MySql already had max_connections set to 1. '+ 28 | 'This probably happened because of a mal-function in this test, so re-setting to the MySql default of 100. '+ 29 | 'If you had a higher value configured, you need to manually fix this now.' 30 | ); 31 | originalMaxConnections = 100; 32 | } 33 | 34 | // Now we set max connections to 1, then we continue with our test 35 | self.client.query('SET GLOBAL max_connections = ?', [1], function() { 36 | connectTwoClients(); 37 | }); 38 | }); 39 | }; 40 | 41 | function connectTwoClients() { 42 | var client1 = common.createClient(); 43 | client1.query('SELECT 1', function(err) { 44 | if (err) { 45 | // There should be no error for the first connection, but if there is one 46 | // anyway, let's try to at least restore the server config before throwing 47 | restoreMaxConnections(function() { 48 | throw err; 49 | }); 50 | return; 51 | } 52 | 53 | var client2 = common.createClient(); 54 | client2.query('SELECT 1', function(err) { 55 | assert.strictEqual(err.number, mysql.ERROR_CON_COUNT_ERROR); 56 | 57 | client1.end(); 58 | restoreMaxConnections(); 59 | }); 60 | }); 61 | } 62 | 63 | function restoreMaxConnections(cb) { 64 | self.client.query('SET GLOBAL max_connections = ?', [originalMaxConnections], cb); 65 | done(); 66 | } 67 | 68 | setMaxConnectionsToOne(); 69 | }); 70 | -------------------------------------------------------------------------------- /node_modules/mysql/test/slow/test-client-query-column-ordering.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var assert = require('assert'); 3 | var test = common.fastOrSlow.slow(); 4 | var mysql = require(common.dir.lib + '/mysql'); 5 | var fs = require('fs'); 6 | 7 | test.before(function() { 8 | this.client = common.createClient(); 9 | }); 10 | 11 | test.after(function(done) { 12 | this.client.end(done); 13 | }); 14 | 15 | test('Column ordering works properly', {timeout: 15 * 1000}, function(done) { 16 | var REPEATS = 500; 17 | 18 | this.client.query('CREATE DATABASE ' + common.TEST_DB, function(err) { 19 | if (err && err.number != mysql.ERROR_DB_CREATE_EXISTS) { 20 | throw err; 21 | } 22 | }); 23 | this.client.query('USE ' + common.TEST_DB); 24 | 25 | this.client.query('DROP TABLE IF EXISTS columnia'); 26 | var fixture = fs.readFileSync(common.dir.fixture + '/columnia.sql', 'utf8'); 27 | this.client.query(fixture); 28 | 29 | var finished = 0; 30 | var self = this; 31 | for (var i = 0; i < REPEATS; i++) { 32 | (function(i) { 33 | var query = self.client.query("SHOW COLUMNS FROM columnia"); 34 | 35 | query.on('row', function(row) { 36 | if (!row.Type) { 37 | throw new Error('Column order mixed up after '+i+' queries.'); 38 | } 39 | }); 40 | 41 | query.on('end', function() { 42 | finished++; 43 | if (finished === REPEATS) { 44 | done(); 45 | } 46 | }); 47 | })(i); 48 | } 49 | }); 50 | 51 | -------------------------------------------------------------------------------- /node_modules/mysql/test/slow/test-client-query-error-handling.js: -------------------------------------------------------------------------------- 1 | var common = require('../common'); 2 | var assert = require('assert'); 3 | var test = common.fastOrSlow.slow(); 4 | var mysql = require(common.dir.lib + '/mysql'); 5 | 6 | var INVALID_QUERY_1 = 'first invalid #*&% query'; 7 | var INVALID_QUERY_2 = 'another #*&% wrong query'; 8 | 9 | test.before(function() { 10 | this.client = common.createClient(); 11 | }); 12 | 13 | test.after(function(done) { 14 | this.client.end(done); 15 | }); 16 | 17 | test('query callback should receive error', function(done) { 18 | this.client.query(INVALID_QUERY_1, function(error) { 19 | assert.ok(error); 20 | assert.strictEqual(error.sql, INVALID_QUERY_1); 21 | done(); 22 | }); 23 | }); 24 | 25 | test('query object should emit error event', function(done) { 26 | var query = this.client.query(INVALID_QUERY_2); 27 | 28 | query.on('error', function(error) { 29 | assert.ok(error); 30 | assert.strictEqual(error.sql, INVALID_QUERY_2); 31 | done(); 32 | }); 33 | }); 34 | 35 | test('query errors are delegated to client error event if needed', function(done) { 36 | var query = this.client.query(INVALID_QUERY_1); 37 | 38 | this.client.on('error', function(error) { 39 | assert.ok(error); 40 | assert.strictEqual(error.sql, INVALID_QUERY_1); 41 | done(); 42 | }); 43 | }); 44 | 45 | test('query errors should not leave client in a broken state', function(done) { 46 | this.client.query(INVALID_QUERY_1, function(error) { 47 | assert.ok(error); 48 | assert.strictEqual(error.sql, INVALID_QUERY_1); 49 | }); 50 | 51 | this.client.query('SHOW STATUS', function(error, rows, fields) { 52 | assert.ifError(error); 53 | assert.equal(rows.length >= 50, true); 54 | assert.equal(Object.keys(fields).length, 2); 55 | }); 56 | 57 | this.client.query(INVALID_QUERY_1, function(error) { 58 | assert.ok(error); 59 | assert.strictEqual(error.sql, INVALID_QUERY_1); 60 | }); 61 | 62 | this.client.query(INVALID_QUERY_2, function(error) { 63 | assert.ok(error); 64 | assert.strictEqual(error.sql, INVALID_QUERY_2); 65 | done(); 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /node_modules/mysql/tool/pcap-mysql.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var sys = require("sys"), 4 | pcap = require("pcap"), 5 | mysqlPort = parseInt(process.argv[3]) || 3306, 6 | pcap_session = pcap.createSession(process.argv[2] || '', 'tcp port '+mysqlPort); 7 | 8 | sys.puts('This tool allows to reverse engineer the mysql procotocol using node-pcap.'); 9 | sys.puts(''); 10 | sys.puts('Available devices (active one is denoted by *):'); 11 | 12 | // Print all devices, currently listening device prefixed with an asterisk 13 | pcap_session.findalldevs().forEach(function (dev) { 14 | sys.print(' '); 15 | if (pcap_session.device_name === dev.name) { 16 | sys.print("* "); 17 | } 18 | sys.print(dev.name + " "); 19 | if (dev.addresses.length > 0) { 20 | dev.addresses.forEach(function (address) { 21 | sys.print(address.addr + "/" + address.netmask); 22 | }); 23 | sys.print("\n"); 24 | } else { 25 | sys.print("no address\n"); 26 | } 27 | }); 28 | 29 | sys.puts(''); 30 | sys.puts('Execute `./pcap-mysql.js ` to listen on another device.'); 31 | sys.puts(''); 32 | 33 | // Listen for packets, decode them, and feed the simple printer. No tricks. 34 | pcap_session.on('packet', function (raw_packet) { 35 | var packet = pcap.decode.packet(raw_packet); 36 | //sys.puts(pcap.print.packet(packet)); 37 | var tcp = packet.link.ip.tcp; 38 | if (!tcp.data) { 39 | return; 40 | } 41 | 42 | if (tcp.sport == mysqlPort) { 43 | sys.puts('<- '+tcp.data.inspect()); 44 | } else { 45 | sys.puts('-> '+tcp.data.inspect()); 46 | } 47 | }); 48 | 49 | -------------------------------------------------------------------------------- /node_modules/nodeunit/.npmignore: -------------------------------------------------------------------------------- 1 | dist 2 | stamp-build 3 | test/fixtures/dir2 4 | -------------------------------------------------------------------------------- /node_modules/nodeunit/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | Nodeunit contributors (sorted alphabeticaly) 2 | ============================================ 3 | 4 | * **[Alex Gorbatchev](https://github.com/alexgorbatchev)** 5 | 6 | * Deeper default object inspection 7 | * Timeout to ensure flushing of console output (default reporter) 8 | 9 | * **[Alex Wolfe](https://github.com/alexkwolfe)** 10 | 11 | * HTML test reporter 12 | 13 | * **[Caolan McMahon](https://github.com/caolan)** 14 | 15 | * Author and maintainer 16 | * Most features develpopment 17 | 18 | * **[Carl Fürstenberg](https://github.com/azatoth)** 19 | 20 | * Debian-friendly Makefile, supports both 'node' and 'nodejs' executables 21 | * Sandbox utility 22 | * Minimal test reporter 23 | 24 | * **[Gerad Suyderhoud](https://github.com/gerad)** 25 | 26 | * First comand-line tool 27 | 28 | * **[Kadir Pekel](https://github.com/kadirpekel)** 29 | 30 | * Improvements to default test reporter 31 | * HTTP test utility 32 | 33 | * **[Λlisue](https://github.com/lambdalisue)** 34 | 35 | * Add machineout reporter 36 | 37 | * **[Matthias Lübken](https://github.com/luebken)** 38 | 39 | * Utility functions for tracking incomplete tests on exit 40 | 41 | * **[Oleg Efimov](https://github.com/Sannis)** 42 | 43 | * Adding 'make lint' and fixing nodelint errors 44 | * Option parsing, --help text and config file support 45 | * Reporters option for command-line tool 46 | 47 | * **[Orlando Vazquez](https://github.com/orlandov)** 48 | 49 | * Added jUnit XML reporter 50 | 51 | * **[Ryan Dahl](https://github.com/ry)** 52 | 53 | * Add package.json 54 | 55 | * **[Sam Stephenson](https://github.com/sstephenson)** 56 | 57 | * Coffee-script support 58 | 59 | * **[Thomas Mayfield](https://github.com/thegreatape)** 60 | 61 | * Async setUp and tearDown support for testCase 62 | 63 | * **[Maciej Małecki](https://github.com/mmalecki)** 64 | 65 | * Removal of `testCase` 66 | 67 | **[Full contributors list](https://github.com/caolan/nodeunit/contributors).** 68 | 69 | -------------------------------------------------------------------------------- /node_modules/nodeunit/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Caolan McMahon 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /node_modules/nodeunit/bin/nodeunit.json: -------------------------------------------------------------------------------- 1 | { 2 | "error_prefix": "\u001B[31m", 3 | "error_suffix": "\u001B[39m", 4 | "ok_prefix": "\u001B[32m", 5 | "ok_suffix": "\u001B[39m", 6 | "bold_prefix": "\u001B[1m", 7 | "bold_suffix": "\u001B[22m", 8 | "assertion_prefix": "\u001B[35m", 9 | "assertion_suffix": "\u001B[39m" 10 | } 11 | -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/console.log.js: -------------------------------------------------------------------------------- 1 | /* 2 | A console.log that won't leave you hanging when node exits 3 | 90% of this file was ripped from node.js 4 | 5 | License: see: https://github.com/joyent/node/blob/master/lib/console.js 6 | */ 7 | 8 | // console object 9 | var formatRegExp = /%[sdj]/g; 10 | function format(f) { 11 | var util = require('util'); 12 | 13 | if (typeof f !== 'string') { 14 | var objects = []; 15 | for (var i = 0; i < arguments.length; i++) { 16 | objects.push(util.inspect(arguments[i])); 17 | } 18 | return objects.join(' '); 19 | } 20 | 21 | 22 | var i = 1; 23 | var args = arguments; 24 | var str = String(f).replace(formatRegExp, function(x) { 25 | switch (x) { 26 | case '%s': return String(args[i++]); 27 | case '%d': return Number(args[i++]); 28 | case '%j': return JSON.stringify(args[i++]); 29 | default: 30 | return x; 31 | } 32 | }); 33 | for (var len = args.length, x = args[i]; i < len; x = args[++i]) { 34 | if (x === null || typeof x !== 'object') { 35 | str += ' ' + x; 36 | } else { 37 | str += ' ' + util.inspect(x); 38 | } 39 | } 40 | return str; 41 | } 42 | 43 | console.log = function() { 44 | var res = process.stdout.write(format.apply(this, arguments) + '\n'); 45 | 46 | // this is the first time stdout got backed up 47 | if (!res && !process.stdout.pendingWrite) { 48 | process.stdout.pendingWrite = true; 49 | 50 | // magic sauce: keep node alive until stdout has flushed 51 | process.stdout.once('drain', function () { 52 | process.stdout.draining = false; 53 | }); 54 | } 55 | }; 56 | -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/History.md: -------------------------------------------------------------------------------- 1 | 2 | 0.4.3 / 2011-06-20 3 | ================== 4 | 5 | * Fixed stacktraces line number when used multiline js expressions [Octave] 6 | 7 | 0.4.2 / 2011-05-11 8 | ================== 9 | 10 | * Added client side support 11 | 12 | 0.4.1 / 2011-04-21 13 | ================== 14 | 15 | * Fixed error context 16 | 17 | 0.4.0 / 2011-04-21 18 | ================== 19 | 20 | * Added; ported jade's error reporting to ejs. [slaskis] 21 | 22 | 0.3.1 / 2011-02-23 23 | ================== 24 | 25 | * Fixed optional `compile()` options 26 | 27 | 0.3.0 / 2011-02-14 28 | ================== 29 | 30 | * Added 'json' filter [Yuriy Bogdanov] 31 | * Use exported version of parse function to allow monkey-patching [Anatoliy Chakkaev] 32 | 33 | 0.2.1 / 2010-10-07 34 | ================== 35 | 36 | * Added filter support 37 | * Fixed _cache_ option. ~4x performance increase 38 | 39 | 0.2.0 / 2010-08-05 40 | ================== 41 | 42 | * Added support for global tag config 43 | * Added custom tag support. Closes #5 44 | * Fixed whitespace bug. Closes #4 45 | 46 | 0.1.0 / 2010-08-04 47 | ================== 48 | 49 | * Faster implementation [ashleydev] 50 | 51 | 0.0.4 / 2010-08-02 52 | ================== 53 | 54 | * Fixed single quotes for content outside of template tags. [aniero] 55 | * Changed; `exports.compile()` now expects only "locals" 56 | 57 | 0.0.3 / 2010-07-15 58 | ================== 59 | 60 | * Fixed single quotes 61 | 62 | 0.0.2 / 2010-07-09 63 | ================== 64 | 65 | * Fixed newline preservation 66 | 67 | 0.0.1 / 2010-07-09 68 | ================== 69 | 70 | * Initial release 71 | -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SRC = $(shell find lib -name "*.js" -type f) 3 | UGLIFY_FLAGS = --no-mangle 4 | 5 | test: 6 | @./node_modules/.bin/expresso test/*.test.js 7 | 8 | ejs.js: $(SRC) 9 | @node support/compile.js $^ 10 | 11 | ejs.min.js: ejs.js 12 | @uglifyjs $(UGLIFY_FLAGS) $< > $@ \ 13 | && du ejs.min.js \ 14 | && du ejs.js 15 | 16 | clean: 17 | rm -f ejs.js 18 | rm -f ejs.min.js 19 | 20 | .PHONY: test -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/benchmark.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var ejs = require('./lib/ejs'), 4 | str = '<% if (foo) { %>

<%= foo %>

<% } %>', 5 | times = 50000; 6 | 7 | console.log('rendering ' + times + ' times'); 8 | 9 | var start = new Date; 10 | while (times--) { 11 | ejs.render(str, { cache: true, filename: 'test', locals: { foo: 'bar' }}); 12 | } 13 | 14 | console.log('took ' + (new Date - start) + 'ms'); -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/examples/client.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/examples/list.ejs: -------------------------------------------------------------------------------- 1 | <% if (names.length) { %> 2 |
    3 | <% names.forEach(function(name){ %> 4 |
  • <%= name %>
  • 5 | <% }) %> 6 |
7 | <% } %> -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/examples/list.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Module dependencies. 4 | */ 5 | 6 | var ejs = require('../') 7 | , fs = require('fs') 8 | , str = fs.readFileSync(__dirname + '/list.ejs', 'utf8'); 9 | 10 | var ret = ejs.render(str, { 11 | locals: { 12 | names: ['foo', 'bar', 'baz'] 13 | } 14 | }); 15 | 16 | console.log(ret); -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/index.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = require('./lib/ejs'); -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/lib/utils.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * EJS 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Escape the given string of `html`. 10 | * 11 | * @param {String} html 12 | * @return {String} 13 | * @api private 14 | */ 15 | 16 | exports.escape = function(html){ 17 | return String(html) 18 | .replace(/&(?!\w+;)/g, '&') 19 | .replace(//g, '>') 21 | .replace(/"/g, '"'); 22 | }; 23 | -------------------------------------------------------------------------------- /node_modules/nodeunit/deps/ejs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ejs", 3 | "description": "Embedded JavaScript templates", 4 | "version": "0.4.3", 5 | "author": "TJ Holowaychuk ", 6 | "keywords": ["template", "engine", "ejs"], 7 | "devDependencies": { 8 | "expresso": "0.9.2" 9 | }, 10 | "main": "./lib/ejs.js" 11 | } -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/bin/nodeunit.json: -------------------------------------------------------------------------------- 1 | { 2 | "error_prefix": "\u001B[31m", 3 | "error_suffix": "\u001B[39m", 4 | "ok_prefix": "\u001B[32m", 5 | "ok_suffix": "\u001B[39m", 6 | "bold_prefix": "\u001B[1m", 7 | "bold_suffix": "\u001B[22m", 8 | "assertion_prefix": "\u001B[35m", 9 | "assertion_suffix": "\u001B[39m" 10 | } 11 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/deps/console.log.js: -------------------------------------------------------------------------------- 1 | /* 2 | A console.log that won't leave you hanging when node exits 3 | 90% of this file was ripped from node.js 4 | 5 | License: see: https://github.com/joyent/node/blob/master/lib/console.js 6 | */ 7 | 8 | // console object 9 | var formatRegExp = /%[sdj]/g; 10 | function format(f) { 11 | var util = require('util'); 12 | 13 | if (typeof f !== 'string') { 14 | var objects = []; 15 | for (var i = 0; i < arguments.length; i++) { 16 | objects.push(util.inspect(arguments[i])); 17 | } 18 | return objects.join(' '); 19 | } 20 | 21 | 22 | var i = 1; 23 | var args = arguments; 24 | var str = String(f).replace(formatRegExp, function(x) { 25 | switch (x) { 26 | case '%s': return String(args[i++]); 27 | case '%d': return Number(args[i++]); 28 | case '%j': return JSON.stringify(args[i++]); 29 | default: 30 | return x; 31 | } 32 | }); 33 | for (var len = args.length, x = args[i]; i < len; x = args[++i]) { 34 | if (x === null || typeof x !== 'object') { 35 | str += ' ' + x; 36 | } else { 37 | str += ' ' + util.inspect(x); 38 | } 39 | } 40 | return str; 41 | } 42 | 43 | console.log = function() { 44 | var res = process.stdout.write(format.apply(this, arguments) + '\n'); 45 | 46 | // this is the first time stdout got backed up 47 | if (!res && !process.stdout.pendingWrite) { 48 | process.stdout.pendingWrite = true; 49 | 50 | // magic sauce: keep node alive until stdout has flushed 51 | process.stdout.once('drain', function () { 52 | process.stdout.draining = false; 53 | }); 54 | } 55 | }; 56 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/deps/ejs.js: -------------------------------------------------------------------------------- 1 | 2 | /*! 3 | * EJS 4 | * Copyright(c) 2010 TJ Holowaychuk 5 | * MIT Licensed 6 | */ 7 | 8 | /** 9 | * Module dependencies. 10 | */ 11 | 12 | var sys = require('sys'); 13 | 14 | /** 15 | * Library version. 16 | */ 17 | 18 | exports.version = '0.0.3'; 19 | 20 | /** 21 | * Intermediate js cache. 22 | * 23 | * @type Object 24 | */ 25 | 26 | var cache = {}; 27 | 28 | /** 29 | * Clear intermediate js cache. 30 | * 31 | * @api public 32 | */ 33 | 34 | exports.clearCache = function(){ 35 | cache = {}; 36 | }; 37 | 38 | /** 39 | * Escape the given string of `html`. 40 | * 41 | * @param {String} html 42 | * @return {String} 43 | * @api private 44 | */ 45 | 46 | function escape(html){ 47 | return String(html) 48 | .replace(/&(?!\w+;)/g, '&') 49 | .replace(//g, '>') 51 | .replace(/"/g, '"'); 52 | } 53 | 54 | /** 55 | * Parse the given `str` of ejs, returning the function body. 56 | * 57 | * @param {String} str 58 | * @return {String} 59 | * @api public 60 | */ 61 | 62 | var parse = exports.parse = function(str){ 63 | return 'var buf = [];\n' 64 | + "with (locals) {\nbuf.push('" 65 | + String(str) 66 | .replace(/[\r\t]/g, " ") 67 | .replace(/\n/g, "\\n") 68 | .split("<%").join("\t") 69 | .replace(/((^|%>)[^\t]*)'/g, "$1\r") 70 | .replace(/\t=(.*?)%>/g, "', escape($1) ,'") 71 | .replace(/\t-(.*?)%>/g, "', $1 ,'") 72 | .split("\t").join("');") 73 | .split("%>").join("buf.push('") 74 | .split("\r").join("\\'") 75 | + "');\n}\nreturn buf.join('');"; 76 | }; 77 | 78 | /** 79 | * Compile the given `str` of ejs into a `Function`. 80 | * 81 | * @param {String} str 82 | * @param {Object} options 83 | * @return {Function} 84 | * @api public 85 | */ 86 | 87 | var compile = exports.compile = function(str, options){ 88 | if (options.debug) sys.puts(parse(str)); 89 | return new Function('locals, escape', parse(str)); 90 | }; 91 | 92 | /** 93 | * Render the given `str` of ejs. 94 | * 95 | * Options: 96 | * 97 | * - `locals` Local variables object 98 | * - `cache` Compiled functions are cached, requires `filename` 99 | * - `filename` Used by `cache` to key caches 100 | * - `context|scope` Function execution context 101 | * - `debug` Output generated function body 102 | * 103 | * @param {String} str 104 | * @param {Object} options 105 | * @return {String} 106 | * @api public 107 | */ 108 | 109 | exports.render = function(str, options){ 110 | var fn, 111 | options = options || {}; 112 | if (options.cache) { 113 | if (options.filename) { 114 | fn = cache[options.filename] = compile(str, options); 115 | } else { 116 | throw new Error('"cache" option requires "filename".'); 117 | } 118 | } else { 119 | fn = compile(str, options); 120 | } 121 | return fn.call( 122 | options.context || options.scope, 123 | options.locals || {}, 124 | escape); 125 | }; -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/index.js: -------------------------------------------------------------------------------- 1 | // This file is just added for convenience so this repository can be 2 | // directly checked out into a project's deps folder 3 | module.exports = require('./lib/nodeunit'); 4 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/lib/.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xianbei/itier/04a11d3515f2186e35ec527aed6453fde3719f2c/node_modules/nodeunit/dist/nodeunit/lib/.swp -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/lib/nodeunit.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * Copyright (c) 2010 Caolan McMahon 4 | * MIT Licensed 5 | */ 6 | 7 | /** 8 | * Module dependencies 9 | */ 10 | 11 | var async = require('../deps/async'), 12 | types = require('./types'), 13 | utils = require('./utils'), 14 | core = require('./core'), 15 | reporters = require('./reporters'), 16 | assert = require('./assert'), 17 | path = require('path') 18 | events = require('events'); 19 | 20 | 21 | /** 22 | * Export sub-modules. 23 | */ 24 | 25 | exports.types = types; 26 | exports.utils = utils; 27 | exports.reporters = reporters; 28 | exports.assert = assert; 29 | 30 | // backwards compatibility 31 | exports.testrunner = { 32 | run: function () { 33 | console.log( 34 | 'WARNING: nodeunit.testrunner is going to be deprecated, please ' + 35 | 'use nodeunit.reporters.default instead!' 36 | ); 37 | return reporters['default'].run.apply(this, arguments); 38 | } 39 | }; 40 | 41 | 42 | /** 43 | * Export all core functions 44 | */ 45 | 46 | for (var k in core) { 47 | exports[k] = core[k]; 48 | }; 49 | 50 | 51 | /** 52 | * Load modules from paths array and run all exported tests in series. If a path 53 | * is a directory, load all supported file types inside it as modules. This only 54 | * reads 1 level deep in the directory and does not recurse through 55 | * sub-directories. 56 | * 57 | * @param {Array} paths 58 | * @param {Object} opt 59 | * @api public 60 | */ 61 | 62 | exports.runFiles = function (paths, opt) { 63 | var all_assertions = []; 64 | var options = types.options(opt); 65 | var start = new Date().getTime(); 66 | 67 | if (!paths.length) { 68 | return options.done(types.assertionList(all_assertions)); 69 | } 70 | 71 | utils.modulePaths(paths, function (err, files) { 72 | if (err) throw err; 73 | async.concatSeries(files, function (file, cb) { 74 | var name = path.basename(file); 75 | exports.runModule(name, require(file), options, cb); 76 | }, 77 | function (err, all_assertions) { 78 | var end = new Date().getTime(); 79 | exports.done() 80 | options.done(types.assertionList(all_assertions, end - start)); 81 | }); 82 | }); 83 | 84 | }; 85 | 86 | /* Export all prototypes from events.EventEmitter */ 87 | var label; 88 | for (label in events.EventEmitter.prototype) { 89 | exports[label] = events.EventEmitter.prototype[label]; 90 | } 91 | 92 | /* Emit event 'complete' on completion of a test suite. */ 93 | exports.complete = function(name, assertions) 94 | { 95 | exports.emit('complete', name, assertions); 96 | }; 97 | 98 | /* Emit event 'complete' on completion of all tests. */ 99 | exports.done = function() 100 | { 101 | exports.emit('done'); 102 | }; 103 | 104 | module.exports = exports; 105 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/lib/reporters/eclipse.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * Copyright (c) 2010 Caolan McMahon 4 | * MIT Licensed 5 | */ 6 | 7 | /** 8 | * Module dependencies 9 | */ 10 | 11 | var nodeunit = require('../nodeunit'), 12 | utils = require('../utils'), 13 | fs = require('fs'), 14 | track = require('../track'), 15 | path = require('path'), 16 | AssertionError = require('../assert').AssertionError; 17 | 18 | /** 19 | * Reporter info string 20 | */ 21 | 22 | exports.info = "Reporter for eclipse plugin"; 23 | 24 | 25 | /** 26 | * Run all tests within each module, reporting the results to the command-line. 27 | * 28 | * @param {Array} files 29 | * @api public 30 | */ 31 | 32 | exports.run = function (files, options, callback) { 33 | 34 | var start = new Date().getTime(); 35 | var paths = files.map(function (p) { 36 | if (p.indexOf('/') === 0) { 37 | return p; 38 | } 39 | return path.join(process.cwd(), p); 40 | }); 41 | var tracker = track.createTracker(function (tracker) { 42 | if (tracker.unfinished()) { 43 | console.log(''); 44 | console.log('FAILURES: Undone tests (or their setups/teardowns): '); 45 | var names = tracker.names(); 46 | for (var i = 0; i < names.length; i += 1) { 47 | console.log('- ' + names[i]); 48 | } 49 | console.log(''); 50 | console.log('To fix this, make sure all tests call test.done()'); 51 | process.reallyExit(tracker.unfinished()); 52 | } 53 | }); 54 | 55 | nodeunit.runFiles(paths, { 56 | testspec: undefined, 57 | moduleStart: function (name) { 58 | console.log('\n' + name); 59 | }, 60 | testDone: function (name, assertions) { 61 | tracker.remove(name); 62 | 63 | if (!assertions.failures()) { 64 | console.log('✔ ' + name); 65 | } 66 | else { 67 | console.log('✖ ' + name + '\n'); 68 | assertions.forEach(function (a) { 69 | if (a.failed()) { 70 | a = utils.betterErrors(a); 71 | if (a.error instanceof AssertionError && a.message) { 72 | console.log( 73 | 'Assertion Message: ' + a.message 74 | ); 75 | } 76 | console.log(a.error.stack + '\n'); 77 | } 78 | }); 79 | } 80 | }, 81 | done: function (assertions, end) { 82 | var end = end || new Date().getTime(); 83 | var duration = end - start; 84 | if (assertions.failures()) { 85 | console.log( 86 | '\n' + 'FAILURES: ' + assertions.failures() + 87 | '/' + assertions.length + ' assertions failed (' + 88 | assertions.duration + 'ms)' 89 | ); 90 | } 91 | else { 92 | console.log( 93 | '\n' + 'OK: ' + assertions.length + 94 | ' assertions (' + assertions.duration + 'ms)' 95 | ); 96 | } 97 | 98 | if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined); 99 | }, 100 | testStart: function (name) { 101 | tracker.put(name); 102 | } 103 | }); 104 | }; 105 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/lib/reporters/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'junit': require('./junit'), 3 | 'default': require('./default'), 4 | 'skip_passed': require('./skip_passed'), 5 | 'minimal': require('./minimal'), 6 | 'html': require('./html'), 7 | 'eclipse': require('./eclipse'), 8 | 'machineout': require('./machineout'), 9 | 'tap': require('./tap'), 10 | 'nested': require('./nested'), 11 | 'verbose' : require('./verbose') 12 | // browser test reporter is not listed because it cannot be used 13 | // with the command line tool, only inside a browser. 14 | }; 15 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/lib/reporters/skip_passed.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * Copyright (c) 2010 Caolan McMahon 4 | * MIT Licensed 5 | */ 6 | 7 | /** 8 | * Module dependencies 9 | */ 10 | 11 | var nodeunit = require('../nodeunit'), 12 | utils = require('../utils'), 13 | fs = require('fs'), 14 | path = require('path'), 15 | AssertionError = require('assert').AssertionError; 16 | 17 | /** 18 | * Reporter info string 19 | */ 20 | 21 | exports.info = "Skip passed tests output"; 22 | 23 | /** 24 | * Run all tests within each module, reporting the results to the command-line. 25 | * 26 | * @param {Array} files 27 | * @api public 28 | */ 29 | 30 | exports.run = function (files, options, callback) { 31 | 32 | if (!options) { 33 | // load default options 34 | var content = fs.readFileSync( 35 | __dirname + '/../../bin/nodeunit.json', 'utf8' 36 | ); 37 | options = JSON.parse(content); 38 | } 39 | 40 | var error = function (str) { 41 | return options.error_prefix + str + options.error_suffix; 42 | }; 43 | var ok = function (str) { 44 | return options.ok_prefix + str + options.ok_suffix; 45 | }; 46 | var bold = function (str) { 47 | return options.bold_prefix + str + options.bold_suffix; 48 | }; 49 | var assertion_message = function (str) { 50 | return options.assertion_prefix + str + options.assertion_suffix; 51 | }; 52 | 53 | var start = new Date().getTime(); 54 | var paths = files.map(function (p) { 55 | return path.join(process.cwd(), p); 56 | }); 57 | 58 | nodeunit.runFiles(paths, { 59 | testspec: options.testspec, 60 | moduleStart: function (name) { 61 | console.log('\n' + bold(name)); 62 | }, 63 | testDone: function (name, assertions) { 64 | if (assertions.failures()) { 65 | console.log(error('✖ ' + name) + '\n'); 66 | assertions.forEach(function (a) { 67 | if (a.failed()) { 68 | a = utils.betterErrors(a); 69 | if (a.error instanceof AssertionError && a.message) { 70 | console.log( 71 | 'Assertion Message: ' + assertion_message(a.message) 72 | ); 73 | } 74 | console.log(a.error.stack + '\n'); 75 | } 76 | }); 77 | } 78 | }, 79 | moduleDone: function (name, assertions) { 80 | if (!assertions.failures()) { 81 | console.log('✔ all tests passed'); 82 | } 83 | else { 84 | console.log(error('✖ some tests failed')); 85 | } 86 | }, 87 | done: function (assertions) { 88 | var end = new Date().getTime(); 89 | var duration = end - start; 90 | if (assertions.failures()) { 91 | console.log( 92 | '\n' + bold(error('FAILURES: ')) + assertions.failures() + 93 | '/' + assertions.length + ' assertions failed (' + 94 | assertions.duration + 'ms)' 95 | ); 96 | } 97 | else { 98 | console.log( 99 | '\n' + bold(ok('OK: ')) + assertions.length + 100 | ' assertions (' + assertions.duration + 'ms)' 101 | ); 102 | } 103 | 104 | if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined); 105 | } 106 | }); 107 | }; 108 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/lib/reporters/tap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module dependencies 3 | */ 4 | 5 | var nodeunit = require('../nodeunit'), 6 | path = require('path'), 7 | assert = require('tap-assert'), 8 | TapProducer = require('tap-producer'); 9 | 10 | /** 11 | * Reporter info string 12 | */ 13 | 14 | exports.info = "TAP output"; 15 | 16 | /** 17 | * Run all tests within each module, reporting the results to the command-line. 18 | * 19 | * @param {Array} files 20 | * @api public 21 | */ 22 | 23 | exports.run = function (files, options) { 24 | 25 | if (!options) { 26 | // load default options 27 | var content = fs.readFileSync( 28 | __dirname + '/../../bin/nodeunit.json', 'utf8' 29 | ); 30 | options = JSON.parse(content); 31 | } 32 | 33 | var paths = files.map(function (p) { 34 | return path.join(process.cwd(), p); 35 | }); 36 | var output = new TapProducer(); 37 | output.pipe(process.stdout); 38 | 39 | nodeunit.runFiles(paths, { 40 | testStart: function (name) { 41 | output.write(name.toString()); 42 | }, 43 | testDone: function (name, assertions) { 44 | assertions.forEach(function (e) { 45 | var extra = {}; 46 | if (e.error) { 47 | extra.error = { 48 | name: e.error.name, 49 | message: e.error.message, 50 | stack: e.error.stack.split(/\n/).filter(function (line) { 51 | // exclude line of "types.js" 52 | return ! RegExp(/types.js:83:39/).test(line); 53 | }).join('\n') 54 | }; 55 | extra.wanted = e.error.expected; 56 | extra.found = e.error.actual; 57 | } 58 | output.write(assert(e.passed(), e.message, extra)); 59 | }); 60 | }, 61 | done: function (assertions) { 62 | output.end(); 63 | } 64 | }); 65 | }; 66 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/lib/track.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Simple util module to track tests. Adds a process.exit hook to print 3 | * the undone tests. 4 | */ 5 | 6 | 7 | exports.createTracker = function (on_exit) { 8 | var names = {}; 9 | var tracker = { 10 | names: function () { 11 | var arr = []; 12 | for (var k in names) { 13 | if (names.hasOwnProperty(k)) { 14 | arr.push(k); 15 | } 16 | } 17 | return arr; 18 | }, 19 | unfinished: function () { 20 | return tracker.names().length; 21 | }, 22 | put: function (testname) { 23 | names[testname] = testname; 24 | }, 25 | remove: function (testname) { 26 | delete names[testname]; 27 | } 28 | }; 29 | 30 | process.on('exit', function() { 31 | on_exit = on_exit || exports.default_on_exit; 32 | on_exit(tracker); 33 | }); 34 | 35 | return tracker; 36 | }; 37 | 38 | exports.default_on_exit = function (tracker) { 39 | if (tracker.unfinished()) { 40 | console.log(''); 41 | console.log('Undone tests (or their setups/teardowns): '); 42 | var names = tracker.names(); 43 | for (var i = 0; i < names.length; i += 1) { 44 | console.log(names[i]); 45 | } 46 | process.reallyExit(tracker.unfinished()); 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/package.json: -------------------------------------------------------------------------------- 1 | { "name": "nodeunit" 2 | , "description": "Easy unit testing for node.js and the browser." 3 | , "maintainers": 4 | [ { "name": "Caolan McMahon" 5 | , "web": "https://github.com/caolan" 6 | } 7 | ] 8 | , "contributors" : 9 | [ { "name": "Romain Beauxis" 10 | , "web": "https://github.com/toots" 11 | } 12 | , { "name": "Alex Gorbatchev" 13 | , "web": "https://github.com/alexgorbatchev" 14 | } 15 | , { "name": "Alex Wolfe" 16 | , "web": "https://github.com/alexkwolfe" 17 | } 18 | , { "name": "Carl Fürstenberg" 19 | , "web": "https://github.com/azatoth" 20 | } 21 | , { "name": "Gerad Suyderhoud" 22 | , "web": "https://github.com/gerad" 23 | } 24 | , { "name": "Kadir Pekel" 25 | , "web": "https://github.com/coffeemate" 26 | } 27 | , { "name": "Oleg Efimov" 28 | , "web": "https://github.com/Sannis" 29 | } 30 | , { "name": "Orlando Vazquez" 31 | , "web": "https://github.com/orlandov" 32 | } 33 | , { "name": "Ryan Dahl" 34 | , "web": "https://github.com/ry" 35 | } 36 | , { "name": "Sam Stephenson" 37 | , "web": "https://github.com/sstephenson" 38 | } 39 | , { "name": "Thomas Mayfield" 40 | , "web": "https://github.com/thegreatape" 41 | } 42 | , { "name": "Elijah Insua ", 43 | "web": "http://tmpvar.com" 44 | } 45 | ] 46 | , "version": "0.6.1" 47 | , "repository" : 48 | { "type" : "git" 49 | , "url" : "http://github.com/caolan/nodeunit.git" 50 | } 51 | , "devDependencies": 52 | { "uglify-js": ">=1.1.0" } 53 | , "bugs" : { "url" : "http://github.com/caolan/nodeunit/issues" } 54 | , "licenses" : 55 | [ { "type" : "MIT" 56 | , "url" : "http://github.com/caolan/nodeunit/raw/master/LICENSE" 57 | } 58 | ] 59 | , "directories" : { "lib": "./lib", "doc" : "./doc", "man" : "./man1" } 60 | , "bin" : { "nodeunit" : "./bin/nodeunit" } 61 | , "dependencies" : 62 | { "tap-assert": ">=0.0.9" 63 | , "tap-producer": ">=0.0.1" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/share/junit.xml.ejs: -------------------------------------------------------------------------------- 1 | 2 | <% for (var i=0; i < suites.length; i++) { %> 3 | <% var suite=suites[i]; %> 4 | 8 | <% for (var j=0; j < suite.testcases.length; j++) { %> 9 | <% var testcase=suites[i].testcases[j]; %> 10 | 11 | <% if (testcase.failure) { %> 12 | 13 | <% if (testcase.failure.backtrace) { %><%= testcase.failure.backtrace %><% } %> 14 | 15 | <% } %> 16 | 17 | <% } %> 18 | 19 | <% } %> 20 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/share/license.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * https://github.com/caolan/nodeunit 4 | * Copyright (c) 2010 Caolan McMahon 5 | * MIT Licensed 6 | * 7 | * json2.js 8 | * http://www.JSON.org/json2.js 9 | * Public Domain. 10 | * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. 11 | */ 12 | -------------------------------------------------------------------------------- /node_modules/nodeunit/dist/nodeunit/share/nodeunit.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Styles taken from qunit.css 3 | */ 4 | 5 | h1#nodeunit-header, h1.nodeunit-header { 6 | padding: 15px; 7 | font-size: large; 8 | background-color: #06b; 9 | color: white; 10 | font-family: 'trebuchet ms', verdana, arial; 11 | margin: 0; 12 | } 13 | 14 | h1#nodeunit-header a { 15 | color: white; 16 | } 17 | 18 | h2#nodeunit-banner { 19 | height: 2em; 20 | border-bottom: 1px solid white; 21 | background-color: #eee; 22 | margin: 0; 23 | font-family: 'trebuchet ms', verdana, arial; 24 | } 25 | h2#nodeunit-banner.pass { 26 | background-color: green; 27 | } 28 | h2#nodeunit-banner.fail { 29 | background-color: red; 30 | } 31 | 32 | h2#nodeunit-userAgent, h2.nodeunit-userAgent { 33 | padding: 10px; 34 | background-color: #eee; 35 | color: black; 36 | margin: 0; 37 | font-size: small; 38 | font-weight: normal; 39 | font-family: 'trebuchet ms', verdana, arial; 40 | font-size: 10pt; 41 | } 42 | 43 | div#nodeunit-testrunner-toolbar { 44 | background: #eee; 45 | border-top: 1px solid black; 46 | padding: 10px; 47 | font-family: 'trebuchet ms', verdana, arial; 48 | margin: 0; 49 | font-size: 10pt; 50 | } 51 | 52 | ol#nodeunit-tests { 53 | font-family: 'trebuchet ms', verdana, arial; 54 | font-size: 10pt; 55 | } 56 | ol#nodeunit-tests li strong { 57 | cursor:pointer; 58 | } 59 | ol#nodeunit-tests .pass { 60 | color: green; 61 | } 62 | ol#nodeunit-tests .fail { 63 | color: red; 64 | } 65 | 66 | p#nodeunit-testresult { 67 | margin-left: 1em; 68 | font-size: 10pt; 69 | font-family: 'trebuchet ms', verdana, arial; 70 | } 71 | -------------------------------------------------------------------------------- /node_modules/nodeunit/doc/nodeunit.md: -------------------------------------------------------------------------------- 1 | nodeunit(1) -- simple node.js unit testing tool 2 | =============================================== 3 | 4 | ## SYNOPSIS 5 | 6 | nodeunit [options] [ ...] 7 | 8 | ## DESCRIPTION 9 | 10 | Nodeunit is a simple unit testing tool based on the node.js assert module. 11 | 12 | * Simple to use 13 | * Just export the tests from a module 14 | * Helps you avoid common pitfalls when testing asynchronous code 15 | * Easy to add test cases with setUp and tearDown functions if you wish 16 | * Allows the use of mocks and stubs 17 | 18 | ## OPTIONS 19 | 20 | __--config FILE__: 21 | Load config options from a JSON file, allows the customisation 22 | of color schemes for the default test reporter etc. 23 | See bin/nodeunit.json for current available options. 24 | 25 | __--reporter FILE__: 26 | You can set the test reporter to a custom module or on of the modules 27 | in nodeunit/lib/reporters, when omitted, the default test runner is used. 28 | 29 | __--list-reporters__: 30 | List available build-in reporters. 31 | 32 | __-h__, __--help__: 33 | Display the help and exit. 34 | 35 | __-v__, __--version__: 36 | Output version information and exit. 37 | 38 | ____: 39 | You can run nodeunit on specific files or on all *\*.js* files inside 40 | a directory. 41 | 42 | ## AUTHORS 43 | 44 | Written by Caolan McMahon and other nodeunit contributors. 45 | Contributors list: . 46 | 47 | ## REPORTING BUGS 48 | 49 | Report nodeunit bugs to . 50 | 51 | ## COPYRIGHT 52 | 53 | Copyright © 2010 Caolan McMahon. 54 | Nodeunit has been released under the MIT license: 55 | . 56 | 57 | ## SEE ALSO 58 | 59 | node(1) 60 | 61 | -------------------------------------------------------------------------------- /node_modules/nodeunit/examples/browser/suite1.js: -------------------------------------------------------------------------------- 1 | this.suite1 = { 2 | 'test one': function (test) { 3 | test.ok(true, 'everythings ok'); 4 | setTimeout(function () { 5 | test.done(); 6 | }, 10); 7 | }, 8 | 'apples and oranges': function (test) { 9 | test.equal('apples', 'oranges', 'comparing apples and oranges'); 10 | test.done(); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /node_modules/nodeunit/examples/browser/suite2.js: -------------------------------------------------------------------------------- 1 | this.suite2 = { 2 | 'another test': function (test) { 3 | setTimeout(function () { 4 | // lots of assertions 5 | test.ok(true, 'everythings ok'); 6 | test.ok(true, 'everythings ok'); 7 | test.ok(true, 'everythings ok'); 8 | test.ok(true, 'everythings ok'); 9 | test.ok(true, 'everythings ok'); 10 | test.done(); 11 | }, 10); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /node_modules/nodeunit/examples/browser/suite3.js: -------------------------------------------------------------------------------- 1 | this.suite3 = { 2 | 'test for ie6,7,8': function (test) { 3 | test.deepEqual(["test"], ["test"]); 4 | test.notDeepEqual(["a"], ["b"]); 5 | test.done(); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /node_modules/nodeunit/examples/browser/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Example tests 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /node_modules/nodeunit/examples/nested/nested_reporter_test.unit.js: -------------------------------------------------------------------------------- 1 | var testCase = require('nodeunit').testCase; 2 | /* 3 | This is an example test suite to demonstrate the nested test reporter. 4 | Run with --reporter nested, e.g., 5 | nodeunit --reporter nested nested_reporter_test.unit.js 6 | 7 | The test output should be something like: 8 | 9 | nested_reporter_test.unit.js 10 | Test 0.1 (pass) 11 | TC 1 12 | TC 1.1 13 | Test 1.1.1 (pass) 14 | TC 2 15 | TC 2.1 16 | TC 2.1.1 17 | Test 2.1.1.1 (pass) 18 | Test 2.1.1.2 (pass) 19 | TC 2.2.1 20 | Test 2.2.1.1 (pass) 21 | TC 2.2.1.1 22 | Test 2.2.1.1.1 (pass) 23 | Test 2.2.1.2 (pass) 24 | TC 3 25 | TC 3.1 26 | TC 3.1.1 27 | Test 3.1.1.1 (should fail) (fail) ✖ 28 | AssertionError: false == true 29 | // stack trace here. 30 | 31 | FAILURES: 1/8 assertions failed (6ms) 32 | */ 33 | 34 | module.exports = testCase({ 35 | "Test 0.1": function(test) { 36 | test.ok(true); 37 | test.done(); 38 | }, 39 | 40 | "TC 1": testCase({ 41 | "TC 1.1": testCase({ 42 | "Test 1.1.1": function(test) { 43 | test.ok(true); 44 | test.done(); 45 | } 46 | }) 47 | }), 48 | 49 | "TC 2": testCase({ 50 | "TC 2.1": testCase({ 51 | "TC 2.1.1": testCase({ 52 | "Test 2.1.1.1": function(test) { 53 | test.ok(true); 54 | test.done(); 55 | }, 56 | 57 | "Test 2.1.1.2": function(test) { 58 | test.ok(true); 59 | test.done(); 60 | } 61 | }), 62 | 63 | "TC 2.2.1": testCase({ 64 | "Test 2.2.1.1": function(test) { 65 | test.ok(true); 66 | test.done(); 67 | }, 68 | 69 | "TC 2.2.1.1": testCase({ 70 | "Test 2.2.1.1.1": function(test) { 71 | test.ok(true); 72 | test.done(); 73 | }, 74 | }), 75 | 76 | "Test 2.2.1.2": function(test) { 77 | test.ok(true); 78 | test.done(); 79 | } 80 | }) 81 | }) 82 | }), 83 | 84 | "TC 3": testCase({ 85 | "TC 3.1": testCase({ 86 | "TC 3.1.1": testCase({ 87 | "Test 3.1.1.1 (should fail)": function(test) { 88 | test.ok(false); 89 | test.done(); 90 | } 91 | }) 92 | }) 93 | }) 94 | }); 95 | -------------------------------------------------------------------------------- /node_modules/nodeunit/img/example_fail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xianbei/itier/04a11d3515f2186e35ec527aed6453fde3719f2c/node_modules/nodeunit/img/example_fail.png -------------------------------------------------------------------------------- /node_modules/nodeunit/img/example_machineout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xianbei/itier/04a11d3515f2186e35ec527aed6453fde3719f2c/node_modules/nodeunit/img/example_machineout.png -------------------------------------------------------------------------------- /node_modules/nodeunit/img/example_pass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xianbei/itier/04a11d3515f2186e35ec527aed6453fde3719f2c/node_modules/nodeunit/img/example_pass.png -------------------------------------------------------------------------------- /node_modules/nodeunit/index.js: -------------------------------------------------------------------------------- 1 | // This file is just added for convenience so this repository can be 2 | // directly checked out into a project's deps folder 3 | module.exports = require('./lib/nodeunit'); 4 | -------------------------------------------------------------------------------- /node_modules/nodeunit/lib/nodeunit.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * Copyright (c) 2010 Caolan McMahon 4 | * MIT Licensed 5 | */ 6 | 7 | /** 8 | * Module dependencies 9 | */ 10 | 11 | var async = require('../deps/async'), 12 | types = require('./types'), 13 | utils = require('./utils'), 14 | core = require('./core'), 15 | reporters = require('./reporters'), 16 | assert = require('./assert'), 17 | path = require('path') 18 | events = require('events'); 19 | 20 | 21 | /** 22 | * Export sub-modules. 23 | */ 24 | 25 | exports.types = types; 26 | exports.utils = utils; 27 | exports.reporters = reporters; 28 | exports.assert = assert; 29 | 30 | // backwards compatibility 31 | exports.testrunner = { 32 | run: function () { 33 | console.log( 34 | 'WARNING: nodeunit.testrunner is going to be deprecated, please ' + 35 | 'use nodeunit.reporters.default instead!' 36 | ); 37 | return reporters['default'].run.apply(this, arguments); 38 | } 39 | }; 40 | 41 | 42 | /** 43 | * Export all core functions 44 | */ 45 | 46 | for (var k in core) { 47 | exports[k] = core[k]; 48 | }; 49 | 50 | 51 | /** 52 | * Load modules from paths array and run all exported tests in series. If a path 53 | * is a directory, load all supported file types inside it as modules. This only 54 | * reads 1 level deep in the directory and does not recurse through 55 | * sub-directories. 56 | * 57 | * @param {Array} paths 58 | * @param {Object} opt 59 | * @api public 60 | */ 61 | 62 | exports.runFiles = function (paths, opt) { 63 | var all_assertions = []; 64 | var options = types.options(opt); 65 | var start = new Date().getTime(); 66 | 67 | if (!paths.length) { 68 | return options.done(types.assertionList(all_assertions)); 69 | } 70 | 71 | utils.modulePaths(paths, function (err, files) { 72 | if (err) throw err; 73 | async.concatSeries(files, function (file, cb) { 74 | var name = path.basename(file); 75 | exports.runModule(name, require(file), options, cb); 76 | }, 77 | function (err, all_assertions) { 78 | var end = new Date().getTime(); 79 | exports.done() 80 | options.done(types.assertionList(all_assertions, end - start)); 81 | }); 82 | }); 83 | 84 | }; 85 | 86 | /* Export all prototypes from events.EventEmitter */ 87 | var label; 88 | for (label in events.EventEmitter.prototype) { 89 | exports[label] = events.EventEmitter.prototype[label]; 90 | } 91 | 92 | /* Emit event 'complete' on completion of a test suite. */ 93 | exports.complete = function(name, assertions) 94 | { 95 | exports.emit('complete', name, assertions); 96 | }; 97 | 98 | /* Emit event 'complete' on completion of all tests. */ 99 | exports.done = function() 100 | { 101 | exports.emit('done'); 102 | }; 103 | 104 | module.exports = exports; 105 | -------------------------------------------------------------------------------- /node_modules/nodeunit/lib/reporters/eclipse.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * Copyright (c) 2010 Caolan McMahon 4 | * MIT Licensed 5 | */ 6 | 7 | /** 8 | * Module dependencies 9 | */ 10 | 11 | var nodeunit = require('../nodeunit'), 12 | utils = require('../utils'), 13 | fs = require('fs'), 14 | track = require('../track'), 15 | path = require('path'), 16 | AssertionError = require('../assert').AssertionError; 17 | 18 | /** 19 | * Reporter info string 20 | */ 21 | 22 | exports.info = "Reporter for eclipse plugin"; 23 | 24 | 25 | /** 26 | * Run all tests within each module, reporting the results to the command-line. 27 | * 28 | * @param {Array} files 29 | * @api public 30 | */ 31 | 32 | exports.run = function (files, options, callback) { 33 | 34 | var start = new Date().getTime(); 35 | var paths = files.map(function (p) { 36 | if (p.indexOf('/') === 0) { 37 | return p; 38 | } 39 | return path.join(process.cwd(), p); 40 | }); 41 | var tracker = track.createTracker(function (tracker) { 42 | if (tracker.unfinished()) { 43 | console.log(''); 44 | console.log('FAILURES: Undone tests (or their setups/teardowns): '); 45 | var names = tracker.names(); 46 | for (var i = 0; i < names.length; i += 1) { 47 | console.log('- ' + names[i]); 48 | } 49 | console.log(''); 50 | console.log('To fix this, make sure all tests call test.done()'); 51 | process.reallyExit(tracker.unfinished()); 52 | } 53 | }); 54 | 55 | nodeunit.runFiles(paths, { 56 | testspec: undefined, 57 | moduleStart: function (name) { 58 | console.log('\n' + name); 59 | }, 60 | testDone: function (name, assertions) { 61 | tracker.remove(name); 62 | 63 | if (!assertions.failures()) { 64 | console.log('✔ ' + name); 65 | } 66 | else { 67 | console.log('✖ ' + name + '\n'); 68 | assertions.forEach(function (a) { 69 | if (a.failed()) { 70 | a = utils.betterErrors(a); 71 | if (a.error instanceof AssertionError && a.message) { 72 | console.log( 73 | 'Assertion Message: ' + a.message 74 | ); 75 | } 76 | console.log(a.error.stack + '\n'); 77 | } 78 | }); 79 | } 80 | }, 81 | done: function (assertions, end) { 82 | var end = end || new Date().getTime(); 83 | var duration = end - start; 84 | if (assertions.failures()) { 85 | console.log( 86 | '\n' + 'FAILURES: ' + assertions.failures() + 87 | '/' + assertions.length + ' assertions failed (' + 88 | assertions.duration + 'ms)' 89 | ); 90 | } 91 | else { 92 | console.log( 93 | '\n' + 'OK: ' + assertions.length + 94 | ' assertions (' + assertions.duration + 'ms)' 95 | ); 96 | } 97 | 98 | if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined); 99 | }, 100 | testStart: function (name) { 101 | tracker.put(name); 102 | } 103 | }); 104 | }; 105 | -------------------------------------------------------------------------------- /node_modules/nodeunit/lib/reporters/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'junit': require('./junit'), 3 | 'default': require('./default'), 4 | 'skip_passed': require('./skip_passed'), 5 | 'minimal': require('./minimal'), 6 | 'html': require('./html'), 7 | 'eclipse': require('./eclipse'), 8 | 'machineout': require('./machineout'), 9 | 'tap': require('./tap'), 10 | 'nested': require('./nested'), 11 | 'verbose' : require('./verbose') 12 | // browser test reporter is not listed because it cannot be used 13 | // with the command line tool, only inside a browser. 14 | }; 15 | -------------------------------------------------------------------------------- /node_modules/nodeunit/lib/reporters/skip_passed.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * Copyright (c) 2010 Caolan McMahon 4 | * MIT Licensed 5 | */ 6 | 7 | /** 8 | * Module dependencies 9 | */ 10 | 11 | var nodeunit = require('../nodeunit'), 12 | utils = require('../utils'), 13 | fs = require('fs'), 14 | path = require('path'), 15 | AssertionError = require('assert').AssertionError; 16 | 17 | /** 18 | * Reporter info string 19 | */ 20 | 21 | exports.info = "Skip passed tests output"; 22 | 23 | /** 24 | * Run all tests within each module, reporting the results to the command-line. 25 | * 26 | * @param {Array} files 27 | * @api public 28 | */ 29 | 30 | exports.run = function (files, options, callback) { 31 | 32 | if (!options) { 33 | // load default options 34 | var content = fs.readFileSync( 35 | __dirname + '/../../bin/nodeunit.json', 'utf8' 36 | ); 37 | options = JSON.parse(content); 38 | } 39 | 40 | var error = function (str) { 41 | return options.error_prefix + str + options.error_suffix; 42 | }; 43 | var ok = function (str) { 44 | return options.ok_prefix + str + options.ok_suffix; 45 | }; 46 | var bold = function (str) { 47 | return options.bold_prefix + str + options.bold_suffix; 48 | }; 49 | var assertion_message = function (str) { 50 | return options.assertion_prefix + str + options.assertion_suffix; 51 | }; 52 | 53 | var start = new Date().getTime(); 54 | var paths = files.map(function (p) { 55 | return path.join(process.cwd(), p); 56 | }); 57 | 58 | nodeunit.runFiles(paths, { 59 | testspec: options.testspec, 60 | moduleStart: function (name) { 61 | console.log('\n' + bold(name)); 62 | }, 63 | testDone: function (name, assertions) { 64 | if (assertions.failures()) { 65 | console.log(error('✖ ' + name) + '\n'); 66 | assertions.forEach(function (a) { 67 | if (a.failed()) { 68 | a = utils.betterErrors(a); 69 | if (a.error instanceof AssertionError && a.message) { 70 | console.log( 71 | 'Assertion Message: ' + assertion_message(a.message) 72 | ); 73 | } 74 | console.log(a.error.stack + '\n'); 75 | } 76 | }); 77 | } 78 | }, 79 | moduleDone: function (name, assertions) { 80 | if (!assertions.failures()) { 81 | console.log('✔ all tests passed'); 82 | } 83 | else { 84 | console.log(error('✖ some tests failed')); 85 | } 86 | }, 87 | done: function (assertions) { 88 | var end = new Date().getTime(); 89 | var duration = end - start; 90 | if (assertions.failures()) { 91 | console.log( 92 | '\n' + bold(error('FAILURES: ')) + assertions.failures() + 93 | '/' + assertions.length + ' assertions failed (' + 94 | assertions.duration + 'ms)' 95 | ); 96 | } 97 | else { 98 | console.log( 99 | '\n' + bold(ok('OK: ')) + assertions.length + 100 | ' assertions (' + assertions.duration + 'ms)' 101 | ); 102 | } 103 | 104 | if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined); 105 | } 106 | }); 107 | }; 108 | -------------------------------------------------------------------------------- /node_modules/nodeunit/lib/reporters/tap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module dependencies 3 | */ 4 | 5 | var nodeunit = require('../nodeunit'), 6 | path = require('path'), 7 | assert = require('tap-assert'), 8 | TapProducer = require('tap-producer'); 9 | 10 | /** 11 | * Reporter info string 12 | */ 13 | 14 | exports.info = "TAP output"; 15 | 16 | /** 17 | * Run all tests within each module, reporting the results to the command-line. 18 | * 19 | * @param {Array} files 20 | * @api public 21 | */ 22 | 23 | exports.run = function (files, options) { 24 | 25 | if (!options) { 26 | // load default options 27 | var content = fs.readFileSync( 28 | __dirname + '/../../bin/nodeunit.json', 'utf8' 29 | ); 30 | options = JSON.parse(content); 31 | } 32 | 33 | var paths = files.map(function (p) { 34 | return path.join(process.cwd(), p); 35 | }); 36 | var output = new TapProducer(); 37 | output.pipe(process.stdout); 38 | 39 | nodeunit.runFiles(paths, { 40 | testStart: function (name) { 41 | output.write(name.toString()); 42 | }, 43 | testDone: function (name, assertions) { 44 | assertions.forEach(function (e) { 45 | var extra = {}; 46 | if (e.error) { 47 | extra.error = { 48 | name: e.error.name, 49 | message: e.error.message, 50 | stack: e.error.stack.split(/\n/).filter(function (line) { 51 | // exclude line of "types.js" 52 | return ! RegExp(/types.js:83:39/).test(line); 53 | }).join('\n') 54 | }; 55 | extra.wanted = e.error.expected; 56 | extra.found = e.error.actual; 57 | } 58 | output.write(assert(e.passed(), e.message, extra)); 59 | }); 60 | }, 61 | done: function (assertions) { 62 | output.end(); 63 | } 64 | }); 65 | }; 66 | -------------------------------------------------------------------------------- /node_modules/nodeunit/lib/track.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Simple util module to track tests. Adds a process.exit hook to print 3 | * the undone tests. 4 | */ 5 | 6 | 7 | exports.createTracker = function (on_exit) { 8 | var names = {}; 9 | var tracker = { 10 | names: function () { 11 | var arr = []; 12 | for (var k in names) { 13 | if (names.hasOwnProperty(k)) { 14 | arr.push(k); 15 | } 16 | } 17 | return arr; 18 | }, 19 | unfinished: function () { 20 | return tracker.names().length; 21 | }, 22 | put: function (testname) { 23 | names[testname] = testname; 24 | }, 25 | remove: function (testname) { 26 | delete names[testname]; 27 | } 28 | }; 29 | 30 | process.on('exit', function() { 31 | on_exit = on_exit || exports.default_on_exit; 32 | on_exit(tracker); 33 | }); 34 | 35 | return tracker; 36 | }; 37 | 38 | exports.default_on_exit = function (tracker) { 39 | if (tracker.unfinished()) { 40 | console.log(''); 41 | console.log('Undone tests (or their setups/teardowns): '); 42 | var names = tracker.names(); 43 | for (var i = 0; i < names.length; i += 1) { 44 | console.log(names[i]); 45 | } 46 | process.reallyExit(tracker.unfinished()); 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /node_modules/nodeunit/man1/nodeunit.1: -------------------------------------------------------------------------------- 1 | .\" Generated with Ronnjs/v0.1 2 | .\" http://github.com/kapouer/ronnjs/ 3 | . 4 | .TH "NODEUNIT" "1" "October 2010" "" "" 5 | . 6 | .SH "NAME" 7 | \fBnodeunit\fR \-\- simple node\.js unit testing tool 8 | . 9 | .SH "SYNOPSIS" 10 | . 11 | .nf 12 | nodeunit [options] [ \.\.\.] 13 | . 14 | .fi 15 | . 16 | .SH "DESCRIPTION" 17 | Nodeunit is a simple unit testing tool based on the node\.js assert module\. 18 | . 19 | .IP "\(bu" 4 20 | Simple to use 21 | . 22 | .IP "\(bu" 4 23 | Just export the tests from a module 24 | . 25 | .IP "\(bu" 4 26 | Helps you avoid common pitfalls when testing asynchronous code 27 | . 28 | .IP "\(bu" 4 29 | Easy to add test cases with setUp and tearDown functions if you wish 30 | . 31 | .IP "\(bu" 4 32 | Allows the use of mocks and stubs 33 | . 34 | .IP "" 0 35 | . 36 | .SH "OPTIONS" 37 | \fB\-\-config FILE\fR: 38 | . 39 | .br 40 | Load config options from a JSON file, allows the customisation 41 | of color schemes for the default test reporter etc\. 42 | See bin/nodeunit\.json for current available options\. 43 | . 44 | .P 45 | \fB\-\-reporter FILE\fR: 46 | . 47 | .br 48 | You can set the test reporter to a custom module or on of the modules 49 | in nodeunit/lib/reporters, when omitted, the default test runner is used\. 50 | . 51 | .P 52 | \fB\-\-list\-reporters\fR: 53 | . 54 | .br 55 | List available build\-in reporters\. 56 | . 57 | .P 58 | \fB\-h\fR, \fB\-\-help\fR: 59 | . 60 | .br 61 | Display the help and exit\. 62 | . 63 | .P 64 | \fB\-v\fR, \fB\-\-version\fR: 65 | . 66 | .br 67 | Output version information and exit\. 68 | . 69 | .P 70 | \fB\fR: 71 | You can run nodeunit on specific files or on all \fI*\.js\fR files inside 72 | . 73 | .br 74 | a directory\. 75 | . 76 | .SH "AUTHORS" 77 | Written by Caolan McMahon and other nodeunit contributors\. 78 | . 79 | .br 80 | Contributors list: \fIhttp://github\.com/caolan/nodeunit/contributors\fR\|\. 81 | . 82 | .SH "REPORTING BUGS" 83 | Report nodeunit bugs to \fIhttp://github\.com/caolan/nodeunit/issues\fR\|\. 84 | . 85 | .SH "COPYRIGHT" 86 | Copyright © 2010 Caolan McMahon\. 87 | . 88 | .br 89 | Nodeunit has been released under the MIT license: 90 | . 91 | .br 92 | \fIhttp://github\.com/caolan/nodeunit/raw/master/LICENSE\fR\|\. 93 | . 94 | .SH "SEE ALSO" 95 | node(1) 96 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-assert/AUTHORS: -------------------------------------------------------------------------------- 1 | Isaac Z. Schlueter (http://blog.izs.me) 2 | baudehlo 3 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-assert/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2009, 2010, 2011 Isaac Z. Schlueter. 2 | All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, 8 | copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-assert/README.md: -------------------------------------------------------------------------------- 1 | An assert module for node-tap. 2 | 3 | More coming. 4 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-assert/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tap-assert", 3 | "version": "0.0.10", 4 | "description": "An assertion module that returns TAP result objects", 5 | "main": "./assert.js", 6 | "author": "Isaac Z. Schlueter (http://blog.izs.me/)", 7 | "repository": { 8 | "type": "git", 9 | "url": "git://github.com/isaacs/tap-assert.git" 10 | }, 11 | "keywords": [ 12 | "assert", 13 | "test", 14 | "tap" 15 | ], 16 | "license": { 17 | "type": "MIT", 18 | "url": "https://github.com/isaacs/tap-assert/raw/master/LICENSE" 19 | }, 20 | "contributors": [ 21 | "Isaac Z. Schlueter (http://blog.izs.me)", 22 | "baudehlo " 23 | ], 24 | "dependencies": {}, 25 | "devDependencies": {}, 26 | "engines": { 27 | "node": "*" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/README.md: -------------------------------------------------------------------------------- 1 | Sometimes, you need to produce some TAPs. 2 | 3 | Not like when you go to the store, and check to see if the melons are 4 | ripe. That's tapping on produce. This is different. 5 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/inherits/README.md: -------------------------------------------------------------------------------- 1 | A dead simple way to do inheritance in JS. 2 | 3 | var inherits = require("inherits") 4 | 5 | function Animal () { 6 | this.alive = true 7 | } 8 | Animal.prototype.say = function (what) { 9 | console.log(what) 10 | } 11 | 12 | inherits(Dog, Animal) 13 | function Dog () { 14 | Dog.super.apply(this) 15 | } 16 | Dog.prototype.sniff = function () { 17 | this.say("sniff sniff") 18 | } 19 | Dog.prototype.bark = function () { 20 | this.say("woof woof") 21 | } 22 | 23 | inherits(Chihuahua, Dog) 24 | function Chihuahua () { 25 | Chihuahua.super.apply(this) 26 | } 27 | Chihuahua.prototype.bark = function () { 28 | this.say("yip yip") 29 | } 30 | 31 | // also works 32 | function Cat () { 33 | Cat.super.apply(this) 34 | } 35 | Cat.prototype.hiss = function () { 36 | this.say("CHSKKSS!!") 37 | } 38 | inherits(Cat, Animal, { 39 | meow: function () { this.say("miao miao") } 40 | }) 41 | Cat.prototype.purr = function () { 42 | this.say("purr purr") 43 | } 44 | 45 | 46 | var c = new Chihuahua 47 | assert(c instanceof Chihuahua) 48 | assert(c instanceof Dog) 49 | assert(c instanceof Animal) 50 | 51 | The actual function is laughably small. 10-lines small. 52 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/inherits/inherits.js: -------------------------------------------------------------------------------- 1 | module.exports = inherits 2 | 3 | function inherits (c, p, proto) { 4 | proto = proto || {} 5 | var e = {} 6 | ;[c.prototype, proto].forEach(function (s) { 7 | Object.getOwnPropertyNames(s).forEach(function (k) { 8 | e[k] = Object.getOwnPropertyDescriptor(s, k) 9 | }) 10 | }) 11 | c.prototype = Object.create(p.prototype, e) 12 | c.super = p 13 | } 14 | 15 | //function Child () { 16 | // Child.super.call(this) 17 | // console.error([this 18 | // ,this.constructor 19 | // ,this.constructor === Child 20 | // ,this.constructor.super === Parent 21 | // ,Object.getPrototypeOf(this) === Child.prototype 22 | // ,Object.getPrototypeOf(Object.getPrototypeOf(this)) 23 | // === Parent.prototype 24 | // ,this instanceof Child 25 | // ,this instanceof Parent]) 26 | //} 27 | //function Parent () {} 28 | //inherits(Child, Parent) 29 | //new Child 30 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/inherits/package.json: -------------------------------------------------------------------------------- 1 | { "name" : "inherits" 2 | , "description": "A tiny simple way to do classic inheritance in js" 3 | , "version" : "1.0.0" 4 | , "keywords" : ["inheritance", "class", "klass", "oop", "object-oriented"] 5 | , "main" : "./inherits.js" 6 | , "repository" : "https://github.com/isaacs/inherits" 7 | , "author" : "Isaac Z. Schlueter (http://blog.izs.me/)" } 8 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/tap-results/README.md: -------------------------------------------------------------------------------- 1 | This is a module for keeping track of tap result objects, counting them 2 | up, etc. 3 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/tap-results/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tap-results", 3 | "version": "0.0.2", 4 | "description": "A util for keeping track of tap result objects", 5 | "main": "./results.js", 6 | "author": "Isaac Z. Schlueter (http://blog.izs.me/)", 7 | "repository": "https://github.com/isaacs/tap-results", 8 | "dependencies": { 9 | "inherits": "~1.0.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/tap-results/results.js: -------------------------------------------------------------------------------- 1 | // A class for counting up results in a test harness. 2 | 3 | module.exports = Results 4 | 5 | var inherits = require("inherits") 6 | , EventEmitter = require("events").EventEmitter 7 | 8 | inherits(Results, EventEmitter) 9 | 10 | function Results (r) { 11 | //console.error("result constructor", r) 12 | this.ok = true 13 | this.addSet(r) 14 | } 15 | 16 | Results.prototype.addSet = function (r) { 17 | //console.error("add set of results", r) 18 | r = r || {ok: true} 19 | ; [ "todo" 20 | , "todoPass" 21 | , "todoFail" 22 | , "skip" 23 | , "skipPass" 24 | , "skipFail" 25 | , "pass" 26 | , "passTotal" 27 | , "fail" 28 | , "failTotal" 29 | , "tests" 30 | , "testsTotal" ].forEach(function (k) { 31 | this[k] = (this[k] || 0) + (r[k] || 0) 32 | //console.error([k, this[k]]) 33 | }, this) 34 | 35 | this.ok = this.ok && r.ok && true 36 | this.bailedOut = this.bailedOut || r.bailedOut || false 37 | this.list = (this.list || []).concat(r.list || []) 38 | this.emit("set", this.list) 39 | //console.error("after addSet", this) 40 | } 41 | 42 | Results.prototype.add = function (r, addToList) { 43 | //console.error("add result", r) 44 | var pf = r.ok ? "pass" : "fail" 45 | , PF = r.ok ? "Pass" : "Fail" 46 | 47 | this.testsTotal ++ 48 | this[pf + "Total"] ++ 49 | 50 | if (r.skip) { 51 | this["skip" + PF] ++ 52 | this.skip ++ 53 | } else if (r.todo) { 54 | this["todo" + PF] ++ 55 | this.todo ++ 56 | } else { 57 | this.tests ++ 58 | this[pf] ++ 59 | } 60 | 61 | if (r.bailout || typeof r.bailout === "string") this.bailedOut = true 62 | this.ok = !!(this.ok && r.ok) 63 | 64 | if (addToList === false) return 65 | this.list = this.list || [] 66 | this.list.push(r) 67 | this.emit("result", r) 68 | } 69 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/yamlish/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Isaac Z. Schlueter 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/yamlish/README.md: -------------------------------------------------------------------------------- 1 | This is a thingie to parse the "yamlish" format used to serialize 2 | objects in the TAP format. 3 | 4 | It's like yaml, but just a tiny little bit smaller. 5 | 6 | Usage: 7 | 8 | var yamlish = require("yamlish") 9 | // returns a string like: 10 | /* 11 | some: 12 | object: 13 | - full 14 | - of 15 | pretty: things 16 | */ 17 | yamlish.encode({some:{object:["full", "of"]}, pretty:"things"}) 18 | 19 | // returns the object 20 | yamlish.decode(someYamlishString) 21 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/node_modules/yamlish/package.json: -------------------------------------------------------------------------------- 1 | { "name" : "yamlish" 2 | , "description" : "Parser/encoder for the yamlish format" 3 | , "repository":"https://github.com/isaacs/yamlish" 4 | , "version" : "0.0.2" 5 | , "main" : "yamlish.js" 6 | , "keywords" : [ "yaml", "yamlish", "test", "anything", "protocol", "tap"] 7 | , "license" : { "type" : "MIT" 8 | , "url" : "http://github.com/isaacs/yamlish/raw/master/LICENSE" } 9 | , "author" : "Isaac Z. Schlueter (http://blog.izs.me/)" } 10 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/package.json: -------------------------------------------------------------------------------- 1 | { "name" : "tap-producer" 2 | , "version" : "0.0.1" 3 | , "description" : "A module for producing TAP output" 4 | , "main" : "./tap-producer.js" 5 | , "author" : "Isaac Z. Schlueter (http://blog.izs.me/)" 6 | , "repository" : "https://github.com/isaacs/tap-producer" 7 | , "dependencies" : 8 | { "inherits" : "*" 9 | , "tap-results" : "0.x" 10 | , "yamlish" : "*" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /node_modules/nodeunit/node_modules/tap-producer/tap-producer.js: -------------------------------------------------------------------------------- 1 | module.exports = TapProducer 2 | 3 | var Results = require("tap-results") 4 | , inherits = require("inherits") 5 | , yamlish = require("yamlish") 6 | 7 | TapProducer.encode = function (result, diag) { 8 | var tp = new TapProducer(diag) 9 | , out = "" 10 | tp.on("data", function (c) { out += c }) 11 | if (Array.isArray(result)) { 12 | result.forEach(tp.write, tp) 13 | } else tp.write(result) 14 | tp.end() 15 | return out 16 | } 17 | 18 | inherits(TapProducer, require("stream").Stream) 19 | function TapProducer (diag) { 20 | TapProducer.super.call(this) 21 | this.diag = diag 22 | this.count = 0 23 | this.readable = this.writable = true 24 | this.results = new Results 25 | } 26 | 27 | TapProducer.prototype.trailer = true 28 | 29 | TapProducer.prototype.write = function (res) { 30 | // console.error("TapProducer.write", res) 31 | if (typeof res === "function") throw new Error("wtf?") 32 | if (!this.writable) this.emit("error", new Error("not writable")) 33 | 34 | var diag = res.diag 35 | if (diag === undefined) diag = this.diag 36 | 37 | this.emit("data", encodeResult(res, this.count + 1, diag)) 38 | 39 | if (typeof res === "string") return true 40 | 41 | this.results.add(res, false) 42 | this.count ++ 43 | } 44 | 45 | TapProducer.prototype.end = function (res) { 46 | if (res) this.write(res) 47 | this.emit("data", "\n1.."+this.results.testsTotal+"\n") 48 | if (this.trailer && typeof this.trailer !== "string") { 49 | // summary trailer. 50 | var trailer = "tests "+this.results.testsTotal + "\n" 51 | if (this.results.pass) { 52 | trailer += "pass " + this.results.pass + "\n" 53 | } 54 | if (this.results.fail) { 55 | trailer += "fail " + this.results.fail + "\n" 56 | } 57 | if (this.results.skip) { 58 | trailer += "skip "+this.results.skip + "\n" 59 | } 60 | if (this.results.todo) { 61 | trailer += "todo "+this.results.todo + "\n" 62 | } 63 | if (this.results.bailedOut) { 64 | trailer += "bailed out" + "\n" 65 | } 66 | 67 | if (this.results.testsTotal === this.results.pass) { 68 | trailer += "\nok\n" 69 | } 70 | this.trailer = trailer 71 | } 72 | if (this.trailer) this.write(this.trailer) 73 | this.writable = false 74 | this.emit("end", null, this.count, this.ok) 75 | } 76 | 77 | function encodeResult (res, count, diag) { 78 | if (typeof res === "string") { 79 | res = res.split(/\r?\n/).map(function (l) { 80 | if (!l.trim()) return l.trim() 81 | return "# " + l 82 | }).join("\n") 83 | if (res.substr(-1) !== "\n") res += "\n" 84 | return res 85 | } 86 | 87 | if (!!process.env.TAP_NODIAG) diag = false 88 | else if (!!process.env.TAP_DIAG) diag = true 89 | else if (diag === undefined) diag = !res.ok 90 | 91 | var output = "" 92 | res.name = res.name && res.name.trim() 93 | output += ( !res.ok ? "not " : "") + "ok " + count 94 | + ( !res.name ? "" 95 | : " " + res.name.replace(/[\r\n]/, " ") ) 96 | + ( res.skip ? " # SKIP" 97 | : res.todo ? " # TODO" 98 | : "" ) 99 | + "\n" 100 | 101 | if (!diag) return output 102 | var d = {} 103 | , dc = 0 104 | Object.keys(res).filter(function (k) { 105 | return k !== "ok" && k !== "name" && k !== "id" 106 | }).forEach(function (k) { 107 | dc ++ 108 | d[k] = res[k] 109 | }) 110 | //console.error(d, "about to encode") 111 | if (dc > 0) output += " ---"+yamlish.encode(d)+"\n ...\n" 112 | return output 113 | } 114 | -------------------------------------------------------------------------------- /node_modules/nodeunit/nodelint.cfg: -------------------------------------------------------------------------------- 1 | //See: http://www.jslint.com/lint.html#options 2 | var options = { 3 | //white: false, // if false, strict whitespace rules should be enforced. 4 | indent: 4, 5 | onevar: false, 6 | vars: true // allow multiple var statement per function. 7 | }; 8 | -------------------------------------------------------------------------------- /node_modules/nodeunit/package.json: -------------------------------------------------------------------------------- 1 | { "name": "nodeunit" 2 | , "description": "Easy unit testing for node.js and the browser." 3 | , "maintainers": 4 | [ { "name": "Caolan McMahon" 5 | , "web": "https://github.com/caolan" 6 | } 7 | ] 8 | , "contributors" : 9 | [ { "name": "Romain Beauxis" 10 | , "web": "https://github.com/toots" 11 | } 12 | , { "name": "Alex Gorbatchev" 13 | , "web": "https://github.com/alexgorbatchev" 14 | } 15 | , { "name": "Alex Wolfe" 16 | , "web": "https://github.com/alexkwolfe" 17 | } 18 | , { "name": "Carl Fürstenberg" 19 | , "web": "https://github.com/azatoth" 20 | } 21 | , { "name": "Gerad Suyderhoud" 22 | , "web": "https://github.com/gerad" 23 | } 24 | , { "name": "Kadir Pekel" 25 | , "web": "https://github.com/coffeemate" 26 | } 27 | , { "name": "Oleg Efimov" 28 | , "web": "https://github.com/Sannis" 29 | } 30 | , { "name": "Orlando Vazquez" 31 | , "web": "https://github.com/orlandov" 32 | } 33 | , { "name": "Ryan Dahl" 34 | , "web": "https://github.com/ry" 35 | } 36 | , { "name": "Sam Stephenson" 37 | , "web": "https://github.com/sstephenson" 38 | } 39 | , { "name": "Thomas Mayfield" 40 | , "web": "https://github.com/thegreatape" 41 | } 42 | , { "name": "Elijah Insua ", 43 | "web": "http://tmpvar.com" 44 | } 45 | ] 46 | , "version": "0.6.4" 47 | , "repository" : 48 | { "type" : "git" 49 | , "url" : "http://github.com/caolan/nodeunit.git" 50 | } 51 | , "devDependencies": 52 | { "uglify-js": ">=1.1.0" } 53 | , "bugs" : { "url" : "http://github.com/caolan/nodeunit/issues" } 54 | , "licenses" : 55 | [ { "type" : "MIT" 56 | , "url" : "http://github.com/caolan/nodeunit/raw/master/LICENSE" 57 | } 58 | ] 59 | , "directories" : { "lib": "./lib", "doc" : "./doc", "man" : "./man1" } 60 | , "bin" : { "nodeunit" : "./bin/nodeunit" } 61 | , "dependencies" : 62 | { "tap-assert": ">=0.0.9" 63 | , "tap-producer": ">=0.0.1" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /node_modules/nodeunit/share/junit.xml.ejs: -------------------------------------------------------------------------------- 1 | 2 | <% for (var i=0; i < suites.length; i++) { %> 3 | <% var suite=suites[i]; %> 4 | 8 | <% for (var j=0; j < suite.testcases.length; j++) { %> 9 | <% var testcase=suites[i].testcases[j]; %> 10 | 11 | <% if (testcase.failure) { %> 12 | 13 | <% if (testcase.failure.backtrace) { %><%= testcase.failure.backtrace %><% } %> 14 | 15 | <% } %> 16 | 17 | <% } %> 18 | 19 | <% } %> 20 | -------------------------------------------------------------------------------- /node_modules/nodeunit/share/license.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Nodeunit 3 | * https://github.com/caolan/nodeunit 4 | * Copyright (c) 2010 Caolan McMahon 5 | * MIT Licensed 6 | * 7 | * json2.js 8 | * http://www.JSON.org/json2.js 9 | * Public Domain. 10 | * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. 11 | */ 12 | -------------------------------------------------------------------------------- /node_modules/nodeunit/share/nodeunit.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Styles taken from qunit.css 3 | */ 4 | 5 | h1#nodeunit-header, h1.nodeunit-header { 6 | padding: 15px; 7 | font-size: large; 8 | background-color: #06b; 9 | color: white; 10 | font-family: 'trebuchet ms', verdana, arial; 11 | margin: 0; 12 | } 13 | 14 | h1#nodeunit-header a { 15 | color: white; 16 | } 17 | 18 | h2#nodeunit-banner { 19 | height: 2em; 20 | border-bottom: 1px solid white; 21 | background-color: #eee; 22 | margin: 0; 23 | font-family: 'trebuchet ms', verdana, arial; 24 | } 25 | h2#nodeunit-banner.pass { 26 | background-color: green; 27 | } 28 | h2#nodeunit-banner.fail { 29 | background-color: red; 30 | } 31 | 32 | h2#nodeunit-userAgent, h2.nodeunit-userAgent { 33 | padding: 10px; 34 | background-color: #eee; 35 | color: black; 36 | margin: 0; 37 | font-size: small; 38 | font-weight: normal; 39 | font-family: 'trebuchet ms', verdana, arial; 40 | font-size: 10pt; 41 | } 42 | 43 | div#nodeunit-testrunner-toolbar { 44 | background: #eee; 45 | border-top: 1px solid black; 46 | padding: 10px; 47 | font-family: 'trebuchet ms', verdana, arial; 48 | margin: 0; 49 | font-size: 10pt; 50 | } 51 | 52 | ol#nodeunit-tests { 53 | font-family: 'trebuchet ms', verdana, arial; 54 | font-size: 10pt; 55 | } 56 | ol#nodeunit-tests li strong { 57 | cursor:pointer; 58 | } 59 | ol#nodeunit-tests .pass { 60 | color: green; 61 | } 62 | ol#nodeunit-tests .fail { 63 | color: red; 64 | } 65 | 66 | p#nodeunit-testresult { 67 | margin-left: 1em; 68 | font-size: 10pt; 69 | font-family: 'trebuchet ms', verdana, arial; 70 | } 71 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/coffee/mock_coffee_module.coffee: -------------------------------------------------------------------------------- 1 | j = 0 2 | j += i for i in [0..5] 3 | 4 | exports.name = "mock_coffee_#{j}" 5 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/dir/mock_module3.js: -------------------------------------------------------------------------------- 1 | exports.name = 'mock_module3'; 2 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/dir/mock_module4.js: -------------------------------------------------------------------------------- 1 | exports.name = 'mock_module4'; 2 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/mock_module1.js: -------------------------------------------------------------------------------- 1 | exports.name = 'mock_module1'; 2 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/mock_module2.js: -------------------------------------------------------------------------------- 1 | exports.name = 'mock_module2'; 2 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/raw_jscode1.js: -------------------------------------------------------------------------------- 1 | function hello_world(arg) { 2 | return "_" + arg + "_"; 3 | } 4 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/raw_jscode2.js: -------------------------------------------------------------------------------- 1 | function get_a_variable() { 2 | return typeof a_variable; 3 | } 4 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/fixtures/raw_jscode3.js: -------------------------------------------------------------------------------- 1 | var t=t?t+1:1; 2 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/test-httputil.js: -------------------------------------------------------------------------------- 1 | var nodeunit = require('../lib/nodeunit'); 2 | var httputil = require('../lib/utils').httputil; 3 | 4 | exports.testHttpUtilBasics = function (test) { 5 | 6 | test.expect(6); 7 | 8 | httputil(function (req, resp) { 9 | test.equal(req.method, 'PUT'); 10 | test.equal(req.url, '/newpair'); 11 | test.equal(req.headers.foo, 'bar'); 12 | 13 | resp.writeHead(500, {'content-type': 'text/plain'}); 14 | resp.end('failed'); 15 | }, function (server, client) { 16 | client.fetch('PUT', '/newpair', {'foo': 'bar'}, function (resp) { 17 | test.equal(resp.statusCode, 500); 18 | test.equal(resp.headers['content-type'], 'text/plain'); 19 | test.equal(resp.body, 'failed'); 20 | 21 | server.close(); 22 | test.done(); 23 | }); 24 | }); 25 | }; 26 | 27 | exports.testHttpUtilJsonHandling = function (test) { 28 | 29 | test.expect(9); 30 | 31 | httputil(function (req, resp) { 32 | test.equal(req.method, 'GET'); 33 | test.equal(req.url, '/'); 34 | test.equal(req.headers.foo, 'bar'); 35 | 36 | var testdata = {foo1: 'bar', foo2: 'baz'}; 37 | 38 | resp.writeHead(200, {'content-type': 'application/json'}); 39 | resp.end(JSON.stringify(testdata)); 40 | 41 | }, function (server, client) { 42 | client.fetch('GET', '/', {'foo': 'bar'}, function (resp) { 43 | test.equal(resp.statusCode, 200); 44 | test.equal(resp.headers['content-type'], 'application/json'); 45 | 46 | test.ok(resp.bodyAsObject); 47 | test.equal(typeof resp.bodyAsObject, 'object'); 48 | test.equal(resp.bodyAsObject.foo1, 'bar'); 49 | test.equal(resp.bodyAsObject.foo2, 'baz'); 50 | 51 | server.close(); 52 | test.done(); 53 | }); 54 | }); 55 | }; 56 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/test-runtest.js: -------------------------------------------------------------------------------- 1 | /* THIS FILE SHOULD BE BROWSER-COMPATIBLE JS! 2 | * You can use @REMOVE_LINE_FOR_BROWSER to remove code from the browser build. 3 | * Only code on that line will be removed, its mostly to avoid requiring code 4 | * that is node specific 5 | */ 6 | 7 | var nodeunit = require('../lib/nodeunit'); // @REMOVE_LINE_FOR_BROWSER 8 | 9 | 10 | exports.testArgs = function (test) { 11 | test.ok(test.expect instanceof Function, 'test.expect'); 12 | test.ok(test.done instanceof Function, 'test.done'); 13 | test.ok(test.ok instanceof Function, 'test.ok'); 14 | test.ok(test.same instanceof Function, 'test.same'); 15 | test.ok(test.equals instanceof Function, 'test.equals'); 16 | test.done(); 17 | }; 18 | 19 | exports.testDoneCallback = function (test) { 20 | test.expect(4); 21 | nodeunit.runTest('testname', exports.testArgs, { 22 | testDone: function (name, assertions) { 23 | test.equals(assertions.failures(), 0, 'failures'); 24 | test.equals(assertions.length, 5, 'length'); 25 | test.ok(typeof assertions.duration === "number"); 26 | test.equals(name, 'testname'); 27 | } 28 | }, test.done); 29 | }; 30 | 31 | exports.testThrowError = function (test) { 32 | test.expect(3); 33 | var err = new Error('test'); 34 | var testfn = function (test) { 35 | throw err; 36 | }; 37 | nodeunit.runTest('testname', testfn, { 38 | log: function (assertion) { 39 | test.same(assertion.error, err, 'assertion.error'); 40 | }, 41 | testDone: function (name, assertions) { 42 | test.equals(assertions.failures(), 1); 43 | test.equals(assertions.length, 1); 44 | } 45 | }, test.done); 46 | }; 47 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/test-sandbox.js: -------------------------------------------------------------------------------- 1 | var nodeunit = require('../lib/nodeunit'); 2 | var sandbox = require('../lib/utils').sandbox; 3 | var testCase = nodeunit.testCase; 4 | 5 | exports.testSimpleSandbox = function (test) { 6 | var raw_jscode1 = sandbox(__dirname + '/fixtures/raw_jscode1.js'); 7 | test.equal(raw_jscode1.hello_world('foo'), '_foo_', 'evaluation ok'); 8 | test.done(); 9 | }; 10 | 11 | exports.testSandboxContext = function (test) { 12 | var a_variable = 42; // should not be visible in the sandbox 13 | var raw_jscode2 = sandbox(__dirname + '/fixtures/raw_jscode2.js'); 14 | a_variable = 42; // again for the win 15 | test.equal( 16 | raw_jscode2.get_a_variable(), 17 | 'undefined', 18 | 'the variable should not be defined' 19 | ); 20 | test.done(); 21 | }; 22 | 23 | exports.testSandboxMultiple = function (test) { 24 | var raw_jscode3 = sandbox([ 25 | __dirname + '/fixtures/raw_jscode3.js', 26 | __dirname + '/fixtures/raw_jscode3.js', 27 | __dirname + '/fixtures/raw_jscode3.js' 28 | ]); 29 | test.equal(raw_jscode3.t, 3, 'two files loaded'); 30 | test.done(); 31 | }; 32 | -------------------------------------------------------------------------------- /node_modules/nodeunit/test/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Nodeunit Test Suite 4 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |

Nodeunit Test Suite

18 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /resources/test/sources/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "test_service_a":{ 3 | "config":"select id as num from service_a.table where ##fm## order by num DESC limit 1,2", 4 | "params":{ 5 | "fm":[{ 6 | "type":"string", 7 | "pos":"##fm##" 8 | }] 9 | } 10 | }, 11 | "test_as_order":{ 12 | "config":"select id as num from service_a.table where ##fm## order by id DESC", 13 | "params":{ 14 | "fm":[{ 15 | "type":"string", 16 | "pos":"##fm##" 17 | }] 18 | } 19 | }, 20 | "test_service_b":{ 21 | "config":"select name from service_b.table where ##minId## order by name DESC", 22 | "params":{ 23 | "minId":[{ 24 | "type":"string", 25 | "pos":"##minId##" 26 | }] 27 | } 28 | }, 29 | "test_innerjoin" : { 30 | "config" : "select * from service_a.table as sa inner join service_b.table as sb on sa.id=sb.id where ##fm## and ##minId##", 31 | "params" : { 32 | "fm" : [{ 33 | "type" : "string", 34 | "pos" : "##fm##", 35 | "replace" : "sa._params.fm" 36 | }], 37 | "minId" : [{ 38 | "type" : "int", 39 | "pos" : "##minId##", 40 | "replace" : "sb._params..minId" 41 | }] 42 | } 43 | }, 44 | "test_leftjoin" : { 45 | "config" : "select sa.id ,sa.sex ,sb.name ,sb.type from service_a.table as sa left join service_b.table as sb on sa.id=sb.id where ##fm## and ##minId##", 46 | "params" : { 47 | "fm" : [{ 48 | "type" : "string", 49 | "pos" : "##fm##", 50 | "replace" : "sa._params.fm" 51 | }], 52 | "minId" : [{ 53 | "type" : "int", 54 | "pos" : "##minId##", 55 | "replace" : "sb._params.minId" 56 | }] 57 | } 58 | }, 59 | "test_union" : { 60 | "config" : "select sa.id as id,sa.sex as type from service_a.table as sa where ##fm## union SELECT sb.id as id,sb.type as type from service_b.table as sb where ##minId##", 61 | "params" : { 62 | "fm" : [{ 63 | "type" : "string", 64 | "pos" : "##fm##", 65 | "replace" : "sa.fm" 66 | }], 67 | "minId" : [{ 68 | "type" : "int", 69 | "pos" : "##minId##", 70 | "replace" : "sb.minId" 71 | }] 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | node core/tcpMaster.js & 2 | -------------------------------------------------------------------------------- /sample/service.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var url = require('url'); 3 | 4 | //convert data to format like below 5 | //{ 6 | // columns : ['id', 'name' ,'type'], 7 | // data : [ 8 | // [1, 'n1', 't1'], 9 | // [2, 'n2', 't2'], 10 | // [3, 'n3', 't3'], 11 | // ... 12 | // ] 13 | //} 14 | function dataFormat(rows){ 15 | var res = { 16 | columns : [], 17 | data : [] 18 | }; 19 | 20 | //rows meust be an array 21 | var fnode = rows[0]; 22 | 23 | if(fnode){ 24 | var key; 25 | for(key in fnode){ 26 | res.columns.push(key); 27 | } 28 | var ele; 29 | var data = res.data; 30 | var len = rows.length,i=0; 31 | while( i < len){ 32 | fnode = rows[i]; 33 | ele = []; 34 | for(key in fnode){ 35 | ele.push(fnode[key]); 36 | } 37 | data.push(ele); 38 | i++; 39 | } 40 | } 41 | return res; 42 | } 43 | 44 | /* 45 | **create a service for query all 'male' or 'female' 46 | **@input : http://host:port/?fm=[m|f] 47 | **@output : formated JSON data 48 | */ 49 | http.createServer(function(req, res){ 50 | var data = [ 51 | {'id' : 1, 'sex' : 'm'}, 52 | {'id' : 2, 'sex' : 'm'}, 53 | {'id' : 3, 'sex' : 'f'}, 54 | {'id' : 4, 'sex' : 'f'}, 55 | {'id' : 5, 'sex' : 'm'}, 56 | {'id' : 6, 'sex' : 'f'}, 57 | {'id' : 7, 'sex' : 'm'}, 58 | {'id' : 8, 'sex' : 'f'}, 59 | {'id' : 9, 'sex' : 'm'}, 60 | {'id' : 10, 'sex' : 'f'} 61 | ]; 62 | var params = url.parse(req.url, true).query; 63 | 64 | var fm = params['fm']; 65 | var arr = []; 66 | for(var i = 0; i < data.length; i++){ 67 | if(data[i].sex == fm) 68 | arr.push(data[i]); 69 | } 70 | 71 | var str = JSON.stringify(dataFormat(arr)); 72 | res.writeHead(200, { 73 | 'Content-type' : 'application/json', 74 | 'Content-length' : str.length 75 | }); 76 | 77 | res.end(str); 78 | 79 | }).listen(3561) 80 | 81 | /* 82 | **create a service for query items greater than some 'id' 83 | **@input : http://host:port/?minId=[id] 84 | **@output : formated JSON data 85 | */ 86 | http.createServer(function(req, res){ 87 | var data = [ 88 | {'id' : 1, 'name' : 'n1', 'type' : 't1'}, 89 | {'id' : 2, 'name' : 'n2', 'type' : 't2'}, 90 | {'id' : 3, 'name' : 'n3', 'type' : 't3'}, 91 | {'id' : 4, 'name' : 'n4', 'type' : 't4'}, 92 | {'id' : 5, 'name' : 'n5', 'type' : 't5'}, 93 | {'id' : 6, 'name' : 'n6', 'type' : 't6'}, 94 | {'id' : 7, 'name' : 'n7', 'type' : 't7'}, 95 | {'id' : 8, 'name' : 'n8', 'type' : 't8'}, 96 | {'id' : 9, 'name' : 'n9', 'type' : 't9'}, 97 | {'id' : 10, 'name' : 'n10', 'type' : 't10'} 98 | ]; 99 | var params = url.parse(req.url, true).query; 100 | 101 | var minId = parseInt(params['minId']); 102 | var arr = []; 103 | for(var i = minId; i < data.length; i++){ 104 | arr.push(data[i]); 105 | } 106 | 107 | var str = JSON.stringify(dataFormat(arr)); 108 | res.writeHead(200, { 109 | 'Content-type' : 'application/json', 110 | 'Content-length' : str.length 111 | }); 112 | 113 | res.end(str); 114 | 115 | }).listen(3562) 116 | -------------------------------------------------------------------------------- /src/data/prototype.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :sanxing 7 | 8 | var prototype=function(){ 9 | // 10 | } 11 | 12 | //初始化 13 | prototype.prototype.init=function(){ 14 | // 15 | } 16 | 17 | //处理数据 18 | prototype.prototype.load=function(){ 19 | // 20 | console.log('load'); 21 | } 22 | 23 | exports.init=function(){ 24 | return new prototype(); 25 | } 26 | -------------------------------------------------------------------------------- /src/data/tmpSql.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :sanxing 7 | 8 | var tmpSql=function(config){ 9 | this.config=config; 10 | } 11 | 12 | //拆分sql 13 | tmpSql.prototype.load=function(){ 14 | 15 | } 16 | 17 | exports.init=function(config){ 18 | return new tmpSql(config); 19 | } 20 | -------------------------------------------------------------------------------- /src/data/union.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :sanxing 7 | 8 | var pro=require('./prototype.js').init(); 9 | 10 | var union=function(data){ 11 | this.data=data; 12 | } 13 | 14 | union.prototype=pro; 15 | 16 | // 17 | union.prototype.load=function(){ 18 | 19 | if(typeof this.data!='object' || typeof this.data.length=='undefined'){ 20 | console.log('数据格式错误'); 21 | return; 22 | } 23 | 24 | var _=this.data,tmp=[]; 25 | 26 | var columns=_[0].columns; 27 | 28 | while(_.length){ 29 | var t=_.shift(); 30 | 31 | if(t.data.length){ 32 | tmp=tmp.concat(t.data); 33 | } 34 | } 35 | 36 | return { 37 | 'columns':columns, 38 | 'data':tmp 39 | }; 40 | } 41 | 42 | 43 | exports.init=function(data){ 44 | 45 | return new union(data); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/dispatch.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :sanxing ,fengyin 7 | 8 | var conf = require('../conf'); 9 | var SqlCache = require('./sqlcache'); 10 | var data = require('./data'); 11 | 12 | var Dispatch = function(req, res){ 13 | this.req = req; 14 | this.res = res; 15 | this.req.url = decodeURIComponent(this.req.url); 16 | } 17 | 18 | Dispatch.prototype.load = function(){ 19 | var self = this; 20 | var url = this.req.url; 21 | //console.log('dispatch ' + url); 22 | log.access(this.req.url); 23 | var sqlInfo; 24 | try{ 25 | sqlInfo = SqlCache.get(this.req.url); 26 | }catch(e){ 27 | log.error("config not found:" + this.req.url) 28 | global.replyError(self.req, self.res, 404); 29 | return 30 | } 31 | 32 | var dObj = data.init('data', sqlInfo, url, function(ret){ 33 | if(ret.error){ 34 | //log.error(ret.error); 35 | global.replyError(self.req, self.res, 500, ret.error); 36 | }else{ 37 | var res = self.res; 38 | res.writeHead(200, { 39 | 'content-type' : 'application/json' 40 | }); 41 | 42 | res.end(JSON.stringify(ret.data)); 43 | } 44 | }); 45 | 46 | dObj.load(); 47 | } 48 | 49 | exports.fn = function(req, res){ 50 | return new Dispatch(req, res); 51 | } 52 | -------------------------------------------------------------------------------- /src/dispatch.js.bake: -------------------------------------------------------------------------------- 1 | // +------------------------------------------------------------------------+ 2 | // | itier请求处理类 | 3 | // +------------------------------------------------------------------------+ 4 | // | Copygight (c) 2003 - 2012 Taobao.com. All Rights Reserved | 5 | // +------------------------------------------------------------------------+ 6 | // | Author: sanxing | 7 | // +------------------------------------------------------------------------+ 8 | // | 2011年10月21日 | 9 | // +------------------------------------------------------------------------+ 10 | 11 | var conf=require('../conf'); 12 | 13 | //安全机制,防止被攻击 14 | var maxParamsCount=100; 15 | 16 | var dispatch=function(req,res){ 17 | this.req=req; 18 | this.res=res; 19 | this.req.url=decodeURIComponent(this.req.url); 20 | } 21 | 22 | //处理 23 | dispatch.prototype.load=function(){ 24 | 25 | var _=this.req; 26 | var firstCode=_.url.substr(0,1); 27 | var u=''; 28 | 29 | if(firstCode=='/'){ 30 | var u=_.url.substr(1); 31 | } 32 | else{ 33 | u=_.url; 34 | } 35 | 36 | var url=u.split('/',maxParamsCount); 37 | var controller=url[0].toLowerCase(); 38 | 39 | if(controller=='status.html'){ 40 | controller='status'; 41 | } 42 | 43 | //去掉controller, 组合新url 44 | url.shift(); 45 | 46 | var Urlnew=url.join('/'); 47 | this.req.url=Urlnew; 48 | 49 | try{ 50 | var obj=require('./controller/' + controller + '.js'); 51 | var _obj=obj.init(this.req,this.res); 52 | _obj.load(); 53 | }catch(e){ 54 | log.excp(e.stack); 55 | this.tryCatch(e,'系统错误',400); 56 | } 57 | } 58 | 59 | dispatch.prototype.tryCatch=function(e,m,c){ 60 | 61 | var format=this.getFormat(); 62 | 63 | var sep=String.fromCharCode(1); 64 | 65 | var string=''; 66 | 67 | if(typeof m=='undefined' || m==''){ 68 | m='系统错误'; 69 | } 70 | 71 | if(typeof c=='undefined' || c==''){ 72 | c=400; 73 | } 74 | 75 | switch(format){ 76 | case 'plain': 77 | var s=[conf.version,c,m,0,0,0]; 78 | string=s.join(sep); 79 | break; 80 | case 'json': 81 | string='{"v":"' + conf.version + '","c":' + c + ',"m":"' + m + '","t":0,"n":0,"fn":0}'; 82 | break; 83 | default: 84 | var s=[conf.version,c,m,0,0,0]; 85 | string=s.join(sep); 86 | break; 87 | } 88 | 89 | log.error( '[m]: ' + e.message + ' [remoteAddress]: ' + this.req.connection.remoteAddress + ' [request url]: ' + this.req.url); 90 | 91 | this.res.end(string); 92 | return; 93 | } 94 | 95 | //获取客户端请求数据的格式 96 | dispatch.prototype.getFormat=function(){ 97 | 98 | var _=this.req.headers; 99 | 100 | if(typeof _['x_itier_format']=='undefined' && conf.run_mode=='test'){ 101 | return 'plain'; 102 | } 103 | else if( typeof _['x_itier_format']=='undefined' ){ 104 | return ''; 105 | } 106 | 107 | return _['x_itier_format']; 108 | } 109 | 110 | exports.fn=function(req,res){ 111 | return new dispatch(req,res); 112 | } 113 | -------------------------------------------------------------------------------- /src/hotcfg.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | var Cfg = require("../core/cfgload").ctor; 9 | var fs = require("fs"); 10 | 11 | function inspect(obj){ 12 | console.log(require("util").inspect(obj)); 13 | } 14 | /* 15 | var log = { 16 | error : function(str){ 17 | console.log(str); 18 | } 19 | } 20 | */ 21 | exports.Cfg2 = Cfg2; 22 | 23 | function Cfg2(fpath, jobId){ 24 | this.map = {}; 25 | 26 | var self = this; 27 | fs.readdir(fpath, function(err ,dnames){ 28 | if(err){ 29 | log.error("error read directory :" + fpath); 30 | }else{ 31 | dnames.forEach(function(dname){ 32 | if(dname[0] != "."){ 33 | self.map[dname] = new Cfg(fpath + "/" + dname, jobId); 34 | } 35 | }) 36 | } 37 | }); 38 | } 39 | 40 | Cfg2.prototype.get = function(r_path){ 41 | var pa = r_path.split('/'); 42 | //inspect(pa); 43 | var dcfg = this.map[pa[0]]; 44 | //inspect(dcfg); 45 | return dcfg.get(pa[1]); 46 | } 47 | 48 | exports.Cfg3 = Cfg3; 49 | 50 | function Cfg3(fpath, jobId){ 51 | jobId = jobId || "ActionLoader"; 52 | 53 | this.map = {}; 54 | 55 | var self = this; 56 | //console.log(fpath); 57 | fs.readdir(fpath, function(err ,dnames){ 58 | if(err){ 59 | log.error("error read directory :" + fpath); 60 | }else{ 61 | dnames.forEach(function(dname){ 62 | if(dname[0] != "."){ 63 | self.map[dname] = new Cfg2(fpath + "/" + dname, jobId); 64 | } 65 | }) 66 | } 67 | }); 68 | } 69 | 70 | Cfg3.prototype.get = function(r_path){ 71 | var pa = r_path.split('/'); 72 | //inspect(pa); 73 | var dcfg = this.map[pa[0]]; 74 | pa.shift(); 75 | //inspect(dcfg); 76 | return dcfg.get(pa.join('/')); 77 | } 78 | -------------------------------------------------------------------------------- /src/parse/url.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :yixuan 7 | 8 | 9 | var operators = { 10 | eq : "=", 11 | le : "<=", 12 | lt : "<", 13 | ge : ">=", 14 | gt : ">", 15 | ne : "<>", 16 | } 17 | 18 | var UrlParser = function(url){ 19 | url = url.trim(); 20 | this.url = url; 21 | } 22 | 23 | UrlParser.prototype.parse = function(){ 24 | var tokens = this.url.split("/"); 25 | var result = {}; 26 | result.app = tokens[1]; 27 | result.modules = tokens[2]+"/"+tokens[3]; 28 | result.action = tokens[4]; 29 | result.where = {}; 30 | result.limit = []; 31 | var i = 5; 32 | while(i < tokens.length){ 33 | if(tokens[i] == "where"){ 34 | var toks = tokens[++i].split(":"); 35 | if(operators[toks[1]] === undefined){ 36 | throw new Error("wrong operator"); 37 | } 38 | result.where[toks[0]+operators[toks[1]]] = toks[2]; 39 | }else if(tokens[i] == "limit"){ 40 | var toks = tokens[++i].split(","); 41 | result.limit.push(toks[0]); 42 | if(toks[1] !== undefined){result.limit.push(toks[1]);} 43 | } 44 | i++; 45 | } 46 | return result; 47 | } 48 | 49 | exports.create = function(url){ 50 | return new UrlParser(url); 51 | } 52 | -------------------------------------------------------------------------------- /src/plugin.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :sanxing 7 | 8 | var plugins=function(){ 9 | // 10 | } 11 | 12 | plugins.prototype.load=function(){ 13 | console.log('process data function,you should prototype it.....'); 14 | } 15 | 16 | exports.init=function(){ 17 | return new plugins(); 18 | } 19 | -------------------------------------------------------------------------------- /src/plugin/sumPlugin.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :sanxing 7 | 8 | var p=require('../plugin.js').init(); 9 | 10 | var sumPlugin = function(data,config){ 11 | this.data = data; 12 | this.config = config; 13 | } 14 | 15 | sumPlugin.prototype=p; 16 | 17 | //根据group by 字段计算求和 18 | sumPlugin.prototype.load = function(){ 19 | 20 | //没有设置求和字段返回原数据 21 | if(typeof this.config.fields=='undefined' || this.config.fields.length==0){ 22 | return this.data; 23 | } 24 | 25 | var _=this; 26 | 27 | if(typeof this.config.groupby!='undefined' && this.config.groupby.length){ 28 | 29 | // 30 | var result={},res=[]; 31 | 32 | this.data.forEach(function(i){ 33 | var key=[],k=''; 34 | _.config.groupby.forEach(function(g){ 35 | key.push(g + '-' + i[g]); 36 | }) 37 | 38 | k=key.join('='); 39 | 40 | if(k){ 41 | if(typeof result[k]=='undefined'){ 42 | res.push(i); 43 | result[k]=res.length-1; 44 | } 45 | else{ 46 | _.config.fields.forEach(function(f){ 47 | res[result[k]][f]+=i[f]; 48 | }) 49 | } 50 | } 51 | }); 52 | 53 | delete result; 54 | 55 | return res; 56 | } 57 | else{ 58 | var result={}; 59 | this.data.forEach(function(i){ 60 | _.config.fields.forEach(function(j){ 61 | if(typeof result[j]=='undefined'){ 62 | result[j]=0; 63 | } 64 | result[j]+=i[j]; 65 | }) 66 | }) 67 | 68 | return [result]; 69 | } 70 | } 71 | 72 | 73 | exports.init = function(data,config){ 74 | return new sumPlugin(data,config); 75 | } 76 | -------------------------------------------------------------------------------- /src/source/service_a.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | //A simiple sample for a loader driver 8 | 9 | var LoaderBase = require('./_loader_base').ctor; 10 | 11 | var config = { 12 | host : 'localhost', 13 | port : 3561, 14 | maxSockets : 20, 15 | pathTemplate : "/?fm={fm}" 16 | } 17 | 18 | var loader = new LoaderBase('serviceA', config); 19 | 20 | //type[debug] now is not supported 21 | exports.load = function(type, sqlObj, cb){ 22 | loader.load(type, sqlObj, cb); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /src/source/service_b.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | var LoaderBase = require('./_loader_base').ctor; 9 | 10 | var config = { 11 | host : 'localhost', 12 | port : 3562, 13 | maxSockets : 20, 14 | pathTemplate : "/?minId={minId}" 15 | } 16 | 17 | var loader = new LoaderBase('serviceB', config); 18 | 19 | //type[debug] now is not supported 20 | exports.load = function(type, sqlObj, cb){ 21 | return loader.load(type, sqlObj, cb); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/source/sql.js: -------------------------------------------------------------------------------- 1 | // (C) 2011-2012 Alibaba Group Holding Limited. 2 | // This program is free software; you can redistribute it and/or 3 | // modify it under the terms of the GNU General Public License 4 | // version 2 as published by the Free Software Foundation. 5 | 6 | // Authors :fengyin 7 | 8 | exports.ctor = Sql; 9 | 10 | function debug(str){ 11 | //console.log(str); 12 | } 13 | 14 | function inspect(obj){ 15 | //console.log(require("util").inspect(obj)); 16 | } 17 | 18 | function Sql(sqlObj){ 19 | this._sqlObj = sqlObj; 20 | } 21 | 22 | Sql.prototype.getAsNames = function(){ 23 | var cols = this._sqlObj.columns; 24 | var arr = []; 25 | for(var i in cols){ 26 | arr.push(i); 27 | } 28 | return arr; 29 | } 30 | 31 | Sql.prototype.getColNames = function(){ 32 | var cols = this._sqlObj.columns; 33 | var colNames = []; 34 | for(var i in cols){ 35 | var robj = cols[i]; 36 | var expr = robj.expr; 37 | var cn = ''; 38 | expr.forEach(function(ele){ 39 | cn += ele.text; 40 | }); 41 | if(cn.lastIndexOf('.') > 0){ 42 | cn = cn.substr(cn.lastIndexOf('.') + 1); 43 | } 44 | colNames.push(cn); 45 | }; 46 | return colNames; 47 | } 48 | 49 | Sql.prototype.getWheres = function(){ 50 | var ws = this._sqlObj.where; 51 | var obj = {}; 52 | for(var i = 0; i< ws.length; i++){ 53 | var key = ws[i].column.text; 54 | if(key.lastIndexOf('.') > 0){ 55 | key = key.substr(key.lastIndexOf('.') + 1) 56 | } 57 | var vals = ws[i].values; 58 | var arr = []; 59 | vals.forEach(function(v){ 60 | arr.push(v.text); 61 | }) 62 | obj[key] = arr.join(''); 63 | } 64 | 65 | debug('wheres :'); 66 | inspect(obj); 67 | return obj; 68 | } 69 | 70 | Sql.prototype.getOrderBy = function(){ 71 | var obArr = this._sqlObj.orderby; 72 | var res = []; 73 | var asNames = this.getAsNames(); 74 | var colNames = this.getColNames(); 75 | for(var i = 0; i < obArr.length; i++){ 76 | var ele = obArr[i]; 77 | var ob = { 78 | type : 'ASC', 79 | name : '' 80 | }; 81 | if(ele.type == 2) ob.type = 'DESC'; 82 | 83 | var obExpr = ele.expr; 84 | var oname = ""; 85 | for(var j = 0; j < obExpr.length; j++){ 86 | oname += obExpr[j].text; 87 | } 88 | var index = -1; 89 | //sort by asname 90 | if(asNames.indexOf(oname) >= 0){ 91 | ob.name = oname; 92 | res.push(ob); 93 | //sort by original colname 94 | }else if((index = colNames.indexOf(oname)) >= 0){ 95 | //console.log('index : ' + index); 96 | ob.name = asNames[index]; 97 | res.push(ob); 98 | } 99 | } 100 | return res; 101 | } 102 | 103 | Sql.prototype.getLimits = function(){ 104 | var lArr = this._sqlObj.limits; 105 | var res = []; 106 | for(var i = 0; i < lArr.length; i++){ 107 | res.push(lArr[i].text); 108 | } 109 | return res; 110 | } 111 | 112 | //not supported now 113 | Sql.prototype.getPlugins = function(){ 114 | return {}; 115 | } 116 | -------------------------------------------------------------------------------- /test/benchmark/ajoin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author : windyrobin@Gmail.com(Edward Zhang) 3 | * @date: 12/31/2011 4 | * 5 | */ 6 | 7 | var on = { 8 | left : ["id", "pid"], 9 | right: ["id", "tid"] 10 | //left : ["id"], 11 | //right: ["id"] 12 | }; 13 | 14 | var ta = { 15 | columns : ["id", "pid", "first"], 16 | data :[] 17 | }; 18 | 19 | var tb = { 20 | columns : ["id", "tid", "last"], 21 | data :[] 22 | }; 23 | 24 | function dataInit(){ 25 | for(var i=0; i< 2000; i++){ 26 | var a = []; 27 | var b = []; 28 | 29 | //var rid = parseInt(Math.random() * 5000); 30 | a.push(i); 31 | rid = parseInt(Math.random() * 10); 32 | a.push(rid); 33 | a.push("hello"); 34 | 35 | b.push(i); 36 | rid = parseInt(Math.random() * 10); 37 | b.push(rid); 38 | b.push("world"); 39 | 40 | ta.data.push(a); 41 | tb.data.push(b); 42 | } 43 | } 44 | 45 | function leftJoin(ta ,tb, on){ 46 | var ka = on.left; 47 | var kb = on.right; 48 | 49 | var klen = kb.length; 50 | var i, j, k; 51 | 52 | //hash b like that: 53 | // kb1 : [ele1, ele2] 54 | // kb2 : [el3, ele5]; 55 | var adata = ta.data; 56 | var bdata = tb.data; 57 | var tblen = bdata.length; 58 | var talen = adata.length; 59 | 60 | var ele; 61 | var aele; 62 | var bele; 63 | var key; 64 | var hba; 65 | 66 | var apos = []; 67 | var acols = ta.columns; 68 | for(i=0; i | 7 | // +------------------------------------------------------------------------+ 8 | // | 2011年10月 | 9 | // +------------------------------------------------------------------------+ 10 | 11 | var Cases = require('nodeunit').testCase; 12 | var UrlParser = require("../../src/parse/url.js"); 13 | 14 | module.exports = Cases({ 15 | setUp: function(callback) { 16 | callback(); 17 | }, 18 | tearDown: function(callback) { 19 | callback(); 20 | }, 21 | 22 | /*{{{ test_should_condition_right_work_fine()*/ 23 | test_should_parse_condition_right_work_fine : function(test){ 24 | var urlParser = UrlParser.create("/db/keywords/fact_query_effect_d/get_title_brief/where/f0:eq:2011-10-16/where/r1:ge:2011-10-10/where/r1:le:2011-10-16/where/keytype:eq:title/where/query:eq:QUERY/where/aid:eq:4458633437/where/utype:eq:0/where/nick:eq:cubetest04/where/uid:eq:233205/limit/3,5"); 25 | var eql = { 26 | app: "db", 27 | modules: "keywords/fact_query_effect_d", 28 | action: "get_title_brief", 29 | where: { 30 | "f0=":"2011-10-16", 31 | "r1>=":"2011-10-10", 32 | "r1<=":"2011-10-16", 33 | "keytype=":"title", 34 | "query=":"QUERY", 35 | "aid=":"4458633437", 36 | "utype=":"0", 37 | "nick=":"cubetest04", 38 | "uid=":"233205" 39 | }, 40 | limit:[3,5] 41 | }; 42 | test.deepEqual(eql,urlParser.parse()); 43 | test.done(); 44 | }, 45 | /*}}}*/ 46 | 47 | /*{{{ test_should_catch_exception_work_fine()*/ 48 | test_should_catch_exception_work_fine : function(test){ 49 | var urlParser = UrlParser.create("/db/keywords/fact_query_effect_d/get_title_brief/where/f0:qq:2011-10-16/where/r1:ge:2011-10-10"); 50 | try{ 51 | urlParser.parse(); 52 | test.ok(false,"url wrong"); 53 | }catch(e){ 54 | if(e.message == "wrong operator"){ 55 | test.ok(true,"every thing is ok"); 56 | }else{ 57 | test.ok(false,"exception"); 58 | } 59 | } 60 | test.done(); 61 | }, 62 | /*}}}*/ 63 | 64 | }); 65 | --------------------------------------------------------------------------------