Skip to content

Commit 3b09730

Browse files
committed
Replace mocha with tape
1 parent f3ab578 commit 3b09730

File tree

2 files changed

+45
-58
lines changed

2 files changed

+45
-58
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@
2222
"browserify": "^13.0.0",
2323
"emoticon": "^2.0.0",
2424
"esmangle": "^1.0.0",
25+
"is-hidden": "^1.1.0",
2526
"istanbul": "^0.4.0",
26-
"mocha": "^3.0.0",
27+
"negate": "^1.0.0",
2728
"remark-cli": "^2.1.0",
2829
"remark-preset-wooorm": "^1.0.0",
2930
"retext": "^4.0.0",
3031
"retext-english": "^2.0.0",
32+
"tape": "^4.6.2",
3133
"xo": "^0.17.1"
3234
},
3335
"scripts": {
34-
"test-api": "mocha --check-leaks test/index.js",
35-
"test-coverage": "istanbul cover _mocha -- test/index.js",
36+
"test-api": "node test",
37+
"test-coverage": "istanbul cover tape test/index.js",
3638
"test-travis": "npm run test-coverage",
3739
"test": "npm run test-api",
3840
"lint": "xo",

test/index.js

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,67 @@
11
'use strict';
22

3-
/* eslint-env mocha */
4-
3+
var fs = require('fs');
4+
var path = require('path');
55
var assert = require('assert');
6+
var test = require('tape');
67
var retext = require('retext');
78
var english = require('retext-english');
89
var emoticons = require('emoticon');
10+
var negate = require('negate');
11+
var hidden = require('is-hidden');
12+
var toString = require('nlcst-to-string');
913
var modifier = require('..');
1014

11-
var smile = require('./fixtures/smile');
12-
var invalid = require('./fixtures/invalid');
13-
var adjacent = require('./fixtures/adjacent');
14-
var sentenceStart = require('./fixtures/sentence-start');
15-
16-
/* Processors. */
1715
var position = retext(english).use(plugin);
1816
var noPosition = retext(english).use(plugin).use(function (instance) {
1917
instance.Parser.prototype.position = false;
2018
});
2119

22-
/*
23-
* Tests.
24-
*/
25-
26-
describe('nlcst-emoticon-modifier()', function () {
27-
it('should throw when not given a parent', function () {
28-
assert.throws(
29-
function () {
30-
modifier({});
31-
},
32-
/Missing children in `parent`/
33-
);
34-
});
35-
36-
it('should classify emoticons (`:)`)', function () {
37-
check('This makes me feel :).', smile);
38-
});
39-
40-
it('should NOT classify invalid emoticons (`):` and `: (`)', function () {
41-
check('Well: (This makes me feel):.', invalid);
42-
});
43-
44-
it('should classify adjacent emoticons (`:) :(`)', function () {
45-
check('This makes me feel :) :(.', adjacent);
46-
});
20+
test('nlcst-emoticon-modifier()', function (t) {
21+
var root = path.join(__dirname, 'fixtures');
22+
23+
t.throws(
24+
function () {
25+
modifier({});
26+
},
27+
/Missing children in `parent`/,
28+
'should throw when not given a parent'
29+
);
30+
31+
fs
32+
.readdirSync(root)
33+
.filter(negate(hidden))
34+
.forEach(function (filename) {
35+
var tree = JSON.parse(fs.readFileSync(path.join(root, filename)));
36+
var fixture = toString(tree);
37+
var name = path.basename(filename, path.extname(filename));
38+
39+
t.deepEqual(position.parse(fixture), tree, name);
40+
t.deepEqual(noPosition.parse(fixture), clean(tree), name + ' (positionless)');
41+
});
4742

48-
it('should classify emoticons at sentence start', function () {
49-
check('<3 I’m going to bed.', sentenceStart);
50-
});
43+
t.end();
5144
});
5245

53-
/*
54-
* Check all emoticons.
55-
*/
46+
test('emoticons', function (t) {
47+
emoticons.forEach(function (emoticon) {
48+
emoticon.emoticons.forEach(function (value) {
49+
var fixture = 'Who doesn’t like ' + value + '?';
50+
var node = position.run(position.parse(fixture));
51+
var emoticon = node.children[0].children[0].children[6];
5652

57-
emoticons.forEach(function (emoticon) {
58-
emoticon.emoticons.forEach(function (value) {
59-
describe(value, function () {
60-
it(
61-
'should classify `' + value + '` as an `EmoticonNode`',
53+
t.doesNotThrow(
6254
function () {
63-
var fixture = 'Who doesn’t like ' + value + '?';
64-
var node = position.run(position.parse(fixture));
65-
var emoticon = node.children[0].children[0].children[6];
66-
6755
assert.strictEqual(emoticon.type, 'EmoticonNode');
6856
assert.strictEqual(emoticon.value, value);
69-
}
57+
},
58+
value
7059
);
7160
});
7261
});
73-
});
7462

75-
/* Short-cut to access the CST. */
76-
function check(fixture, node) {
77-
assert.deepEqual(position.run(position.parse(fixture)), node);
78-
assert.deepEqual(noPosition.run(noPosition.parse(fixture, {position: false})), clean(node));
79-
}
63+
t.end();
64+
});
8065

8166
/* Add modifier to processor. */
8267
function plugin(processor) {

0 commit comments

Comments
 (0)