Skip to content

Commit 1efd2ca

Browse files
committed
Refactor to replace mocha with tape
1 parent 60235cd commit 1efd2ca

File tree

2 files changed

+99
-76
lines changed

2 files changed

+99
-76
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"istanbul": "^0.4.0",
3535
"jscs": "^2.0.0",
3636
"jscs-jsdoc": "^1.0.0",
37-
"mocha": "^2.0.0",
3837
"parse-dutch": "^2.0.0",
3938
"parse-english": "^2.0.0",
4039
"parse-latin": "^2.0.0",
@@ -45,12 +44,13 @@
4544
"remark-slug": "^3.0.0",
4645
"remark-validate-links": "^2.0.0",
4746
"retext": "^1.0.0",
47+
"tape": "^4.4.0",
4848
"vfile": "^1.0.0"
4949
},
5050
"scripts": {
51-
"test-api": "mocha --check-leaks test/index.js",
52-
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test/index.js",
53-
"test-coverage": "istanbul cover _mocha -- test/index.js",
51+
"test-api": "node test/index.js",
52+
"test-coveralls": "istanbul cover --report lcovonly test/index.js",
53+
"test-coverage": "istanbul cover test/index.js",
5454
"test-travis": "npm run test-coveralls",
5555
"test": "npm run test-api",
5656
"lint-api": "eslint .",

test/index.js

Lines changed: 95 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3-
/* eslint-env node, mocha */
3+
/* eslint-env node */
44

55
/*
66
* Dependencies.
77
*/
88

9-
var assert = require('assert');
109
var fs = require('fs');
1110
var path = require('path');
11+
var test = require('tape');
1212
var remark = require('remark');
1313
var VFile = require('vfile');
1414
var Latin = require('parse-latin');
@@ -50,53 +50,76 @@ function toFile(tree) {
5050
* Tests.
5151
*/
5252

53-
describe('mdast-util-to-nlcst', function () {
54-
it('should fail when not given a file', function () {
55-
assert.throws(function () {
53+
test('mdast-util-to-nlcst', function (t) {
54+
t.throws(
55+
function () {
5656
toNLCST();
57-
}, /mdast-util-to-nlcst expected file/);
57+
},
58+
/mdast-util-to-nlcst expected file/,
59+
'should fail when not given a file'
60+
);
5861

59-
assert.throws(function () {
62+
t.throws(
63+
function () {
6064
toNLCST({});
61-
}, /mdast-util-to-nlcst expected file/);
62-
});
65+
},
66+
/mdast-util-to-nlcst expected file/,
67+
'should fail when not given a file (#2)'
68+
);
6369

64-
it('should fail when not given an AST', function () {
65-
assert.throws(function () {
70+
t.throws(
71+
function () {
6672
toNLCST(toFile());
67-
}, /mdast-util-to-nlcst expected node/);
73+
},
74+
/mdast-util-to-nlcst expected node/,
75+
'should fail when not given an AST'
76+
);
6877

69-
assert.throws(function () {
78+
t.throws(
79+
function () {
7080
toNLCST(toFile({}));
71-
}, /mdast-util-to-nlcst expected node/);
72-
});
73-
74-
it('should fail when not given a file', function () {
75-
var node = {
76-
'type': 'text',
77-
'value': 'foo'
78-
};
79-
80-
assert.throws(function () {
81-
toNLCST(node);
82-
}, /mdast-util-to-nlcst expected file/);
83-
84-
assert.throws(function () {
85-
toNLCST(node, {
81+
},
82+
/mdast-util-to-nlcst expected node/,
83+
'should fail when not given an AST (#2)'
84+
);
85+
86+
t.throws(
87+
function () {
88+
toNLCST({
89+
'type': 'text',
90+
'value': 'foo'
91+
});
92+
},
93+
/mdast-util-to-nlcst expected file/,
94+
'should fail when not given a file'
95+
);
96+
97+
t.throws(
98+
function () {
99+
toNLCST({
100+
'type': 'text',
101+
'value': 'foo'
102+
}, {
86103
'foo': 'bar'
87104
});
88-
}, /mdast-util-to-nlcst expected file/);
89-
});
105+
},
106+
/mdast-util-to-nlcst expected file/,
107+
'should fail when not given a file (#2)'
108+
);
90109

91-
it('should fail when not given positional information', function () {
92-
assert.throws(function () {
110+
t.throws(
111+
function () {
93112
toNLCST(toFile({
94113
'type': 'text',
95114
'value': 'foo'
96115
}));
97-
}, /mdast-util-to-nlcst expected position on nodes/);
116+
},
117+
/mdast-util-to-nlcst expected position on nodes/,
118+
'should fail when not given positional information'
119+
);
98120

99-
assert.throws(function () {
121+
t.throws(
122+
function () {
100123
toNLCST(toFile({
101124
'type': 'text',
102125
'value': 'foo',
@@ -105,10 +128,12 @@ describe('mdast-util-to-nlcst', function () {
105128
'end': {}
106129
}
107130
}));
108-
}, /mdast-util-to-nlcst expected position on nodes/);
109-
});
131+
},
132+
/mdast-util-to-nlcst expected position on nodes/,
133+
'should fail when not given positional information (#2)'
134+
);
110135

111-
it('should accept nodes without offsets', function () {
136+
t.test('should accept nodes without offsets', function (st) {
112137
var node = {
113138
'type': 'text',
114139
'value': 'foo',
@@ -126,11 +151,13 @@ describe('mdast-util-to-nlcst', function () {
126151

127152
toNLCST(toFile(node), Latin);
128153

129-
assert.equal(node.position.start.offset, 0);
130-
assert.equal(node.position.end.offset, 3);
154+
st.equal(node.position.start.offset, 0);
155+
st.equal(node.position.end.offset, 3);
156+
157+
st.end();
131158
});
132159

133-
it('should accept a parser', function () {
160+
t.test('should accept a parser', function (st) {
134161
var node = {
135162
'type': 'text',
136163
'value': 'foo',
@@ -146,58 +173,54 @@ describe('mdast-util-to-nlcst', function () {
146173
}
147174
};
148175

149-
assert.throws(function () {
176+
st.throws(function () {
150177
toNLCST(toFile(node));
151178
}, /mdast-util-to-nlcst expected parser/);
152179

153-
assert.doesNotThrow(function () {
180+
st.doesNotThrow(function () {
154181
toNLCST(toFile(node), English);
155182
});
156183

157-
assert.doesNotThrow(function () {
184+
st.doesNotThrow(function () {
158185
toNLCST(toFile(node), Dutch);
159186
});
160187

161-
assert.doesNotThrow(function () {
188+
st.doesNotThrow(function () {
162189
toNLCST(toFile(node), new English());
163190
});
164191

165-
assert.doesNotThrow(function () {
192+
st.doesNotThrow(function () {
166193
toNLCST(toFile(node), new Dutch());
167194
});
168-
});
169-
});
170195

171-
/**
172-
* Describe a fixture.
173-
*
174-
* @param {string} fixture - Name of fixture.
175-
*/
176-
function describeFixture(fixture) {
177-
it('should work on `' + fixture + '`', function (done) {
178-
var filepath = join(ROOT, fixture);
179-
var output = read(join(filepath, 'output.json'), 'utf-8');
180-
var input = read(join(filepath, 'input.md'), 'utf-8');
181-
182-
remark().process(input, function (err, file) {
183-
assert.deepEqual(toNLCST(file, Latin), JSON.parse(output));
184-
done(err);
185-
});
196+
st.end();
186197
});
187-
}
188-
189-
/*
190-
* Skip hidden files.
191-
*/
192-
193-
fixtures = fixtures.filter(function (filepath) {
194-
return filepath.indexOf('.') !== 0;
195198
});
196199

197200
/*
198201
* Assert fixtures.
199202
*/
200203

201-
describe('Fixtures', function () {
202-
fixtures.forEach(describeFixture);
204+
test('Fixtures', function (t) {
205+
fixtures
206+
.filter(function (filepath) {
207+
return filepath.indexOf('.') !== 0;
208+
})
209+
.forEach(function (fixture) {
210+
var filepath = join(ROOT, fixture);
211+
var output = read(join(filepath, 'output.json'), 'utf-8');
212+
var input = read(join(filepath, 'input.md'), 'utf-8');
213+
214+
remark().process(input, function (err, file) {
215+
t.ifError(err);
216+
217+
t.deepEqual(
218+
toNLCST(file, Latin),
219+
JSON.parse(output),
220+
'should work on `' + fixture + '`'
221+
);
222+
});
223+
});
224+
225+
t.end();
203226
});

0 commit comments

Comments
 (0)