Skip to content

Commit f41cfc7

Browse files
committed
Replace istanbul with nyc, mocha with tape
1 parent e64ef55 commit f41cfc7

File tree

3 files changed

+133
-111
lines changed

3 files changed

+133
-111
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
*.log
3+
.nyc_output/
34
coverage/
45
node_modules/

package.json

Lines changed: 12 additions & 8 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": "^2.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",
5248
"lint": "xo",
53-
"make": "npm run lint && npm run test-coverage",
5449
"bundle": "browserify index.js --no-builtins -s unistUtilFindAllBefore > unist-util-find-all-before.js",
5550
"postbundle": "esmangle unist-util-find-all-before.js > unist-util-find-all-before.min.js",
5651
"build-md": "mdast . --quiet",
57-
"build": "npm run bundle && npm run build-md"
52+
"build": "npm run bundle && npm run build-md",
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: 120 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,131 @@
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 findAllBefore = require('./');
87

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

13-
describe('unist-util-find-all-before', function () {
14-
it('should fail without parent', function () {
15-
assert.throws(
16-
function () {
17-
findAllBefore();
18-
},
19-
/Expected parent node/
20-
);
21-
});
22-
23-
it('should fail without parent node', function () {
24-
assert.throws(
25-
function () {
26-
findAllBefore({type: 'foo'});
27-
},
28-
/Expected parent node/
29-
);
30-
});
31-
32-
it('should fail without index', function () {
33-
assert.throws(
34-
function () {
35-
findAllBefore({type: 'foo', children: []});
36-
},
37-
/Expected positive finite index or child node/
38-
);
39-
40-
assert.throws(
41-
function () {
42-
findAllBefore({type: 'foo', children: []}, -1);
43-
},
44-
/Expected positive finite index or child node/
45-
);
46-
47-
assert.throws(
48-
function () {
49-
findAllBefore({type: 'foo', children: []}, {type: 'bar'});
50-
},
51-
/Expected positive finite index or child node/
52-
);
53-
});
54-
55-
it('should fail for invalid `test`', function () {
56-
assert.throws(
57-
function () {
58-
findAllBefore({type: 'foo', children: [{type: 'bar'}]}, 1, false);
59-
},
60-
/Expected function, string, or node as test/
61-
);
62-
63-
assert.throws(
64-
function () {
65-
findAllBefore({
66-
type: 'foo',
67-
children: [{type: 'bar'}]
68-
}, 1, true);
69-
},
70-
/Expected function, string, or node as test/
71-
);
72-
});
73-
74-
it('should return the preceding nodes when without `test`', function () {
75-
var res = [children[0]];
76-
77-
assert.deepEqual(findAllBefore(paragraph, children[1]), res);
78-
assert.deepEqual(findAllBefore(paragraph, 1), res);
79-
assert.deepEqual(findAllBefore(paragraph, 0), []);
80-
});
81-
82-
it('should return `[node]` when given a `node` and existing', function () {
83-
var res = [children[0]];
84-
85-
assert.deepEqual(findAllBefore(paragraph, 100, children[0]), res);
86-
assert.deepEqual(findAllBefore(paragraph, children[1], children[0]), res);
87-
assert.deepEqual(findAllBefore(paragraph, 1, children[0]), res);
88-
assert.deepEqual(findAllBefore(paragraph, children[0], children[0]), []);
89-
assert.deepEqual(findAllBefore(paragraph, 0, children[0]), []);
90-
assert.deepEqual(findAllBefore(paragraph, 1, children[1]), []);
91-
});
92-
93-
it('should return children when given a `type` and existing', function () {
94-
var result = [children[3]];
95-
96-
assert.deepEqual(findAllBefore(paragraph, 100, 'strong'), result);
97-
assert.deepEqual(findAllBefore(paragraph, 3, 'strong'), []);
98-
assert.deepEqual(findAllBefore(paragraph, children[4], 'strong'), result);
99-
assert.deepEqual(findAllBefore(paragraph, children[3], 'strong'), []);
100-
});
101-
102-
it('should return children when given a `test` and existing', function () {
103-
var res = children.slice(4).reverse();
104-
105-
assert.deepEqual(findAllBefore(paragraph, 100, test), res);
106-
assert.deepEqual(findAllBefore(paragraph, 3, test), []);
107-
assert.deepEqual(findAllBefore(paragraph, children[4], test), []);
108-
assert.deepEqual(findAllBefore(paragraph, children[3], test), []);
109-
110-
function test(node, n) {
111-
return n > 3;
112-
}
113-
});
12+
test('unist-util-find-all-before', function (t) {
13+
t.throws(
14+
function () {
15+
findAllBefore();
16+
},
17+
/Expected parent node/,
18+
'should fail without parent'
19+
);
20+
21+
t.throws(
22+
function () {
23+
findAllBefore({type: 'foo'});
24+
},
25+
/Expected parent node/,
26+
'should fail without parent node'
27+
);
28+
29+
t.doesNotThrow(
30+
function () {
31+
assert.throws(
32+
function () {
33+
findAllBefore({type: 'foo', children: []});
34+
},
35+
/Expected positive finite index or child node/
36+
);
37+
38+
assert.throws(
39+
function () {
40+
findAllBefore({type: 'foo', children: []}, -1);
41+
},
42+
/Expected positive finite index or child node/
43+
);
44+
45+
assert.throws(
46+
function () {
47+
findAllBefore({type: 'foo', children: []}, {type: 'bar'});
48+
},
49+
/Expected positive finite index or child node/
50+
);
51+
},
52+
'should fail without index'
53+
);
54+
55+
t.doesNotThrow(
56+
function () {
57+
assert.throws(
58+
function () {
59+
findAllBefore({type: 'foo', children: [{type: 'bar'}]}, 1, false);
60+
},
61+
/Expected function, string, or node as test/
62+
);
63+
64+
assert.throws(
65+
function () {
66+
findAllBefore({
67+
type: 'foo',
68+
children: [{type: 'bar'}]
69+
}, 1, true);
70+
},
71+
/Expected function, string, or node as test/
72+
);
73+
},
74+
'should fail for invalid `test`'
75+
);
76+
77+
t.doesNotThrow(
78+
function () {
79+
var res = [children[0]];
80+
81+
assert.deepEqual(findAllBefore(paragraph, children[1]), res);
82+
assert.deepEqual(findAllBefore(paragraph, 1), res);
83+
assert.deepEqual(findAllBefore(paragraph, 0), []);
84+
},
85+
'should return the preceding nodes when without `test`'
86+
);
87+
88+
t.doesNotThrow(
89+
function () {
90+
var res = [children[0]];
91+
92+
assert.deepEqual(findAllBefore(paragraph, 100, children[0]), res);
93+
assert.deepEqual(findAllBefore(paragraph, children[1], children[0]), res);
94+
assert.deepEqual(findAllBefore(paragraph, 1, children[0]), res);
95+
assert.deepEqual(findAllBefore(paragraph, children[0], children[0]), []);
96+
assert.deepEqual(findAllBefore(paragraph, 0, children[0]), []);
97+
assert.deepEqual(findAllBefore(paragraph, 1, children[1]), []);
98+
},
99+
'should return `[node]` when given a `node` and existing'
100+
);
101+
102+
t.doesNotThrow(
103+
function () {
104+
var result = [children[3]];
105+
106+
assert.deepEqual(findAllBefore(paragraph, 100, 'strong'), result);
107+
assert.deepEqual(findAllBefore(paragraph, 3, 'strong'), []);
108+
assert.deepEqual(findAllBefore(paragraph, children[4], 'strong'), result);
109+
assert.deepEqual(findAllBefore(paragraph, children[3], 'strong'), []);
110+
},
111+
'should return children when given a `type` and existing'
112+
);
113+
114+
t.doesNotThrow(
115+
function () {
116+
var res = children.slice(4).reverse();
117+
118+
assert.deepEqual(findAllBefore(paragraph, 100, test), res);
119+
assert.deepEqual(findAllBefore(paragraph, 3, test), []);
120+
assert.deepEqual(findAllBefore(paragraph, children[4], test), []);
121+
assert.deepEqual(findAllBefore(paragraph, children[3], test), []);
122+
123+
function test(node, n) {
124+
return n > 3;
125+
}
126+
},
127+
'should return children when given a `test` and existing'
128+
);
129+
130+
t.end();
114131
});

0 commit comments

Comments
 (0)