Skip to content

Commit 7129f2c

Browse files
committed
Replace mocha with tape
1 parent 56956e7 commit 7129f2c

File tree

2 files changed

+120
-109
lines changed

2 files changed

+120
-109
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"remark-lint": "^3.0.0",
3939
"remark-slug": "^4.0.0",
4040
"remark-validate-links": "^3.0.0",
41-
"mocha": "^2.0.0",
42-
"retext": "^1.0.0"
41+
"retext": "^1.0.0",
42+
"tape": "^4.4.0"
4343
},
4444
"scripts": {
4545
"build-md": "remark . --quiet --frail",
@@ -49,8 +49,8 @@
4949
"lint-api": "eslint .",
5050
"lint-style": "jscs --reporter inline .",
5151
"lint": "npm run lint-api && npm run lint-style",
52-
"test-api": "mocha --check-leaks test.js",
53-
"test-coverage": "istanbul cover _mocha -- --check-leaks test.js",
52+
"test-api": "node test.js",
53+
"test-coverage": "istanbul cover test.js",
5454
"test": "npm run build && npm run lint && npm run test-coverage"
5555
}
5656
}

test.js

Lines changed: 116 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
'use strict';
1010

11-
/* eslint-env node, mocha */
11+
/* eslint-env node */
1212

1313
/*
1414
* Module dependencies.
1515
*/
1616

17-
var assert = require('assert');
17+
var test = require('tape');
1818
var chalk = require('chalk');
1919
var retext = require('retext');
2020
var inspect = require('./');
@@ -24,7 +24,6 @@ var inspect = require('./');
2424
*/
2525

2626
var strip = chalk.stripColor;
27-
var equal = assert.equal;
2827

2928
/*
3029
* Fixtures.
@@ -36,81 +35,75 @@ var paragraph = 'Some simple text. Other “sentence”.';
3635
* Tests.
3736
*/
3837

