Skip to content

Commit 669a6d2

Browse files
committed
Merge pull request #13 from takamin/use-mocha
Support mocha to test
2 parents 3ee1c56 + 07ada93 commit 669a6d2

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "list-it",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "This module is used to create a preformatted text table.",
55
"repository": {
66
"type": "git",

test/test.js

+39-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
(function() {
1+
(function(describe, it) {
22
"use strict";
33
var listit = require('../lib');
44
var chai = require('chai');
55
var should = chai.should();
66
var assert = chai.assert;
7+
8+
// Ansi escape sequences
79
var ansi = require('ansi-escape-sequences');
810
var style = {};
911
var fg = {};
@@ -22,38 +24,49 @@
2224
delete fg[key];
2325
}
2426
});
25-
var col = 0;
26-
var logbuf = listit.buffer();
27-
process.on("exit", function() {
28-
console.error(logbuf.toString());
29-
});
30-
var titles = [];
31-
function describe(name, func) {
32-
titles.push(name);
33-
func();
34-
titles = titles.slice(0, titles.length - 1);
35-
}
3627
function styled(message, styles) {
3728
var args = Array.apply(null, arguments);
3829
styles = args.slice(1);
3930
styles.push(message, ansi.style.reset);
4031
return styles.join('');
4132
}
42-
function it(name, test) {
43-
logbuf.d(titles.join(" ") + " " + name);
44-
try {
45-
test();
46-
logbuf.d(styled(" PASS ",
47-
bg.green, fg.white));
48-
logbuf.nl();
49-
} catch(ex) {
50-
logbuf.d(styled(" FAIL ",
51-
bg.red, fg.white, style.bold));
52-
logbuf.nl();
53-
test();
54-
console.error(ex);
33+
34+
// Alternate Mocha
35+
if(!describe && !it) {
36+
var logbuf = listit.buffer();
37+
var titles = [];
38+
var pass = styled(" \u2713 ", fg.green);
39+
var fail = styled(" \u2717 ", bg.red, fg.white, style.bold);
40+
var indent = function() {
41+
return " " + " ".repeat(titles.length);
42+
};
43+
var result = function(result, name) {
44+
return indent() + result + " " + name;
45+
};
46+
describe = function (name, func) {
47+
console.log(indent() + styled(name, style.bold));
48+
titles.push(name);
49+
func();
50+
titles = titles.slice(0, titles.length - 1);
51+
}
52+
it = function (name, test) {
53+
logbuf.d(titles.join(" ") + " " + name);
54+
try {
55+
test();
56+
logbuf.d(pass);
57+
logbuf.nl();
58+
console.log(result(pass, name));
59+
} catch(ex) {
60+
logbuf.d(fail);
61+
logbuf.nl();
62+
console.log(result(fail, styled(name, fg.red, style.bold)));
63+
test();
64+
console.error(ex);
65+
}
5566
}
5667
}
68+
69+
// Tests
5770
describe("listit.buffer", function() {
5871
describe("#constructor", function() {
5972
it('should return a blank string', function() {
@@ -289,4 +302,4 @@
289302
});
290303
});
291304
});
292-
}());
305+
}((typeof(describe) == "function") ? describe : false, (typeof(it) == "function") ? it : false));

0 commit comments

Comments
 (0)