mirror of https://github.com/n2geoff/testit.git
convert to rollup build system
This commit is contained in:
parent
1a388656f2
commit
ec4e087e90
20
gulpfile.js
20
gulpfile.js
|
@ -1,9 +1,25 @@
|
|||
const gulp = require("gulp");
|
||||
const gulp = require("gulp");
|
||||
const minify = require("gulp-minify");
|
||||
const strip = require("gulp-strip-comments");
|
||||
const strip = require("gulp-strip-comments");
|
||||
const rollup = require("gulp-rollup-2").rollup;
|
||||
|
||||
gulp.task("default", function build() {
|
||||
return gulp.src("./src/testit.js")
|
||||
.pipe(rollup({
|
||||
input: "./src/testit.js",
|
||||
output: [
|
||||
{
|
||||
file: "testit.js",
|
||||
name: "es",
|
||||
format: "es"
|
||||
},
|
||||
{
|
||||
file: "testit.umd.js",
|
||||
name: "umd",
|
||||
format: "umd"
|
||||
},
|
||||
]
|
||||
}))
|
||||
.pipe(strip({safe: true}))
|
||||
.pipe(minify({ext: {min: ".min.js"}}))
|
||||
.pipe(gulp.dest("dist"))
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "testit",
|
||||
"version": "0.8.2",
|
||||
"description": "a minimalistic testing library",
|
||||
"version": "0.9.0",
|
||||
"description": "minimalistic testing library",
|
||||
"main": "src/testit.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
@ -15,6 +15,7 @@
|
|||
"eslint": "^7.8.1",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-minify": "^3.1.0",
|
||||
"gulp-rollup-2": "^1.1.0",
|
||||
"gulp-strip-comments": "^2.5.2"
|
||||
},
|
||||
"repository": {
|
||||
|
|
177
src/testit.js
177
src/testit.js
|
@ -1,105 +1,94 @@
|
|||
/*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */
|
||||
;(function (root, factory) {
|
||||
"use strict";
|
||||
// support browser & commonjs
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = factory(root.test);
|
||||
} else {
|
||||
root.test = factory(root.test);
|
||||
}
|
||||
}(this, function () {
|
||||
"use strict";
|
||||
/*! Test.it v 0.9.0 | MIT | https://github.com/n2geoff/testit */
|
||||
const test = {
|
||||
"log": console.log,
|
||||
"_tests": {},
|
||||
"run": function run(errors, next) {
|
||||
// TODO: rewrite to allow a show errors flag (optional)
|
||||
if(typeof errors !== "boolean") {
|
||||
next = errors;
|
||||
errors = true;
|
||||
}
|
||||
|
||||
const test = {
|
||||
"_tests": {},
|
||||
"run": function run(errors, next) {
|
||||
// TODO: rewrite to allow a show errors flag (optional)
|
||||
if(typeof errors !== "boolean") {
|
||||
next = errors;
|
||||
errors = true;
|
||||
}
|
||||
let tests = this._tests || [];
|
||||
// capture results
|
||||
let failed = [];
|
||||
let passed = [];
|
||||
|
||||
let tests = this._tests;
|
||||
// capture results
|
||||
let failed = [];
|
||||
let passed = [];
|
||||
// loop through tests
|
||||
Object.keys(tests).forEach((name) => {
|
||||
let test = tests[name];
|
||||
|
||||
// loop through tests
|
||||
Object.keys(tests).forEach((name) => {
|
||||
let test = tests[name];
|
||||
|
||||
// execute
|
||||
try {
|
||||
test();
|
||||
passed.push(`\n+OK ${name}`);
|
||||
} catch (err) {
|
||||
if (errors) {
|
||||
failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`);
|
||||
} else {
|
||||
failed.push(`\n-ERR ${name}`);
|
||||
}
|
||||
// execute
|
||||
try {
|
||||
test();
|
||||
passed.push(`\n+OK ${name}`);
|
||||
} catch (err) {
|
||||
if (errors) {
|
||||
failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`);
|
||||
} else {
|
||||
failed.push(`\n-ERR ${name}`);
|
||||
}
|
||||
});
|
||||
|
||||
// summary
|
||||
if(typeof next === "function") {
|
||||
return next({
|
||||
pass: passed,
|
||||
fail: failed
|
||||
});
|
||||
} else {
|
||||
console.log(...passed, ...failed);
|
||||
console.log(`\n# tests ${failed.length + passed.length} pass ${passed.length} fail ${failed.length}`);
|
||||
|
||||
return failed.length ? false : true;
|
||||
}
|
||||
},
|
||||
"it": function it(tests) {
|
||||
this._tests = tests;
|
||||
return this;
|
||||
},
|
||||
"expects": function expects(val) {
|
||||
return {
|
||||
"to": {
|
||||
"be": {
|
||||
"a": (type) => { return test.expects(val).to.be.an(type); },
|
||||
"an": (type) => {
|
||||
});
|
||||
|
||||
if(['array'].indexOf(type) !== -1) {
|
||||
if(val.constructor.name.toLowerCase() !== 'array') {
|
||||
throw new Error(`expected ${typeof val} to be an ${type}`);
|
||||
}
|
||||
// summary
|
||||
if(typeof next === "function") {
|
||||
return next({
|
||||
pass: passed,
|
||||
fail: failed
|
||||
});
|
||||
} else {
|
||||
test.log(...passed, ...failed);
|
||||
test.log(`\n# tests ${failed.length + passed.length} pass ${passed.length} fail ${failed.length}`);
|
||||
|
||||
return true;
|
||||
}
|
||||
return failed.length ? false : true;
|
||||
}
|
||||
},
|
||||
"it": function it(tests) {
|
||||
this._tests = tests;
|
||||
return this;
|
||||
},
|
||||
"expects": function expects(val) {
|
||||
return {
|
||||
"to": {
|
||||
"be": {
|
||||
"a": (type) => { return test.expects(val).to.be.an(type); },
|
||||
"an": (type) => {
|
||||
|
||||
if(typeof val !== type) {
|
||||
if(["array"].indexOf(type) !== -1) {
|
||||
if(val.constructor.name.toLowerCase() !== "array") {
|
||||
throw new Error(`expected ${typeof val} to be an ${type}`);
|
||||
}
|
||||
},
|
||||
"ok": () => { return test.expects(val).to.exist(); },
|
||||
"like": (comp) => {
|
||||
if(val != comp) {
|
||||
throw new Error(`expected ${val} == ${comp}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
"equal": (comp) => {
|
||||
if(val !== comp) {
|
||||
throw new Error(`expected ${val} === ${comp}`);
|
||||
}
|
||||
},
|
||||
"exist": () => {
|
||||
if(!val) {
|
||||
throw new Error(`expected ${val} to be truthy`);
|
||||
}
|
||||
},
|
||||
"pass": () => { return true; },
|
||||
"fail": (msg) => { throw new Error(msg); }
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
return test;
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(typeof val !== type) {
|
||||
throw new Error(`expected ${typeof val} to be an ${type}`);
|
||||
}
|
||||
},
|
||||
"ok": () => { return test.expects(val).to.exist(); },
|
||||
"like": (comp) => {
|
||||
if(val != comp) {
|
||||
throw new Error(`expected ${val} == ${comp}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
"equal": (comp) => {
|
||||
if(val !== comp) {
|
||||
throw new Error(`expected ${val} === ${comp}`);
|
||||
}
|
||||
},
|
||||
"exist": () => {
|
||||
if(!val) {
|
||||
throw new Error(`expected ${val} to be truthy`);
|
||||
}
|
||||
},
|
||||
"pass": () => { return true; },
|
||||
"fail": (msg) => { throw new Error(msg); }
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default test;
|
||||
|
|
Loading…
Reference in New Issue