Skip to content

Commit 041314d

Browse files
committed
Replace mocha with tape, istanbul with nyc
1 parent bb6e412 commit 041314d

File tree

3 files changed

+124
-104
lines changed

3 files changed

+124
-104
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
.DS_Store
22
*.log
3-
bower_components/
4-
build/
5-
components/
3+
.nyc_output/
64
coverage/
75
node_modules/
8-
build.js
6+
unist-util-find-before.js
7+
unist-util-find-before.min.js

package.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,31 @@
3434
"devDependencies": {
3535
"browserify": "^11.0.0",
3636
"esmangle": "^1.0.0",
37-
"istanbul": "^0.3.0",
3837
"mdast": "^1.0.0",
3938
"mdast-comment-config": "^1.0.0",
4039
"mdast-github": "^1.0.0",
4140
"mdast-lint": "^1.0.0",
4241
"mdast-slug": "^1.0.0",
4342
"mdast-validate-links": "^1.0.0",
44-
"mocha": "^2.0.0",
43+
"nyc": "^9.0.1",
44+
"tape": "^4.6.2",
4545
"xo": "^0.17.1"
4646
},
4747
"scripts": {
48-
"test-api": "mocha --check-leaks test.js",
49-
"test-coverage": "istanbul cover _mocha -- test.js",
50-
"test-travis": "npm run test-coverage",
51-
"test": "npm run test-api",
52-
"lint": "xo",
53-
"make": "npm run lint && npm run test-coverage",
54-
"bundle": "browserify index.js --no-builtins -s unistUtilFindBefore > unist-util-find-before.js",
55-
"postbundle": "esmangle unist-util-find-before.js > unist-util-find-before.min.js",
5648
"build-md": "mdast . --quiet",
57-
"build": "npm run bundle && npm run build-md"
49+
"build-bundle": "browserify index.js --no-builtins -s unistUtilFindBefore > unist-util-find-before.js",
50+
"build-mangle": "esmangle unist-util-find-before.js > unist-util-find-before.min.js",
51+
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
52+
"lint": "xo",
53+
"test-api": "node test",
54+
"test-coverage": "nyc --reporter lcov tape test.js",
55+
"test": "npm run build && npm run lint && npm run test-coverage"
56+
},
57+
"nyc": {
58+
"check-coverage": true,
59+
"lines": 100,
60+
"functions": 100,
61+
"branches": 100
5862
},
5963
"xo": {
6064
"space": true,

test.js

Lines changed: 106 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,128 @@
11
'use strict';
22

3-
/* eslint-env mocha */
4-
53
var assert = require('assert');
4+
var test = require('tape');
65
var mdast = require('mdast');
76
var findBefore = require('./');
87

98
var tree = mdast.parse('Some *emphasis*, **importance**, and `code`.');
109
var paragraph = tree.children[0];
1110
var children = paragraph.children;
1211

13-
describe('unist-util-find-before', function () {
14-
it('should fail without parent', function () {
15-
assert.throws(
16-
function () {
17-
findBefore();
18-
},
19-
/Expected parent node/
20-
);
21-
});
12+
test('unist-util-find-before', function (t) {
13+
t.throws(
14+
function () {
15+
findBefore();
16+
},
17+
/Expected parent node/,
18+
'should fail without parent'
19+
);
20+
21+
t.throws(
22+
function () {
23+
findBefore({
24+
type: 'foo'
25+
});
26+
},
27+
/Expected parent node/,
28+
'should fail without parent node'
29+
);
2230

23-
it('should fail without parent node', function () {
24-
assert.throws(
25-
function () {
26-
findBefore({
27-
type: 'foo'
28-
});
29-
},
30-
/Expected parent node/
31-
);
32-
});
31+
t.doesNotThrow(
32+
function () {
33+
assert.throws(
34+
function () {
35+
findBefore({type: 'foo', children: []});
36+
},
37+
/Expected positive finite index or child node/
38+
);
3339

34-
it('should fail without index', function () {
35-
assert.throws(
36-
function () {
37-
findBefore({type: 'foo', children: []});
38-
},
39-
/Expected positive finite index or child node/
40-
);
40+
assert.throws(
41+
function () {
42+
findBefore({type: 'foo', children: []}, -1);
43+
},
44+
/Expected positive finite index or child node/
45+
);
4146

42-
assert.throws(
43-
function () {
44-
findBefore({type: 'foo', children: []}, -1);
45-
},
46-
/Expected positive finite index or child node/
47-
);
47+
assert.throws(
48+
function () {
49+
findBefore({type: 'foo', children: []}, {type: 'bar'});
50+
},
51+
/Expected positive finite index or child node/
52+
);
53+
},
54+
'should fail without index'
55+
);
4856

49-
assert.throws(
50-
function () {
51-
findBefore({type: 'foo', children: []}, {type: 'bar'});
52-
},
53-
/Expected positive finite index or child node/
54-
);
55-
});
57+
t.doesNotThrow(
58+
function () {
59+
assert.throws(
60+
function () {
61+
findBefore({
62+
type: 'foo',
63+
children: [{type: 'bar'}]
64+
}, 1, false);
65+
},
66+
/Expected function, string, or node as test/
67+
);
5668

57-
it('should fail for invalid `test`', function () {
58-
assert.throws(
59-
function () {
60-
findBefore({
61-
type: 'foo',
62-
children: [{type: 'bar'}]
63-
}, 1, false);
64-
},
65-
/Expected function, string, or node as test/
66-
);
69+
assert.throws(
70+
function () {
71+
findBefore({
72+
type: 'foo',
73+
children: [{type: 'bar'}]
74+
}, 1, true);
75+
},
76+
/Expected function, string, or node as test/
77+
);
78+
},
79+
'should fail for invalid `test`'
80+
);
6781

68-
assert.throws(
69-
function () {
70-
findBefore({
71-
type: 'foo',
72-
children: [{type: 'bar'}]
73-
}, 1, true);
74-
},
75-
/Expected function, string, or node as test/
76-
);
77-
});
82+
t.doesNotThrow(
83+
function () {
84+
assert.strictEqual(findBefore(paragraph, children[1]), children[0]);
85+
assert.strictEqual(findBefore(paragraph, 1), children[0]);
86+
assert.strictEqual(findBefore(paragraph, 0), null);
87+
},
88+
'should return the preceding node when without `test`'
89+
);
7890

79-
it('should return the preceding node when without `test`', function () {
80-
assert.strictEqual(findBefore(paragraph, children[1]), children[0]);
81-
assert.strictEqual(findBefore(paragraph, 1), children[0]);
82-
assert.strictEqual(findBefore(paragraph, 0), null);
83-
});
91+
t.doesNotThrow(
92+
function () {
93+
assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]);
94+
assert.strictEqual(findBefore(paragraph, children[1], children[0]), children[0]);
95+
assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]);
96+
assert.strictEqual(findBefore(paragraph, children[0], children[0]), null);
97+
assert.strictEqual(findBefore(paragraph, 0, children[0]), null);
98+
assert.strictEqual(findBefore(paragraph, 1, children[1]), null);
99+
},
100+
'should return `node` when given a `node` and existing'
101+
);
84102

85-
it('should return `node` when given a `node` and existing', function () {
86-
assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]);
87-
assert.strictEqual(findBefore(paragraph, children[1], children[0]), children[0]);
88-
assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]);
89-
assert.strictEqual(findBefore(paragraph, children[0], children[0]), null);
90-
assert.strictEqual(findBefore(paragraph, 0, children[0]), null);
91-
assert.strictEqual(findBefore(paragraph, 1, children[1]), null);
92-
});
103+
t.doesNotThrow(
104+
function () {
105+
assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]);
106+
assert.strictEqual(findBefore(paragraph, 3, 'strong'), null);
107+
assert.strictEqual(findBefore(paragraph, children[4], 'strong'), children[3]);
108+
assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null);
109+
},
110+
'should return a child when given a `type` and existing'
111+
);
93112

