Skip to content

Commit

Permalink
Replace mocha with tape, istanbul with nyc
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 21, 2016
1 parent bb6e412 commit 041314d
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 104 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.DS_Store
*.log
bower_components/
build/
components/
.nyc_output/
coverage/
node_modules/
build.js
unist-util-find-before.js
unist-util-find-before.min.js
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,31 @@
"devDependencies": {
"browserify": "^11.0.0",
"esmangle": "^1.0.0",
"istanbul": "^0.3.0",
"mdast": "^1.0.0",
"mdast-comment-config": "^1.0.0",
"mdast-github": "^1.0.0",
"mdast-lint": "^1.0.0",
"mdast-slug": "^1.0.0",
"mdast-validate-links": "^1.0.0",
"mocha": "^2.0.0",
"nyc": "^9.0.1",
"tape": "^4.6.2",
"xo": "^0.17.1"
},
"scripts": {
"test-api": "mocha --check-leaks test.js",
"test-coverage": "istanbul cover _mocha -- test.js",
"test-travis": "npm run test-coverage",
"test": "npm run test-api",
"lint": "xo",
"make": "npm run lint && npm run test-coverage",
"bundle": "browserify index.js --no-builtins -s unistUtilFindBefore > unist-util-find-before.js",
"postbundle": "esmangle unist-util-find-before.js > unist-util-find-before.min.js",
"build-md": "mdast . --quiet",
"build": "npm run bundle && npm run build-md"
"build-bundle": "browserify index.js --no-builtins -s unistUtilFindBefore > unist-util-find-before.js",
"build-mangle": "esmangle unist-util-find-before.js > unist-util-find-before.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"xo": {
"space": true,
Expand Down
195 changes: 106 additions & 89 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,111 +1,128 @@
'use strict';

/* eslint-env mocha */

var assert = require('assert');
var test = require('tape');
var mdast = require('mdast');
var findBefore = require('./');

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

describe('unist-util-find-before', function () {
it('should fail without parent', function () {
assert.throws(
function () {
findBefore();
},
/Expected parent node/
);
});
test('unist-util-find-before', function (t) {
t.throws(
function () {
findBefore();
},
/Expected parent node/,
'should fail without parent'
);

t.throws(
function () {
findBefore({
type: 'foo'
});
},
/Expected parent node/,
'should fail without parent node'
);

it('should fail without parent node', function () {
assert.throws(
function () {
findBefore({
type: 'foo'
});
},
/Expected parent node/
);
});
t.doesNotThrow(
function () {
assert.throws(
function () {
findBefore({type: 'foo', children: []});
},
/Expected positive finite index or child node/
);

it('should fail without index', function () {
assert.throws(
function () {
findBefore({type: 'foo', children: []});
},
/Expected positive finite index or child node/
);
assert.throws(
function () {
findBefore({type: 'foo', children: []}, -1);
},
/Expected positive finite index or child node/
);

assert.throws(
function () {
findBefore({type: 'foo', children: []}, -1);
},
/Expected positive finite index or child node/
);
assert.throws(
function () {
findBefore({type: 'foo', children: []}, {type: 'bar'});
},
/Expected positive finite index or child node/
);
},
'should fail without index'
);

assert.throws(
function () {
findBefore({type: 'foo', children: []}, {type: 'bar'});
},
/Expected positive finite index or child node/
);
});
t.doesNotThrow(
function () {
assert.throws(
function () {
findBefore({
type: 'foo',
children: [{type: 'bar'}]
}, 1, false);
},
/Expected function, string, or node as test/
);

it('should fail for invalid `test`', function () {
assert.throws(
function () {
findBefore({
type: 'foo',
children: [{type: 'bar'}]
}, 1, false);
},
/Expected function, string, or node as test/
);
assert.throws(
function () {
findBefore({
type: 'foo',
children: [{type: 'bar'}]
}, 1, true);
},
/Expected function, string, or node as test/
);
},
'should fail for invalid `test`'
);

assert.throws(
function () {
findBefore({
type: 'foo',
children: [{type: 'bar'}]
}, 1, true);
},
/Expected function, string, or node as test/
);
});
t.doesNotThrow(
function () {
assert.strictEqual(findBefore(paragraph, children[1]), children[0]);
assert.strictEqual(findBefore(paragraph, 1), children[0]);
assert.strictEqual(findBefore(paragraph, 0), null);
},
'should return the preceding node when without `test`'
);

it('should return the preceding node when without `test`', function () {
assert.strictEqual(findBefore(paragraph, children[1]), children[0]);
assert.strictEqual(findBefore(paragraph, 1), children[0]);
assert.strictEqual(findBefore(paragraph, 0), null);
});
t.doesNotThrow(
function () {
assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]);
assert.strictEqual(findBefore(paragraph, children[1], children[0]), children[0]);
assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]);
assert.strictEqual(findBefore(paragraph, children[0], children[0]), null);
assert.strictEqual(findBefore(paragraph, 0, children[0]), null);
assert.strictEqual(findBefore(paragraph, 1, children[1]), null);
},
'should return `node` when given a `node` and existing'
);

it('should return `node` when given a `node` and existing', function () {
assert.strictEqual(findBefore(paragraph, 100, children[0]), children[0]);
assert.strictEqual(findBefore(paragraph, children[1], children[0]), children[0]);
assert.strictEqual(findBefore(paragraph, 1, children[0]), children[0]);
assert.strictEqual(findBefore(paragraph, children[0], children[0]), null);
assert.strictEqual(findBefore(paragraph, 0, children[0]), null);
assert.strictEqual(findBefore(paragraph, 1, children[1]), null);
});
t.doesNotThrow(
function () {
assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]);
assert.strictEqual(findBefore(paragraph, 3, 'strong'), null);
assert.strictEqual(findBefore(paragraph, children[4], 'strong'), children[3]);
assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null);
},
'should return a child when given a `type` and existing'
);

it('should return a child when given a `type` and existing', function () {
assert.strictEqual(findBefore(paragraph, 100, 'strong'), children[3]);
assert.strictEqual(findBefore(paragraph, 3, 'strong'), null);
assert.strictEqual(findBefore(paragraph, children[4], 'strong'), children[3]);
assert.strictEqual(findBefore(paragraph, children[3], 'strong'), null);
});
t.doesNotThrow(
function () {
assert.strictEqual(findBefore(paragraph, 100, test), children[3]);
assert.strictEqual(findBefore(paragraph, 3, test), null);
assert.strictEqual(findBefore(paragraph, children[4], test), children[3]);
assert.strictEqual(findBefore(paragraph, children[3], test), null);

it('should return a child when given a `test` and existing', function () {
assert.strictEqual(findBefore(paragraph, 100, test), children[3]);
assert.strictEqual(findBefore(paragraph, 3, test), null);
assert.strictEqual(findBefore(paragraph, children[4], test), children[3]);
assert.strictEqual(findBefore(paragraph, children[3], test), null);
function test(node, n) {
return n === 3;
}
},
'should return a child when given a `test` and existing'
);

function test(node, n) {
return n === 3;
}
});
t.end();
});

0 comments on commit 041314d

Please sign in to comment.