convert to rollup build system

This commit is contained in:
Geoff Doty 2020-09-08 17:29:56 -05:00
parent 1a388656f2
commit ec4e087e90
4 changed files with 958 additions and 235 deletions

View File

@ -1,10 +1,26 @@
const gulp = require("gulp"); const gulp = require("gulp");
const minify = require("gulp-minify"); 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() { gulp.task("default", function build() {
return gulp.src("./src/testit.js") 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(strip({safe: true}))
.pipe(minify({ext: {min: ".min.js"}})) .pipe(minify({ext: {min: ".min.js"}}))
.pipe(gulp.dest("dist")) .pipe(gulp.dest("dist"))
}); });

989
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
{ {
"name": "testit", "name": "testit",
"version": "0.8.2", "version": "0.9.0",
"description": "a minimalistic testing library", "description": "minimalistic testing library",
"main": "src/testit.js", "main": "src/testit.js",
"directories": { "directories": {
"test": "test" "test": "test"
@ -15,6 +15,7 @@
"eslint": "^7.8.1", "eslint": "^7.8.1",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-minify": "^3.1.0", "gulp-minify": "^3.1.0",
"gulp-rollup-2": "^1.1.0",
"gulp-strip-comments": "^2.5.2" "gulp-strip-comments": "^2.5.2"
}, },
"repository": { "repository": {

View File

@ -1,105 +1,94 @@
/*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */ /*! Test.it v 0.9.0 | MIT | https://github.com/n2geoff/testit */
;(function (root, factory) { const test = {
"use strict"; "log": console.log,
// support browser & commonjs "_tests": {},
if (typeof module === "object" && module.exports) { "run": function run(errors, next) {
module.exports = factory(root.test); // TODO: rewrite to allow a show errors flag (optional)
} else { if(typeof errors !== "boolean") {
root.test = factory(root.test); next = errors;
} errors = true;
}(this, function () { }
"use strict";
const test = { let tests = this._tests || [];
"_tests": {}, // capture results
"run": function run(errors, next) { let failed = [];
// TODO: rewrite to allow a show errors flag (optional) let passed = [];
if(typeof errors !== "boolean") {
next = errors;
errors = true;
}
let tests = this._tests; // loop through tests
// capture results Object.keys(tests).forEach((name) => {
let failed = []; let test = tests[name];
let passed = [];
// loop through tests // execute
Object.keys(tests).forEach((name) => { try {
let test = tests[name]; test();
passed.push(`\n+OK ${name}`);
// execute } catch (err) {
try { if (errors) {
test(); failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`);
passed.push(`\n+OK ${name}`); } else {
} catch (err) { failed.push(`\n-ERR ${name}`);
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) { // summary
if(val.constructor.name.toLowerCase() !== 'array') { if(typeof next === "function") {
throw new Error(`expected ${typeof val} to be an ${type}`); 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}`); 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;