@fatso83/mini-mocha
Advanced tools
Comparing version 1.0.3 to 2.0.0
40
demo.js
@@ -1,30 +0,32 @@ | ||
require('./index'); | ||
require("./index").install(); | ||
describe("Block A", function() { | ||
var Foo = { | ||
myMethod: function() { return "original"; } | ||
var Foo = { | ||
myMethod: function() { | ||
return "original"; | ||
} | ||
}; | ||
before(() => console.log("before")); | ||
after(() => console.log("after")); | ||
beforeEach(() => console.log("before each")); | ||
afterEach(() => console.log("after each")); | ||
before(() => console.log("before")); | ||
after(() => console.log("after")); | ||
beforeEach(() => console.log("before each")); | ||
afterEach(() => console.log("after each")); | ||
it("normal sync test", function() { | ||
// no-op | ||
}); | ||
it("normal sync test", function() { | ||
// no-op | ||
}); | ||
it("failing test", function() { | ||
throw new Error("My error"); | ||
}); | ||
it("failing test", function() { | ||
throw new Error("My error"); | ||
}); | ||
it("async test (not supported)", function(done) { | ||
console.warn("should never get here"); | ||
}); | ||
it("async test (not supported)", function(done) { | ||
console.warn("should never get here"); | ||
}); | ||
}); | ||
describe("Block B", function() { | ||
it("failing test", function() { | ||
throw new Error("My error"); | ||
}); | ||
it("failing test", function() { | ||
throw new Error("My error"); | ||
}); | ||
}); |
141
index.js
@@ -1,58 +0,107 @@ | ||
var d = ""; | ||
var assert = require("assert"); | ||
var d = null; | ||
var doPrint = false; | ||
var its = []; | ||
function it(title, fn) { | ||
its.push(function() { | ||
if(fn.length) return unsupported("async/callback testing")(); | ||
var beforeEachs = []; | ||
var befores = []; | ||
var afters = []; | ||
var afterEachs = []; | ||
var printFn = console.log.bind(console); | ||
beforeEachs.forEach(run); | ||
try{ fn(); log(title, null); } | ||
catch(err){ log(title, err.message); } | ||
afterEachs.forEach(run); | ||
}); | ||
} | ||
function describe(title, fn) { | ||
d = title; | ||
fn(); | ||
befores.forEach(run) | ||
its.forEach(run) | ||
afters.forEach(run) | ||
function it(title, fn) { | ||
assert(typeof title === "string", "title required"); | ||
assert(typeof fn === "function", "missing function"); | ||
its.push(function() { | ||
if (fn.length) return unsupported("async/callback testing")(); | ||
beforeEachs.forEach(run); | ||
try { | ||
fn(); | ||
log(title, null); | ||
} catch (err) { | ||
log(title, err.message); | ||
} | ||
afterEachs.forEach(run); | ||
}); | ||
// To support running without outer describe block | ||
if (!d) { | ||
its.forEach(run); | ||
its = []; | ||
befores = []; | ||
afters = []; | ||
} | ||
} | ||
function log(title, err) { | ||
var status = err? `❌. ${err}`: "✔️"; | ||
console.log(d && `${d}: ` + `${title}: ${status}`); | ||
function describe(title, fn) { | ||
assert(title, "title required"); | ||
assert(typeof fn === "function"); | ||
d = title; | ||
fn(); | ||
befores.forEach(run); | ||
its.forEach(run); | ||
afters.forEach(run); | ||
// reset | ||
its = []; | ||
befores = []; | ||
afters = []; | ||
afterEachs = []; | ||
beforeEachs = []; | ||
d = null; | ||
} | ||
function run(fn){ fn(); } | ||
function unsupported(title) { | ||
return function(){ | ||
console.error("This operation is unsupported: " + title) | ||
} | ||
function before(fn) { | ||
befores.push(fn); | ||
} | ||
var befores = []; | ||
function before(fn){ | ||
befores.push(fn); | ||
function after(fn) { | ||
afters.push(fn); | ||
} | ||
var afters = []; | ||
function after(fn){ | ||
afters.push(fn); | ||
function beforeEach(fn) { | ||
beforeEachs.push(fn); | ||
} | ||
var beforeEachs = []; | ||
function beforeEach(fn){ | ||
beforeEachs.push(fn); | ||
function afterEach(fn) { | ||
afterEachs.push(fn); | ||
} | ||
var afterEachs = []; | ||
function afterEach(fn){ | ||
afterEachs.push(fn); | ||
function log(title, err) { | ||
var status = err ? `❌. ${err}` : "✔️"; | ||
if (doPrint) { | ||
printFn((d ? `${d}: ` : "") + `${title}: ${status}`); | ||
} | ||
} | ||
function run(fn) { | ||
fn(); | ||
} | ||
function unsupported(title) { | ||
return function() { | ||
console.error("This operation is unsupported: " + title); | ||
}; | ||
} | ||
global.describe = describe; | ||
global.it = it; | ||
global.before = before; | ||
global.after = after; | ||
//global.beforeEach = unsupported("beforeEach"); | ||
//global.afterEach = unsupported("afterEach"); | ||
global.beforeEach = beforeEach; | ||
global.afterEach = afterEach; | ||
function install() { | ||
doPrint = true; | ||
global.describe = describe; | ||
global.it = it; | ||
global.before = before; | ||
global.after = after; | ||
global.beforeEach = beforeEach; | ||
global.afterEach = afterEach; | ||
} | ||
module.exports = { | ||
describe: describe, | ||
it: it, | ||
before: before, | ||
after: after, | ||
beforeEach: beforeEach, | ||
afterEach: afterEach, | ||
install: install, | ||
setPrint: function(fn) { | ||
printFn = fn; | ||
} | ||
}; |
{ | ||
"name": "@fatso83/mini-mocha", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "A minimal emulation of Mocha", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node demo.js" | ||
"fixup": "prettier --write *.js", | ||
"test": "node index.test.js | faucet", | ||
"precommit": "prettier -c *.js && node index.test.js" | ||
}, | ||
@@ -22,3 +24,9 @@ "repository": { | ||
"url": "https://github.com/fatso83/mini-mocha/issues" | ||
}, | ||
"devDependencies": { | ||
"faucet": "0.0.1", | ||
"husky": "^1.3.1", | ||
"prettier": "^1.16.4", | ||
"tape": "^4.10.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5843
5
167
4