From 041314dd697ca234d50087012cd47e568bff589a Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 21 Nov 2016 17:42:42 +0100 Subject: [PATCH] Replace mocha with tape, istanbul with nyc --- .gitignore | 7 +- package.json | 26 ++++--- test.js | 195 ++++++++++++++++++++++++++++----------------------- 3 files changed, 124 insertions(+), 104 deletions(-) diff --git a/.gitignore b/.gitignore index f41859a..d0fb912 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/package.json b/package.json index 60ce4f9..66f2a40 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/test.js b/test.js index 70c17c4..210bdcd 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,7 @@ 'use strict'; -/* eslint-env mocha */ - var assert = require('assert'); +var test = require('tape'); var mdast = require('mdast'); var findBefore = require('./'); @@ -10,102 +9,120 @@ 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(); });