changed how testit is self tested

This commit is contained in:
Geoff Doty 2020-09-08 17:37:24 -05:00
parent ec4e087e90
commit 85a491ce98
5 changed files with 65 additions and 48 deletions

View File

@ -7,9 +7,9 @@
"test": "test"
},
"scripts": {
"build": "node_modules/.bin/gulp",
"lint": "node_modules/.bin/eslint src/testit.js",
"test": "node test/run.js"
"build": "npx gulp default",
"lint": "npx eslint src/testit.js",
"test": "npm run build && npm run lint && node test/run.js"
},
"devDependencies": {
"eslint": "^7.8.1",

View File

@ -1,6 +1,6 @@
/*! Test.it v 0.9.0 | MIT | https://github.com/n2geoff/testit */
const test = {
"log": console.log,
"log": console.log, // eslint-disable-line
"_tests": {},
"run": function run(errors, next) {
// TODO: rewrite to allow a show errors flag (optional)

View File

@ -1,6 +1,12 @@
var test = test || require("../src/testit");
function spec(test) {
// npm run test
if(!test) {
try {
var test = require("../dist/testit.umd.js");
} catch(e) {};
}
test.it({
return {
"'like' should do truthy evaluation via ==": function() {
test.expects(1).to.be.like('1');
test.expects("1").to.be.like(1);
@ -33,4 +39,5 @@ test.it({
test.expects(false).to.be.a('boolean');
test.expects(undefined).to.be.a('undefined');
}
});
};
}

View File

@ -5,20 +5,29 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Test It Spec</title>
<script src="../src/testit.js"></script>
<script src="./index.spec.js"></script>
<script src="index.spec.js"></script>
<style>
#summary {font-size: 2rem; text-transform: uppercase;}
</style>
</head>
<body>
<script>
test.run(false, function(r) {
<div id="summary"></div>
<div id="errors"></div>
<script type="module">
import test from "../src/testit.js";
test.it(spec(test)).run(false, function(r) {
let errors = [];
document.body.style.backgroundColor = (
r.fail.length ? "#ff9999" : "#99ff99"
);
r.pass.forEach((p) => document.write(`<br>${p}`));
r.fail.forEach((f) => document.write(`<br><b>${f}</b>`));
r.pass.forEach((p) => errors.push(`<br>${p}`));
r.fail.forEach((f) => errors.push(`<br><b>${f}</b>`));
document.write(`<p>tests ${r.pass.length + r.fail.length} pass ${r.pass.length} fail ${r.fail.length}`);
document.querySelector('#errors').innerHTML = errors;
document.querySelector('#summary').innerHTML = `tests: ${r.pass.length + r.fail.length} pass: ${r.pass.length} fail: ${r.fail.length}`;
});
</script>
</body>

View File

@ -1,5 +1,6 @@
var path = require("path");
var fs = require("fs");
var test = require("../dist/testit.umd.js");
fs.readdir(__dirname, function(err, files) {
if(err) {
@ -16,9 +17,9 @@ fs.readdir(__dirname, function(err, files) {
var me = fs.readFileSync(path.join(__dirname, file));
// eval maybe evil, but it is YOUR code, are you evil?
eval(me.toString()); // jshint ignore:line
// eval can be evil, but it is YOUR code, are you evil?
eval(me.toString());
test.run();
test.it(spec()).run();
});
});