Skip to content

Commit 05a1e5e

Browse files
committed
fix mocha output
1 parent f8eb89c commit 05a1e5e

File tree

2 files changed

+110
-103
lines changed

2 files changed

+110
-103
lines changed

bin/test.js

Lines changed: 109 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -213,120 +213,127 @@ if (options.mocha) {
213213
process.on('exit', function () {
214214
process.exit(failures); // exit with non-zero status if there were failures
215215
});
216+
} else {
217+
runTests();
216218
}
217219
});
218-
}
220+
} else runTests();
219221

220222
// run tests
221-
console.log('\n*** START TESTING ***\n');
222-
if (options.evalCode) {
223-
var EOF = engine.lexer.EOF;
224-
engine.lexer.mode_eval = true;
225-
engine.lexer.all_tokens = false;
226-
engine.lexer.setInput(options.evalCode);
227-
var token = engine.lexer.lex() || EOF;
228-
var names = engine.tokens.values;
229-
var tokens = [];
230-
while(token != EOF) {
231-
if (names[token]) {
232-
tokens.push(names[token]);
223+
function runTests() {
224+
225+
console.log('\n*** START TESTING ***\n');
226+
if (options.evalCode) {
227+
var EOF = engine.lexer.EOF;
228+
engine.lexer.mode_eval = true;
229+
engine.lexer.all_tokens = false;
230+
engine.lexer.setInput(options.evalCode);
231+
var token = engine.lexer.lex() || EOF;
232+
var names = engine.tokens.values;
233+
var tokens = [];
234+
while(token != EOF) {
235+
if (names[token]) {
236+
tokens.push(names[token]);
237+
} else {
238+
tokens.push(token);
239+
}
240+
token = engine.lexer.lex() || EOF;
241+
}
242+
console.log('-- TOKENS : ');
243+
console.log(tokens.join(' '));
244+
245+
var ast = engine.parser.parse(options.evalCode);
246+
console.log('-- AST : ');
247+
console.log(
248+
util.inspect(
249+
ast, {
250+
showHidden: false,
251+
depth: 20,
252+
colors: true
253+
}
254+
)
255+
);
256+
257+
} else if (options.filename) {
258+
if (!test(options.filename)) {
259+
abort('Error: test FAILED !!!');
233260
} else {
234-
tokens.push(token);
261+
console.log('Success');
235262
}
236-
token = engine.lexer.lex() || EOF;
237-
}
238-
console.log('-- TOKENS : ');
239-
console.log(tokens.join(' '));
263+
} else if (options.path) {
240264

241-
var ast = engine.parser.parse(options.evalCode);
242-
console.log('-- AST : ');
243-
console.log(
244-
util.inspect(
245-
ast, {
246-
showHidden: false,
247-
depth: 20,
248-
colors: true
249-
}
250-
)
251-
);
252-
253-
} else if (options.filename) {
254-
if (!test(options.filename)) {
255-
abort('Error: test FAILED !!!');
256-
} else {
257-
console.log('Success');
258-
}
259-
} else if (options.path) {
260-
261-
var files = [];
262-
var scanFiles = function(path) {
263-
var items = fs.readdirSync(path);
264-
for(var i = 0; i < items.length; i ++) {
265-
var file = items[i];
266-
if (file[0] != '.') {
267-
var stat = fs.statSync(path + file);
268-
if (!stat.isDirectory()) {
269-
files.push(path + file);
270-
} else if (options.recusive) {
271-
scanFiles(path + file + '/');
265+
var files = [];
266+
var scanFiles = function(path) {
267+
var items = fs.readdirSync(path);
268+
for(var i = 0; i < items.length; i ++) {
269+
var file = items[i];
270+
if (file[0] != '.') {
271+
var stat = fs.statSync(path + file);
272+
if (!stat.isDirectory()) {
273+
files.push(path + file);
274+
} else if (options.recusive) {
275+
scanFiles(path + file + '/');
276+
}
272277
}
273278
}
274-
}
275-
};
276-
277-
console.log('Scan files ' + options.path);
278-
scanFiles(options.path);
279-
console.log('Found ' + files.length + ' items');
280-
281-
var stats = {
282-
time: process.hrtime(),
283-
progress: 0,
284-
code: 0
285-
};
279+
};
286280

287-
function secondsToTime(secs)
288-
{
289-
secs = Math.round(secs);
290-
var hours = Math.floor(secs / (60 * 60));
291-
if (hours < 10) hours = '0' + hours;
292-
var divisor_for_minutes = secs % (60 * 60);
293-
var minutes = Math.floor(divisor_for_minutes / 60);
294-
if (minutes < 10) minutes = '0' + minutes;
295-
var divisor_for_seconds = divisor_for_minutes % 60;
296-
var seconds = Math.ceil(divisor_for_seconds);
297-
if (seconds < 10) seconds = '0' + seconds;
298-
return hours + ':' + minutes + ':' + seconds;
299-
}
300-
// running
301-
for(var i = 0; i < files.length; i++) {
302-
var file = files[i];
303-
if (i / files.length * 100 > stats.progress + 2) {
304-
stats.progress = i / files.length * 100;
305-
var now = process.hrtime(stats.time);
306-
var remain = (now[0] / stats.progress) * (100 - stats.progress);
307-
console.log(
308-
'Progress ',
309-
Math.round(stats.progress) + '%',
310-
' remains ',
311-
secondsToTime(remain)
312-
);
281+
console.log('Scan files ' + options.path);
282+
scanFiles(options.path);
283+
console.log('Found ' + files.length + ' items');
284+
285+
var stats = {
286+
time: process.hrtime(),
287+
progress: 0,
288+
code: 0
289+
};
290+
291+
function secondsToTime(secs)
292+
{
293+
secs = Math.round(secs);
294+
var hours = Math.floor(secs / (60 * 60));
295+
if (hours < 10) hours = '0' + hours;
296+
var divisor_for_minutes = secs % (60 * 60);
297+
var minutes = Math.floor(divisor_for_minutes / 60);
298+
if (minutes < 10) minutes = '0' + minutes;
299+
var divisor_for_seconds = divisor_for_minutes % 60;
300+
var seconds = Math.ceil(divisor_for_seconds);
301+
if (seconds < 10) seconds = '0' + seconds;
302+
return hours + ':' + minutes + ':' + seconds;
313303
}
314-
try {
315-
test(file);
316-
} catch(e) {
317-
stats.code = 1;
318-
console.error('Error on ' + file);
319-
console.error(e);
304+
// running
305+
for(var i = 0; i < files.length; i++) {
306+
var file = files[i];
307+
if (i / files.length * 100 > stats.progress + 2) {
308+
stats.progress = i / files.length * 100;
309+
var now = process.hrtime(stats.time);
310+
var remain = (now[0] / stats.progress) * (100 - stats.progress);
311+
console.log(
312+
'Progress ',
313+
Math.round(stats.progress) + '%',
314+
' remains ',
315+
secondsToTime(remain)
316+
);
317+
}
318+
try {
319+
test(file);
320+
} catch(e) {
321+
stats.code = 1;
322+
console.error('Error on ' + file);
323+
console.error(e);
324+
}
320325
}
326+
327+
var duration = process.hrtime(stats.time);
328+
console.log('\n--------------------------------------');
329+
console.log('Tests duration : ' + duration[0] +'sec');
330+
331+
if (stats.code === 0) {
332+
console.log('I AM HAPPY !');
333+
}
334+
335+
process.exit(stats.code);
321336
}
322337

323-
var duration = process.hrtime(stats.time);
324-
console.log('\n--------------------------------------');
325-
console.log('Tests duration : ' + duration[0] +'sec');
326-
327-
if (stats.code === 0) {
328-
console.log('I AM HAPPY !');
329-
}
330-
331-
process.exit(stats.code);
332338
}
339+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"bench": "node --expose-gc bin/bench.js",
88
"test": "node --stack-size=5000 bin/test.js -r -d test/",
9-
"cover": "node --stack-size=5000 node_modules/istanbul/lib/cli.js cover -x \"**/bin/**\" bin/test.js -- -r -d test/ -m test/functional",
9+
"cover": "node --stack-size=5000 node_modules/istanbul/lib/cli.js cover -x \"**/bin/**\" bin/test.js -- -r -d test/ -m test/functional/",
1010
"mocha": "node node_modules/mocha/bin/mocha test/functional --stack-size=5000"
1111
},
1212
"repository": {

0 commit comments

Comments
 (0)