1 var assert = require('assert'),
3 path = require('path'),
4 nodeunit = require('../lib/nodeunit');
7 var setup = function (fn) {
8 return function (test) {
9 process.chdir(__dirname);
11 mock_module1: require(__dirname + '/fixtures/mock_module1'),
12 mock_module2: require(__dirname + '/fixtures/mock_module2'),
13 mock_module3: require(__dirname + '/fixtures/dir/mock_module3'),
14 mock_module4: require(__dirname + '/fixtures/dir/mock_module4')
21 exports.testRunFiles = setup(function (test) {
23 var runModule_copy = nodeunit.runModule;
25 var runModule_calls = [];
29 moduleStart: function () {
32 testDone: function () {
35 testStart: function () {
41 done: function (assertions) {
42 test.equals(assertions.failures(), 0, 'failures');
43 test.equals(assertions.length, 4, 'length');
44 test.ok(typeof assertions.duration === "number");
46 var called_with = function (name) {
47 return runModule_calls.some(function (m) {
48 return m.name === name;
51 test.ok(called_with('mock_module1'), 'mock_module1 ran');
52 test.ok(called_with('mock_module2'), 'mock_module2 ran');
53 test.ok(called_with('mock_module3'), 'mock_module3 ran');
54 test.ok(called_with('mock_module4'), 'mock_module4 ran');
55 test.equals(runModule_calls.length, 4);
57 nodeunit.runModule = runModule_copy;
62 nodeunit.runModule = function (name, mod, options, callback) {
63 test.equals(options.testDone, opts.testDone);
64 test.equals(options.testStart, opts.testStart);
65 test.equals(options.log, opts.log);
66 test.ok(typeof name === "string");
67 runModule_calls.push(mod);
68 var m = [{failed: function () {
76 [__dirname + '/fixtures/mock_module1.js',
77 __dirname + '/fixtures/mock_module2.js',
78 __dirname + '/fixtures/dir'],
83 exports.testRunFilesEmpty = function (test) {
85 nodeunit.runFiles([], {
86 moduleStart: function () {
87 test.ok(false, 'should not be called');
89 testDone: function () {
90 test.ok(false, 'should not be called');
92 testStart: function () {
93 test.ok(false, 'should not be called');
96 test.ok(false, 'should not be called');
98 done: function (assertions) {
99 test.equals(assertions.failures(), 0, 'failures');
100 test.equals(assertions.length, 0, 'length');
101 test.ok(typeof assertions.duration === "number");
108 exports.testEmptyDir = function (test) {
109 var dir2 = __dirname + '/fixtures/dir2';
111 // git doesn't like empty directories, so we have to create one
112 path.exists(dir2, function (exists) {
114 fs.mkdirSync(dir2, 0777);
117 // runFiles on empty directory:
118 nodeunit.runFiles([dir2], {
119 moduleStart: function () {
120 test.ok(false, 'should not be called');
122 testDone: function () {
123 test.ok(false, 'should not be called');
125 testStart: function () {
126 test.ok(false, 'should not be called');
129 test.ok(false, 'should not be called');
131 done: function (assertions) {
132 test.equals(assertions.failures(), 0, 'failures');
133 test.equals(assertions.length, 0, 'length');
134 test.ok(typeof assertions.duration === "number");
144 CoffeeScript = require('coffee-script');
149 exports.testCoffeeScript = function (test) {
150 process.chdir(__dirname);
152 mock_coffee_module: require(__dirname +
153 '/fixtures/coffee/mock_coffee_module')
157 var runModule_copy = nodeunit.runModule;
159 var runModule_calls = [];
163 moduleStart: function () {
164 return 'moduleStart';
166 testDone: function () {
169 testStart: function () {
175 done: function (assertions) {
176 test.equals(assertions.failures(), 0, 'failures');
177 test.equals(assertions.length, 1, 'length');
178 test.ok(typeof assertions.duration === "number");
180 var called_with = function (name) {
181 return runModule_calls.some(function (m) {
182 return m.name === name;
186 called_with('mock_coffee_15'),
187 'mock_coffee_module ran'
189 test.equals(runModule_calls.length, 1);
191 nodeunit.runModule = runModule_copy;
196 nodeunit.runModule = function (name, mod, options, callback) {
197 test.equals(options.testDone, opts.testDone);
198 test.equals(options.testStart, opts.testStart);
199 test.equals(options.log, opts.log);
200 test.ok(typeof name === "string");
201 runModule_calls.push(mod);
202 var m = [{failed: function () {
210 [__dirname + 'fixtures/coffee/mock_coffee_module.coffee'],