qunit-tapを使ってnode.jsのテストをproveで行う - すぎゃーんメモ ã®ç¶ãã§ãã
qunit-tapã¯1.0.0ãreleaseããã¾ããã
https://github.com/twada/qunit-tap/commit/5da16418b6de71e4be186d080a0622e5689e8878
ã§ã@t_wadaãããã追å æ å ±ãããã ãã¾ããã
Node 㧠qunit-tap ãåããéã«ãã¡ãã£ã¨ã ãæéãããããã¹ãããã¡ãã¨éãããã«ã¯ QUnit.init(); ã®å¾ã« QUnit.config.updateRate = 0; ãå¿ è¦ããã§ããæ°ã¥ãã®ãé ãã¦ãã¿ã¾ãããã¨ã³ããªãä¿®æ£ãã¦ããã ããã¨å¬ããã§ã
2011-03-28 19:59:24 via web
exports = module.exports = global; var path = require('path'); QUnit = require(path.join(path.dirname(require.resolve('qunit-tap')), '..', 'vendor', 'qunit', 'qunit', 'qunit')).QUnit; require("qunit-tap").qunitTap(QUnit, require("sys").puts, { noPlan: true }); QUnit.init(); exports.assert = QUnit;
ã¨helper scriptãç¨æãã¦ããå ´åã
require('../test_helper.js'); QUnit.test('hoge', function() { assert.ok(true); }); QUnit.start();
ã®ãããªåç´ãªãã¹ãã¯åé¡ãªãã§ãã
require('../test_helper.js'); QUnit.test('hoge', function() { for (var i = 0; i < 30000; i++) { assert.ok(true); } }); QUnit.start();
ã®ããã«ãæéã®ããããã¹ããè¡ãã¨ãä¸æãããã¾ããã
$ prove --ext=.js --exec=node t/hoge.js .. 29145/? node.js:134 throw e; // process.nextTick error, or 'error' event on first tick ^ TypeError: Object #<Object> has no method 'setTimeout' at process (/Users/sugyan/.nvm/v0.4.4/lib/node/.npm/qunit-tap/1.0.0/package/vendor/qunit/qunit/qunit.js:861:11) at Object.start (/Users/sugyan/.nvm/v0.4.4/lib/node/.npm/qunit-tap/1.0.0/package/vendor/qunit/qunit/qunit.js:412:4) at Object.<anonymous> (/Users/sugyan/temp/qunit-tap/t/hoge.js:9:7) at Module._compile (module.js:404:26) at Object..js (module.js:410:10) at Module.load (module.js:336:31) at Function._load (module.js:297:12) at Array.<anonymous> (module.js:423:10) at EventEmitter._tickCallback (node.js:126:26) t/hoge.js .. Dubious, test returned 1 (wstat 256, 0x100) All 30000 subtests passed Test Summary Report ------------------- t/hoge.js (Wstat: 256 Tests: 30000 Failed: 0) Non-zero exit status: 1 Parse errors: No plan found in TAP output Files=1, Tests=30000, 3 wallclock secs ( 2.27 usr 0.01 sys + 0.29 cusr 0.06 csys = 2.63 CPU) Result: FAIL
ã§ãhelper scriptã§"QUnit.config.updateRate"ã0ã«ããã¨ä¸æãããããã«ãªãã¾ãã
exports = module.exports = global; var path = require('path'); QUnit = require(path.join(path.dirname(require.resolve('qunit-tap')), '..', 'vendor', 'qunit', 'qunit', 'qunit')).QUnit; require("qunit-tap").qunitTap(QUnit, require("sys").puts, { noPlan: true }); QUnit.init(); QUnit.config.updateRate = 0; exports.assert = QUnit;
ã©ãããqunit.jsã®ä¸ã§ãã®è¨å®å¤ã¨ãã¹ãå®è¡æéã«ãã£ã¦å¦çãåãåãã¦ããããã§
while ( config.queue.length && !config.blocking ) { if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) { config.queue.shift()(); } else { window.setTimeout( process, 13 ); break; } }
ååã«å¤§ããªå¤ã«ãã¦ãããã0以ä¸ã«ãã¦ããã°æéã®ããããã¹ãã®ã¨ãã«åé¡ãèµ·ãããªããªãâ¦ãããããã©ä¸ã®"setTimeout(process, 13)"ã£ã¦ãªãã â¦ï¼ãã¸ãã¯ãã³ãã¼ãã
è足
æåãæéãããããã¹ããããããããã
require('../test_helper.js'); QUnit.test('hoge', function() { setTimeout(function() { assert.ok(true); }, 1000); }); QUnit.start();
ã®ãããªã®ãæ¸ãã¦ãã¦ãupdateRateãè¨å®ãã¦ãåãã¾ãã ï¼ï¼ãã¨ãªã£ã¦ãããã§ãããQUnitã§éåæã®ãã¹ããæ¸ãå ´åã¯QUnit#stop 㨠QUnit#start ã®çµã¿åãããã QUnit#asyncTest ã使ãããã§ãã
require('../test_helper.js'); QUnit.asyncTest('hoge', function() { setTimeout(function() { assert.ok(true); QUnit.start(); }, 1000); }); QUnit.test('fuga' , function() { QUnit.stop(200); setTimeout(function() { assert.ok(true); QUnit.start(); }, 100); }); QUnit.start();
ã¡ããã¨QUnitã®ããã¥ã¡ã³ã( http://docs.jquery.com/QUnit/asyncTest ãããï¼ )ã¨ãèªãã¹ãã§ããã