Skip to content

Commit c022ade

Browse files
committed
Refactor to replace mocha with tape
1 parent 34300e3 commit c022ade

File tree

2 files changed

+111
-86
lines changed

2 files changed

+111
-86
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"name": "mdast-util-heading-style",
33
"version": "1.0.0",
44
"description": "Utility to get the style of an mdast heading",
@@ -35,11 +35,11 @@
3535
"remark-lint": "^2.0.0",
3636
"remark-slug": "^3.0.0",
3737
"remark-validate-links": "^2.0.0",
38-
"mocha": "^2.0.0"
38+
"tape": "^4.4.0"
3939
},
4040
"scripts": {
41-
"test-api": "mocha --check-leaks test.js",
42-
"test-coverage": "istanbul cover _mocha -- test.js",
41+
"test-api": "node test.js",
42+
"test-coverage": "istanbul cover test.js",
4343
"test-travis": "npm run test-coverage",
4444
"test": "npm run test-api",
4545
"lint-api": "eslint .",

test.js

Lines changed: 107 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,130 @@
11
'use strict';
22

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

55
/*
66
* Dependencies.
77
*/
88

9-
var style = require('./index.js');
9+
var test = require('tape');
1010
var remark = require('remark');
11-
var assert = require('assert');
12-
13-
/*
14-
* Methods.
15-
*/
16-
17-
var throws = assert.throws;
18-
var equal = assert.strictEqual;
11+
var style = require('./index.js');
1912

2013
/*
2114
* Tests.
2215
*/
2316

24-
describe('mdast-util-heading-style', function () {
25-
it('should fail without node', function () {
26-
throws(function () {
17+
test('mdast-util-heading-style', function (t) {
18+
t.throws(
19+
function () {
2720
style();
28-
});
29-
});
21+
},
22+
'should fail without node'
23+
);
3024

31-
it('should NOT fail on undetectable nodes', function () {
32-
equal(null, style({
25+
t.equal(
26+
style({
3327
'type': 'heading',
3428
'children': [
3529
{
3630
'type': 'text',
3731
'value': 'foo'
3832
}
3933
]
40-
}));
41-
});
42-
43-
it('should work', function () {
44-
equal(style(remark.parse('# ATX').children[0]), 'atx');
45-
46-
equal(style(remark.parse('# ATX #').children[0]), 'atx-closed');
47-
48-
equal(style(remark.parse('ATX\n===').children[0]), 'setext');
49-
});
50-
51-
it('should work on ambiguous nodes', function () {
52-
equal(style(remark.parse('### ATX').children[0]), null);
53-
54-
equal(style(remark.parse('### ATX').children[0], 'atx'), 'atx');
55-
56-
equal(style(remark.parse('### ATX').children[0], 'setext'), 'setext');
57-
});
58-
59-
it('should work on empty nodes', function () {
60-
equal(
61-
style(remark.parse('###### ######').children[0]),
62-
'atx-closed'
63-
);
64-
65-
equal(
66-
style(remark.parse('### ###').children[0]),
67-
'atx-closed'
68-
);
69-
70-
equal(
71-
style(remark.parse('# #').children[0]),
72-
'atx-closed'
73-
);
74-
75-
equal(
76-
style(remark.parse('###### ').children[0], 'atx'),
77-
'atx'
78-
);
79-
80-
equal(
81-
style(remark.parse('### ').children[0], 'atx'),
82-
'atx'
83-
);
84-
85-
equal(
86-
style(remark.parse('# ').children[0], 'setext'),
87-
'atx'
88-
);
89-
90-
equal(
91-
style(remark.parse('###### ').children[0], 'setext'),
92-
'setext'
93-
);
94-
95-
equal(
96-
style(remark.parse('### ').children[0], 'setext'),
97-
'setext'
98-
);
99-
100-
equal(
101-
style(remark.parse('# ').children[0], 'setext'),
102-
'atx'
103-
);
104-
});
34+
}),
35+
null,
36+
'should NOT fail on undetectable nodes'
37+
);
38+
39+
t.equal(
40+
style(remark.parse('# ATX').children[0]),
41+
'atx',
42+
'should detect atx'
43+
);
44+
45+
t.equal(
46+
style(remark.parse('# ATX #').children[0]),
47+
'atx-closed',
48+
'should detect closed atx'
49+
);
50+
51+
t.equal(
52+
style(remark.parse('ATX\n===').children[0]),
53+
'setext',
54+
'should detect closed setext'
55+
);
56+
57+
t.equal(
58+
style(remark.parse('### ATX').children[0]),
59+
null,
60+
'should work on ambiguous nodes'
61+
);
62+
63+
t.equal(
64+
style(remark.parse('### ATX').children[0], 'atx'),
65+
'atx',
66+
'should work on ambiguous nodes (preference to atx)'
67+
);
68+
69+
t.equal(
70+
style(remark.parse('### ATX').children[0], 'setext'),
71+
'setext',
72+
'should work on ambiguous nodes (preference to setext)'
73+
);
74+
75+
t.equal(
76+
style(remark.parse('###### ######').children[0]),
77+
'atx-closed',
78+
'should work on empty nodes (#1)'
79+
);
80+
81+
t.equal(
82+
style(remark.parse('### ###').children[0]),
83+
'atx-closed',
84+
'should work on empty nodes (#2)'
85+
);
86+
87+
t.equal(
88+
style(remark.parse('# #').children[0]),
89+
'atx-closed',
90+
'should work on empty nodes (#3)'
91+
);
92+
93+
t.equal(
94+
style(remark.parse('###### ').children[0], 'atx'),
95+
'atx',
96+
'should work on empty nodes (#4)'
97+
);
98+
99+
t.equal(
100+
style(remark.parse('### ').children[0], 'atx'),
101+
'atx',
102+
'should work on empty nodes (#5)'
103+
);
104+
105+
t.equal(
106+
style(remark.parse('## ').children[0]),
107+
'atx',
108+
'should work on empty nodes (#6)'
109+
);
110+
111+
t.equal(
112+
style(remark.parse('###### ').children[0], 'setext'),
113+
'setext',
114+
'should work on empty nodes (#7)'
115+
);
116+
117+
t.equal(
118+
style(remark.parse('### ').children[0], 'setext'),
119+
'setext',
120+
'should work on empty nodes (#8)'
121+
);
122+
123+
t.equal(
124+
style(remark.parse('## ').children[0], 'setext'),
125+
'atx',
126+
'should work on empty nodes (#9)'
127+
);
128+
129+
t.end();
105130
});

0 commit comments

Comments
 (0)