94-
it('should return a child when given a `type` and existing', function () {
95-
assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]);
96-
assert.strictEqual(findBefore(paragraph, 3, 'strong'), null);
97-
assert.strictEqual(findBefore(paragraph, children[4], 'strong'), children[3]);
98-
assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null);
99-
});
113+
t.doesNotThrow(
114+
function () {
115+
assert.strictEqual(findBefore(paragraph, 100, test), children[3]);
116+
assert.strictEqual(findBefore(paragraph, 3, test), null);
117+
assert.strictEqual(findBefore(paragraph, children[4], test), children[3]);
118+
assert.strictEqual(findBefore(paragraph, children[3], test), null);
100119

101-
it('should return a child when given a `test` and existing', function () {
102-
assert.strictEqual(findBefore(paragraph, 100, test), children[3]);
103-
assert.strictEqual(findBefore(paragraph, 3, test), null);
104-
assert.strictEqual(findBefore(paragraph, children[4], test), children[3]);
105-
assert.strictEqual(findBefore(paragraph, children[3], test), null);
120+
function test(node, n) {
121+
return n === 3;
122+
}
123+
},
124+
'should return a child when given a `test` and existing'
125+
);
106126

107-
function test(node, n) {
108-
return n === 3;
109-
}
110-
});
127+
t.end();
111128
});

0 commit comments

Comments
 (0)