39-
describe('inspect', function () {
40-
it('should be a `function`', function () {
41-
equal(typeof inspect, 'function');
42-
});
38+
test('inspect', function (t) {
39+
t.equal(typeof inspect, 'function', 'should be a `function`');
40+
41+
t.test('should have `color` and `noColor` properties', function (st) {
42+
st.equal(typeof inspect.color, 'function');
43+
st.equal(typeof inspect.noColor, 'function');
4344

44-
it('should have `color` and `noColor` properties', function () {
45-
equal(typeof inspect.color, 'function');
46-
equal(typeof inspect.noColor, 'function');
45+
st.equal(typeof inspect.color.noColor, 'function');
46+
st.equal(typeof inspect.noColor.color, 'function');
4747

48-
equal(typeof inspect.color.noColor, 'function');
49-
equal(typeof inspect.noColor.color, 'function');
48+
st.end();
5049
});
50+
51+
t.end();
5152
});
5253

5354
/*
5455
* Unit tests for `Node#inspect()`.
5556
*/
5657

57-
describe('inspect()', function () {
58-
var tree;
59-
60-
before(function () {
61-
tree = retext().parse(paragraph);
62-
});
63-
64-
it('should work on `RootNode`', function () {
65-
equal(
66-
strip(inspect(tree)),
67-
[
68-
'RootNode[1] (1:1-1:36, 0-35)',
69-
'└─ ParagraphNode[3] (1:1-1:36, 0-35)',
70-
' ├─ SentenceNode[6] (1:1-1:18, 0-17)',
71-
' │ ├─ WordNode[1] (1:1-1:5, 0-4)',
72-
' │ │ └─ TextNode: "Some" (1:1-1:5, 0-4)',
73-
' │ ├─ WhiteSpaceNode: " " (1:5-1:6, 4-5)',
74-
' │ ├─ WordNode[1] (1:6-1:12, 5-11)',
75-
' │ │ └─ TextNode: "simple" (1:6-1:12, 5-11)',
76-
' │ ├─ WhiteSpaceNode: " " (1:12-1:13, 11-12)',
77-
' │ ├─ WordNode[1] (1:13-1:17, 12-16)',
78-
' │ │ └─ TextNode: "text" (1:13-1:17, 12-16)',
79-
' │ └─ PunctuationNode: "." (1:17-1:18, 16-17)',
80-
' ├─ WhiteSpaceNode: " " (1:18-1:19, 17-18)',
81-
' └─ SentenceNode[6] (1:19-1:36, 18-35)',
82-
' ├─ WordNode[1] (1:19-1:24, 18-23)',
83-
' │ └─ TextNode: "Other" (1:19-1:24, 18-23)',
84-
' ├─ WhiteSpaceNode: " " (1:24-1:25, 23-24)',
85-
' ├─ PunctuationNode: "“" (1:25-1:26, 24-25)',
86-
' ├─ WordNode[1] (1:26-1:34, 25-33)',
87-
' │ └─ TextNode: "sentence" (1:26-1:34, 25-33)',
88-
' ├─ PunctuationNode: "”" (1:34-1:35, 33-34)',
89-
' └─ PunctuationNode: "." (1:35-1:36, 34-35)'
90-
].join('\n')
91-
);
92-
});
58+
test('inspect()', function (t) {
59+
t.equal(
60+
strip(inspect(retext().parse(paragraph))),
61+
[
62+
'RootNode[1] (1:1-1:36, 0-35)',
63+
'└─ ParagraphNode[3] (1:1-1:36, 0-35)',
64+
' ├─ SentenceNode[6] (1:1-1:18, 0-17)',
65+
' │ ├─ WordNode[1] (1:1-1:5, 0-4)',
66+
' │ │ └─ TextNode: "Some" (1:1-1:5, 0-4)',
67+
' │ ├─ WhiteSpaceNode: " " (1:5-1:6, 4-5)',
68+
' │ ├─ WordNode[1] (1:6-1:12, 5-11)',
69+
' │ │ └─ TextNode: "simple" (1:6-1:12, 5-11)',
70+
' │ ├─ WhiteSpaceNode: " " (1:12-1:13, 11-12)',
71+
' │ ├─ WordNode[1] (1:13-1:17, 12-16)',
72+
' │ │ └─ TextNode: "text" (1:13-1:17, 12-16)',
73+
' │ └─ PunctuationNode: "." (1:17-1:18, 16-17)',
74+
' ├─ WhiteSpaceNode: " " (1:18-1:19, 17-18)',
75+
' └─ SentenceNode[6] (1:19-1:36, 18-35)',
76+
' ├─ WordNode[1] (1:19-1:24, 18-23)',
77+
' │ └─ TextNode: "Other" (1:19-1:24, 18-23)',
78+
' ├─ WhiteSpaceNode: " " (1:24-1:25, 23-24)',
79+
' ├─ PunctuationNode: "“" (1:25-1:26, 24-25)',
80+
' ├─ WordNode[1] (1:26-1:34, 25-33)',
81+
' │ └─ TextNode: "sentence" (1:26-1:34, 25-33)',
82+
' ├─ PunctuationNode: "”" (1:34-1:35, 33-34)',
83+
' └─ PunctuationNode: "." (1:35-1:36, 34-35)'
84+
].join('\n'),
85+
'should work on `RootNode`'
86+
);
9387

94-
it('should work on `SentenceNode`', function () {
95-
equal(
96-
strip(inspect(tree.children[0].children[0])),
97-
[
98-
'SentenceNode[6] (1:1-1:18, 0-17)',
99-
'├─ WordNode[1] (1:1-1:5, 0-4)',
100-
'│ └─ TextNode: "Some" (1:1-1:5, 0-4)',
101-
'├─ WhiteSpaceNode: " " (1:5-1:6, 4-5)',
102-
'├─ WordNode[1] (1:6-1:12, 5-11)',
103-
'│ └─ TextNode: "simple" (1:6-1:12, 5-11)',
104-
'├─ WhiteSpaceNode: " " (1:12-1:13, 11-12)',
105-
'├─ WordNode[1] (1:13-1:17, 12-16)',
106-
'│ └─ TextNode: "text" (1:13-1:17, 12-16)',
107-
'└─ PunctuationNode: "." (1:17-1:18, 16-17)'
108-
].join('\n')
109-
);
110-
});
88+
t.equal(
89+
strip(inspect(retext().parse(paragraph).children[0].children[0])),
90+
[
91+
'SentenceNode[6] (1:1-1:18, 0-17)',
92+
'├─ WordNode[1] (1:1-1:5, 0-4)',
93+
'│ └─ TextNode: "Some" (1:1-1:5, 0-4)',
94+
'├─ WhiteSpaceNode: " " (1:5-1:6, 4-5)',
95+
'├─ WordNode[1] (1:6-1:12, 5-11)',
96+
'│ └─ TextNode: "simple" (1:6-1:12, 5-11)',
97+
'├─ WhiteSpaceNode: " " (1:12-1:13, 11-12)',
98+
'├─ WordNode[1] (1:13-1:17, 12-16)',
99+
'│ └─ TextNode: "text" (1:13-1:17, 12-16)',
100+
'└─ PunctuationNode: "." (1:17-1:18, 16-17)'
101+
].join('\n'),
102+
'should work on `SentenceNode`'
103+
);
111104

112-
it('should work with a list of nodes', function () {
113-
equal(strip(inspect([
105+
t.equal(
106+
strip(inspect([
114107
{
115108
'type': 'SymbolNode',
116109
'value': '$'
@@ -122,32 +115,38 @@ describe('inspect()', function () {
122115
'value': '5,00'
123116
}]
124117
}
125-
])), [
118+
])),
119+
[
126120
'SymbolNode: "$"',
127121
'WordNode[1]',
128122
'└─ text: "5,00"'
129-
].join('\n'));
130-
});
123+
].join('\n'),
124+
'should work with a list of nodes'
125+
);
126+
127+
t.test('should work on non-nodes', function (st) {
128+
st.equal(strip(inspect('foo')), 'foo');
129+
st.equal(strip(inspect('null')), 'null');
130+
st.equal(strip(inspect(NaN)), 'NaN');
131+
st.equal(strip(inspect(3)), '3');
131132

132-
it('should work on non-nodes', function () {
133-
equal(strip(inspect('foo')), 'foo');
134-
equal(strip(inspect('null')), 'null');
135-
equal(strip(inspect(NaN)), 'NaN');
136-
equal(strip(inspect(3)), '3');
133+
st.end();
137134
});
138135

139-
it('should work with data attributes', function () {
140-
equal(strip(inspect({
136+
t.equal(
137+
strip(inspect({
141138
'type': 'SymbolNode',
142139
'value': '$',
143140
'data': {
144141
'test': true
145142
}
146-
})), 'SymbolNode: "$" [data={"test":true}]');
147-
});
143+
})),
144+
'SymbolNode: "$" [data={"test":true}]',
145+
'should work with data attributes'
146+
);
148147

149-
it('should work without `offset` in `position`', function () {
150-
equal(strip(inspect({
148+
t.equal(
149+
strip(inspect({
151150
'type': 'foo',
152151
'value': 'foo\nbaar',
153152
'position': {
@@ -160,22 +159,26 @@ describe('inspect()', function () {
160159
'column': 5
161160
}
162161
}
163-
})), 'foo: "foo\\nbaar" (1:1-2:5)');
164-
});
162+
})),
163+
'foo: "foo\\nbaar" (1:1-2:5)',
164+
'should work without `offset` in `position`'
165+
);
165166

166-
it('should work without `line` and `column` in `position`', function () {
167-
equal(strip(inspect({
167+
t.equal(
168+
strip(inspect({
168169
'type': 'foo',
169170
'value': 'foo\nbaar',
170171
'position': {
171172
'start': {},
172173
'end': {}
173174
}
174-
})), 'foo: "foo\\nbaar" (1:1-1:1)');
175-
});
175+
})),
176+
'foo: "foo\\nbaar" (1:1-1:1)',
177+
'should work without `line` and `column` in `position`'
178+
);
176179

177-
it('should work with just `offset` in `position`', function () {
178-
equal(strip(inspect({
180+
t.equal(
181+
strip(inspect({
179182
'type': 'foo',
180183
'value': 'foo\nbaar',
181184
'position': {
@@ -186,15 +189,18 @@ describe('inspect()', function () {
186189
'offset': 8
187190
}
188191
}
189-
})), 'foo: "foo\\nbaar" (1:1-1:1, 1-8)');
190-
});
191-
});
192+
})),
193+
'foo: "foo\\nbaar" (1:1-1:1, 1-8)',
194+
'should work with just `offset` in `position`'
195+
);
192196

193-
describe('inspect.noColor()', function () {
194-
it('should work', function () {
195-
var sentence = retext().parse(paragraph).children[0].children[0];
197+
t.end();
198+
});
196199

197-
equal(inspect.noColor(sentence), [
200+
test('inspect.noColor()', function (t) {
201+
t.equal(
202+
inspect.noColor(retext().parse(paragraph).children[0].children[0]),
203+
[
198204
'SentenceNode[6] (1:1-1:18, 0-17)',
199205
'├─ WordNode[1] (1:1-1:5, 0-4)',
200206
'│ └─ TextNode: "Some" (1:1-1:5, 0-4)',
@@ -205,15 +211,17 @@ describe('inspect.noColor()', function () {
205211
'├─ WordNode[1] (1:13-1:17, 12-16)',
206212
'│ └─ TextNode: "text" (1:13-1:17, 12-16)',
207213
'└─ PunctuationNode: "." (1:17-1:18, 16-17)'
208-
].join('\n'));
209-
});
210-
});
214+
].join('\n'),
215+
'should work'
216+
);
211217

212-
describe('inspect.color()', function () {
213-
it('should work', function () {
214-
var sentence = retext().parse(paragraph).children[0].children[0];
218+
t.end();
219+
});
215220

216-
equal(inspect.color(sentence), [
221+
test('inspect.color()', function (t) {
222+
t.equal(
223+
inspect.color(retext().parse(paragraph).children[0].children[0]),
224+
[
217225
'SentenceNode' +
218226
chalk.dim('[') + chalk.yellow('6') + chalk.dim(']') +
219227
' (1:1-1:18, 0-17)',
@@ -244,6 +252,9 @@ describe('inspect.color()', function () {
244252
chalk.dim('└─ ') + 'PunctuationNode' +
245253
chalk.dim(': ') + chalk.green('"."') +
246254
' (1:17-1:18, 16-17)'
247-
].join('\n'));
248-
});
255+
].join('\n'),
256+
'should work'
257+
);
258+
259+
t.end();
249260
});

0 commit comments

Comments
 (0)