Name: js-handler/node_modules/nodeunit/test/test-runmodule.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.testRunModule = function (test) { |
| 11: | test.expect(11); |
| 12: | var call_order = []; |
| 13: | var testmodule = { |
| 14: | test1: function (test) { |
| 15: | call_order.push('test1'); |
| 16: | test.ok(true, 'ok true'); |
| 17: | test.done(); |
| 18: | }, |
| 19: | test2: function (test) { |
| 20: | call_order.push('test2'); |
| 21: | test.ok(false, 'ok false'); |
| 22: | test.ok(false, 'ok false'); |
| 23: | test.done(); |
| 24: | }, |
| 25: | test3: function (test) { |
| 26: | call_order.push('test3'); |
| 27: | test.done(); |
| 28: | } |
| 29: | }; |
| 30: | nodeunit.runModule('testmodule', testmodule, { |
| 31: | log: function (assertion) { |
| 32: | call_order.push('log'); |
| 33: | }, |
| 34: | testStart: function (name) { |
| 35: | call_order.push('testStart'); |
| 36: | test.ok( |
| 37: | name.toString() === 'test1' || |
| 38: | name.toString() === 'test2' || |
| 39: | name.toString() === 'test3', |
| 40: | 'testStart called with test name ' |
| 41: | ); |
| 42: | }, |
| 43: | testDone: function (name, assertions) { |
| 44: | call_order.push('testDone'); |
| 45: | test.ok( |
| 46: | name.toString() === 'test1' || |
| 47: | name.toString() === 'test2' || |
| 48: | name.toString() === 'test3', |
| 49: | 'testDone called with test name' |
| 50: | ); |
| 51: | }, |
| 52: | moduleDone: function (name, assertions) { |
| 53: | call_order.push('moduleDone'); |
| 54: | test.equals(assertions.length, 3); |
| 55: | test.equals(assertions.failures(), 2); |
| 56: | test.equals(name, 'testmodule'); |
| 57: | test.ok(typeof assertions.duration === "number"); |
| 58: | test.same(call_order, [ |
| 59: | 'testStart', 'test1', 'log', 'testDone', |
| 60: | 'testStart', 'test2', 'log', 'log', 'testDone', |
| 61: | 'testStart', 'test3', 'testDone', |
| 62: | 'moduleDone' |
| 63: | ]); |
| 64: | } |
| 65: | }, test.done); |
| 66: | }; |
| 67: | |
| 68: | |
| 69: | exports.testRunModuleTestSpec = function (test) { |
| 70: | test.expect(6); |
| 71: | var call_order = []; |
| 72: | var testmodule = { |
| 73: | test1: function (test) { |
| 74: | test.ok(true, 'ok true'); |
| 75: | test.done(); |
| 76: | }, |
| 77: | test2: function (test) { |
| 78: | call_order.push('test2'); |
| 79: | test.ok(false, 'ok false'); |
| 80: | test.ok(false, 'ok false'); |
| 81: | test.done(); |
| 82: | }, |
| 83: | test3: function (test) { |
| 84: | test.done(); |
| 85: | } |
| 86: | }; |
| 87: | nodeunit.runModule('testmodule', testmodule, { |
| 88: | testspec: "test2", |
| 89: | log: function (assertion) { |
| 90: | call_order.push('log'); |
| 91: | }, |
| 92: | testStart: function (name) { |
| 93: | call_order.push('testStart'); |
| 94: | test.equals( |
| 95: | name,'test2', |
| 96: | 'testStart called with test name ' |
| 97: | ); |
| 98: | }, |
| 99: | testDone: function (name, assertions) { |
| 100: | call_order.push('testDone'); |
| 101: | test.equal( |
| 102: | name, 'test2', |
| 103: | 'testDone called with test name' |
| 104: | ); |
| 105: | }, |
| 106: | moduleDone: function (name, assertions) { |
| 107: | call_order.push('moduleDone'); |
| 108: | test.equals(assertions.length, 2); |
| 109: | test.equals(name, 'testmodule'); |
| 110: | test.ok(typeof assertions.duration === "number"); |
| 111: | test.same(call_order, [ |
| 112: | 'testStart', 'test2', 'log', 'log', 'testDone', |
| 113: | 'moduleDone' |
| 114: | ]); |
| 115: | } |
| 116: | }, test.done); |
| 117: | }; |
| 118: | |
| 119: | exports.testRunModuleEmpty = function (test) { |
| 120: | nodeunit.runModule('module with no exports', {}, { |
| 121: | log: function (assertion) { |
| 122: | test.ok(false, 'log should not be called'); |
| 123: | }, |
| 124: | testStart: function (name) { |
| 125: | test.ok(false, 'testStart should not be called'); |
| 126: | }, |
| 127: | testDone: function (name, assertions) { |
| 128: | test.ok(false, 'testDone should not be called'); |
| 129: | }, |
| 130: | moduleDone: function (name, assertions) { |
| 131: | test.equals(assertions.length, 0); |
| 132: | test.equals(assertions.failures(), 0); |
| 133: | test.equals(name, 'module with no exports'); |
| 134: | test.ok(typeof assertions.duration === "number"); |
| 135: | } |
| 136: | }, test.done); |
| 137: | }; |
| 138: | |
| 139: | |
| 140: | exports.testNestedTests = function (test) { |
| 141: | var call_order = []; |
| 142: | var m = { |
| 143: | test1: function (test) { |
| 144: | test.done(); |
| 145: | }, |
| 146: | suite: { |
| 147: | t1: function (test) { |
| 148: | test.done(); |
| 149: | }, |
| 150: | t2: function (test) { |
| 151: | test.done(); |
| 152: | }, |
| 153: | another_suite: { |
| 154: | t3: function (test) { |
| 155: | test.done(); |
| 156: | } |
| 157: | } |
| 158: | } |
| 159: | }; |
| 160: | nodeunit.runModule('modulename', m, { |
| 161: | testStart: function (name) { |
| 162: | call_order.push(['testStart'].concat(name)); |
| 163: | }, |
| 164: | testDone: function (name, assertions) { |
| 165: | call_order.push(['testDone'].concat(name)); |
| 166: | } |
| 167: | }, function () { |
| 168: | test.same(call_order, [ |
| 169: | ['testStart', 'test1'], ['testDone', 'test1'], |
| 170: | ['testStart', 'suite', 't1'], ['testDone', 'suite', 't1'], |
| 171: | ['testStart', 'suite', 't2'], ['testDone', 'suite', 't2'], |
| 172: | ['testStart', 'suite', 'another_suite', 't3'], |
| 173: | ['testDone', 'suite', 'another_suite', 't3'] |
| 174: | ]); |
| 175: | test.done(); |
| 176: | }); |
| 177: | }; |
