From 85a491ce9840762af1e5cf323886ef433248709d Mon Sep 17 00:00:00 2001 From: Geoff Doty Date: Tue, 8 Sep 2020 17:37:24 -0500 Subject: [PATCH] changed how testit is self tested --- package.json | 6 ++-- src/testit.js | 2 +- test/index.spec.js | 75 +++++++++++++++++++++++++--------------------- test/run.html | 23 +++++++++----- test/run.js | 7 +++-- 5 files changed, 65 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 26b72a0..4c05f63 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/testit.js b/src/testit.js index ce5711e..27723ff 100644 --- a/src/testit.js +++ b/src/testit.js @@ -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) diff --git a/test/index.spec.js b/test/index.spec.js index 678ba31..e5bf54e 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,36 +1,43 @@ -var test = test || require("../src/testit"); - -test.it({ - "'like' should do truthy evaluation via ==": function() { - test.expects(1).to.be.like('1'); - test.expects("1").to.be.like(1); - test.expects(1).to.be.ok(); - }, - "'equal' should do === evaluation exist": function() { - test.expects(1).to.equal(1); - test.expects('hello').to.equal('hello'); - }, - "you should be able to 'pass' a test": function() { - test.expects().to.pass(); - }, - "you should be able to fail' a test too": function() { +function spec(test) { + // npm run test + if(!test) { try { - test.expects().to.fail(); - } catch(e) { - test.expects().to.pass(); - } - }, - "you should be able to test if something 'exists'": function() { - test.expects({}).to.exist(); - test.expects({}).to.be.ok(); - test.expects({}).to.be.a('object'); - }, - "should be able to check types": function() { - test.expects(123).to.be.a('number'); - test.expects([]).to.be.an('array'); - test.expects({}).to.be.a('object'); - test.expects(true).to.be.a('boolean'); - test.expects(false).to.be.a('boolean'); - test.expects(undefined).to.be.a('undefined'); + var test = require("../dist/testit.umd.js"); + } catch(e) {}; } -}); + + return { + "'like' should do truthy evaluation via ==": function() { + test.expects(1).to.be.like('1'); + test.expects("1").to.be.like(1); + test.expects(1).to.be.ok(); + }, + "'equal' should do === evaluation exist": function() { + test.expects(1).to.equal(1); + test.expects('hello').to.equal('hello'); + }, + "you should be able to 'pass' a test": function() { + test.expects().to.pass(); + }, + "you should be able to fail' a test too": function() { + try { + test.expects().to.fail(); + } catch(e) { + test.expects().to.pass(); + } + }, + "you should be able to test if something 'exists'": function() { + test.expects({}).to.exist(); + test.expects({}).to.be.ok(); + test.expects({}).to.be.a('object'); + }, + "should be able to check types": function() { + test.expects(123).to.be.a('number'); + test.expects([]).to.be.an('array'); + test.expects({}).to.be.a('object'); + test.expects(true).to.be.a('boolean'); + test.expects(false).to.be.a('boolean'); + test.expects(undefined).to.be.a('undefined'); + } + }; +} diff --git a/test/run.html b/test/run.html index 50d4b35..fd48165 100644 --- a/test/run.html +++ b/test/run.html @@ -5,20 +5,29 @@ Test It Spec - - + + - diff --git a/test/run.js b/test/run.js index d9f3b92..149fe57 100644 --- a/test/run.js +++ b/test/run.js @@ -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(); }); });