Compare commits

..

No commits in common. "master" and "v1.1.0" have entirely different histories.

12 changed files with 425 additions and 790 deletions

34
.eslintrc.js Normal file
View File

@ -0,0 +1,34 @@
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"no-console": [
"warn"
],
"indent": [
"error",
4,
{"SwitchCase": 1}
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
}

View File

@ -33,7 +33,7 @@ The `dist` includes the minified version of the source code.
Run unit tests using this command: Run unit tests using this command:
```bash ```bash
npm run test npm test
``` ```
## Reporting a bug ## Reporting a bug

View File

@ -1,6 +1,6 @@
The MIT License The MIT License
Copyright (c) 2023 Geoff Doty Copyright (c) 2021 Geoff Doty
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View File

@ -31,10 +31,10 @@ By default, you can run your tests like
import test from 'testit'; import test from 'testit';
test.it({ test.it({
'my passing test'() { 'my passing test': function() {
test.assert(true); test.assert(true);
}, },
'my failing test'() { 'my failing test': function() {
test.assert(true === false, 'just wanted to fail fast'); test.assert(true === false, 'just wanted to fail fast');
} }
}).run(); }).run();
@ -68,10 +68,10 @@ For Example...
```js ```js
test.it({ test.it({
'my passing test'() { 'my passing test': function() {
test.assert(true); test.assert(true);
} }
}, (results) => { }, function(results) {
if (window.document && document.body) { if (window.document && document.body) {
document.body.style.backgroundColor = ( document.body.style.backgroundColor = (
results.fail.length ? '#ff9999' : '#99ff99' results.fail.length ? '#ff9999' : '#99ff99'
@ -112,7 +112,7 @@ putting that above your tests will allow you to write like
```js ```js
test.it({ test.it({
"my test should work"() { "my test should work": function() {
assert(true); assert(true);
} }
}); });

12
dist/testit.min.js vendored
View File

@ -1,9 +1,9 @@
/*! Test.it v1.2.0 | MIT | https://github.com/n2geoff/testit */const o={log:console.log,version:"v1.2.0",_tests:{},run(t,s){typeof t!="boolean"&&(s=t,t=!0);let r=this._tests||[],e=[],l=[];return Object.keys(r).forEach(n=>{let h=r[n];try{h(),l.push(` /*! Test.it v1.0.0 | MIT | https://github.com/n2geoff/testit */const i={log:console.log,version:"v1.0.0",_tests:{},run:function(t,n){typeof t!="boolean"&&(n=t,t=!0);let r=this._tests||[],e=[],s=[];return Object.keys(r).forEach(l=>{let h=r[l];try{h(),s.push(`
+OK ${n}`)}catch(i){t?e.push(` +OK ${l}`)}catch(f){t?e.push(`
-ERR ${n} -ERR ${l}
--- ---
${i.stack} ${f.stack}
---`):e.push(` ---`):e.push(`
-ERR ${n}`)}}),typeof s=="function"?s({pass:l,fail:e}):(o.log(...l,...e),o.log(` -ERR ${l}`)}}),typeof n=="function"?n({pass:s,fail:e}):(i.log(...s,...e),i.log(`
# tests ${e.length+l.length} pass ${l.length} fail ${e.length}`),!e.length)},it(t){return this._tests=t,this},assert(t,s){try{if(!t)throw new Error(s||"Assertion Failed")}catch{throw new Error(s)}}};var f=o;export{f as default,o as test}; # tests ${e.length+s.length} pass ${s.length} fail ${e.length}`),!e.length)},it:function(t){return this._tests=t,this},assert:(o,t)=>{try{if(!o)throw new Error(t||"Assertion Failed")}catch(n){throw new Error(t)}}};var u=i;export{u as default};
//# sourceMappingURL=testit.min.js.map //# sourceMappingURL=testit.min.js.map

View File

@ -1,7 +1,7 @@
{ {
"version": 3, "version": 3,
"sources": ["../src/testit.js"], "sources": ["../src/testit.js"],
"sourcesContent": ["/*! Test.it v1.2.0 | MIT | https://github.com/n2geoff/testit */\nexport const test = {\n log: console.log,\n version: \"v1.2.0\",\n _tests: {},\n run(errors, next) {\n // TODO: rewrite to allow show errors flag (optional)\n if(typeof errors !== \"boolean\") {\n next = errors;\n errors = true;\n }\n\n let tests = this._tests || [];\n // capture results\n let failed = [];\n let passed = [];\n\n // loop through tests\n Object.keys(tests).forEach((name) => {\n let test = tests[name];\n\n // execute\n try {\n test();\n passed.push(`\\n+OK ${name}`);\n } catch (err) {\n if (errors) {\n failed.push(`\\n-ERR ${name} \\n --- \\n ${err.stack} \\n ---`);\n } else {\n failed.push(`\\n-ERR ${name}`);\n }\n }\n });\n\n // summary\n if(typeof next === \"function\") {\n return next({\n pass: passed,\n fail: failed\n });\n } else {\n test.log(...passed, ...failed);\n test.log(`\\n# tests ${failed.length + passed.length} pass ${passed.length} fail ${failed.length}`);\n\n return failed.length ? false : true;\n }\n },\n it(tests) {\n this._tests = tests;\n return this;\n },\n assert(expression, msg) {\n try {\n if(!expression) {\n throw new Error(msg || \"Assertion Failed\");\n }\n } catch {\n throw new Error(msg);\n }\n }\n};\n\nexport default test;\n"], "sourcesContent": ["/*! Test.it v1.0.0 | MIT | https://github.com/n2geoff/testit */\r\nconst test = {\r\n \"log\": console.log, // eslint-disable-line\r\n \"version\": \"v1.0.0\",\r\n \"_tests\": {},\r\n \"run\": function run(errors, next) {\r\n // TODO: rewrite to allow a show errors flag (optional)\r\n if(typeof errors !== \"boolean\") {\r\n next = errors;\r\n errors = true;\r\n }\r\n\r\n let tests = this._tests || [];\r\n // capture results\r\n let failed = [];\r\n let passed = [];\r\n\r\n // loop through tests\r\n Object.keys(tests).forEach((name) => {\r\n let test = tests[name];\r\n\r\n // execute\r\n try {\r\n test();\r\n passed.push(`\\n+OK ${name}`);\r\n } catch (err) {\r\n if (errors) {\r\n failed.push(`\\n-ERR ${name} \\n --- \\n ${err.stack} \\n ---`);\r\n } else {\r\n failed.push(`\\n-ERR ${name}`);\r\n }\r\n }\r\n });\r\n\r\n // summary\r\n if(typeof next === \"function\") {\r\n return next({\r\n pass: passed,\r\n fail: failed\r\n });\r\n } else {\r\n test.log(...passed, ...failed);\r\n test.log(`\\n# tests ${failed.length + passed.length} pass ${passed.length} fail ${failed.length}`);\r\n\r\n return failed.length ? false : true;\r\n }\r\n },\r\n \"it\": function it(tests) {\r\n this._tests = tests;\r\n return this;\r\n },\r\n \"assert\": (expression, msg) => {\r\n try {\r\n if(!expression) {\r\n throw new Error(msg || \"Assertion Failed\");\r\n }\r\n } catch (e) {\r\n throw new Error(msg);\r\n }\r\n }\r\n};\r\n\r\nexport default test;\r\n"],
"mappings": "AAAA,+DACO,MAAMA,EAAO,CAChB,IAAK,QAAQ,IACb,QAAS,SACT,OAAQ,CAAC,EACT,IAAIC,EAAQC,EAAM,CAEX,OAAOD,GAAW,YACjBC,EAAOD,EACPA,EAAS,IAGb,IAAIE,EAAQ,KAAK,QAAU,CAAC,EAExBC,EAAS,CAAC,EACVC,EAAS,CAAC,EAoBd,OAjBA,OAAO,KAAKF,CAAK,EAAE,QAASG,GAAS,CACjC,IAAIN,EAAOG,EAAMG,CAAI,EAGrB,GAAI,CACAN,EAAK,EACLK,EAAO,KAAK;AAAA,MAASC,CAAI,EAAE,CAC/B,OAASC,EAAK,CACNN,EACAG,EAAO,KAAK;AAAA,OAAUE,CAAI;AAAA;AAAA,GAAcC,EAAI,KAAK;AAAA,KAAS,EAE1DH,EAAO,KAAK;AAAA,OAAUE,CAAI,EAAE,CAEpC,CACJ,CAAC,EAGE,OAAOJ,GAAS,WACRA,EAAK,CACR,KAAMG,EACN,KAAMD,CACV,CAAC,GAEDJ,EAAK,IAAI,GAAGK,EAAQ,GAAGD,CAAM,EAC7BJ,EAAK,IAAI;AAAA,UAAaI,EAAO,OAASC,EAAO,MAAM,SAASA,EAAO,MAAM,SAASD,EAAO,MAAM,EAAE,EAE1F,CAAAA,EAAO,OAEtB,EACA,GAAGD,EAAO,CACN,YAAK,OAASA,EACP,IACX,EACA,OAAOK,EAAYC,EAAK,CACpB,GAAI,CACA,GAAG,CAACD,EACA,MAAM,IAAI,MAAMC,GAAO,kBAAkB,CAEjD,MAAQ,CACJ,MAAM,IAAI,MAAMA,CAAG,CACvB,CACJ,CACJ,EAEA,IAAOC,EAAQV", "mappings": "AAAA,+DACA,MAAM,EAAO,CACT,IAAO,QAAQ,IACf,QAAW,SACX,OAAU,GACV,IAAO,cAEH,AAAG,MAAO,IAAW,WACjB,GAAO,EACP,EAAS,IAGb,MAAY,KAAK,QAAU,KAEd,KACA,GAoBb,MAjBA,QAAO,KAAK,GAAO,QAAQ,IACvB,MAAW,EAAM,GAGjB,IACI,IACA,EAAO,KAAK;AAAA,MAAS,cAErB,AAAI,EACA,EAAO,KAAK;AAAA,OAAU;AAAA;AAAA,GAAkB,EAAI;AAAA,OAE5C,EAAO,KAAK;AAAA,OAAU,QAM/B,MAAO,IAAS,WACR,EAAK,CACR,KAAM,EACN,KAAM,IAGV,GAAK,IAAI,GAAG,EAAQ,GAAG,GACvB,EAAK,IAAI;AAAA,UAAa,EAAO,OAAS,EAAO,eAAe,EAAO,eAAe,EAAO,UAElF,GAAO,SAGtB,GAAM,YACF,YAAK,OAAS,EACP,MAEX,OAAU,QACN,IACI,GAAG,CAAC,EACA,KAAM,IAAI,OAAM,GAAO,6BAG3B,KAAM,IAAI,OAAM,MAK5B,MAAe",
"names": ["test", "errors", "next", "tests", "failed", "passed", "name", "err", "expression", "msg", "testit_default"] "names": []
} }

View File

@ -1,26 +0,0 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default [...compat.extends("eslint:recommended"), {
languageOptions: {
globals: {
...globals.browser,
},
ecmaVersion: "latest",
sourceType: "module",
},
rules: {},
}];

1078
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,19 @@
{ {
"name": "testit.run", "name": "testit",
"version": "1.2.0", "version": "1.1.0",
"description": "minimalistic client-side testing library", "description": "minimalistic clinet-side testing library",
"main": "src/testit.js", "main": "src/testit.js",
"type": "module",
"directories": { "directories": {
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"build": "npx esbuild src/testit.js --minify --sourcemap --format=esm --outfile=dist/testit.min.js", "build": "esbuild src/testit.js --minify --sourcemap --format=esm --outfile=dist/testit.min.js",
"lint": "npx eslint src/testit.js", "lint": "npx eslint src/testit.js",
"test": "npx live-server --open=test/ --port=5000" "test": "npx live-server --open=test/ --port=5000"
}, },
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"eslint": "^9.23.0" "eslint": "^8.20.0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -1,10 +1,10 @@
/*! Test.it v1.2.0 | MIT | https://github.com/n2geoff/testit */ /*! Test.it v1.0.0 | MIT | https://github.com/n2geoff/testit */
export const test = { const test = {
log: console.log, "log": console.log, // eslint-disable-line
version: "v1.2.0", "version": "v1.0.0",
_tests: {}, "_tests": {},
run(errors, next) { "run": function run(errors, next) {
// TODO: rewrite to allow show errors flag (optional) // TODO: rewrite to allow a show errors flag (optional)
if(typeof errors !== "boolean") { if(typeof errors !== "boolean") {
next = errors; next = errors;
errors = true; errors = true;
@ -45,16 +45,16 @@ export const test = {
return failed.length ? false : true; return failed.length ? false : true;
} }
}, },
it(tests) { "it": function it(tests) {
this._tests = tests; this._tests = tests;
return this; return this;
}, },
assert(expression, msg) { "assert": (expression, msg) => {
try { try {
if(!expression) { if(!expression) {
throw new Error(msg || "Assertion Failed"); throw new Error(msg || "Assertion Failed");
} }
} catch { } catch (e) {
throw new Error(msg); throw new Error(msg);
} }
} }

View File

@ -1,29 +1,29 @@
import test from "../src/testit.js"; import test from "../src/testit.js";
export default test.it({ export default test.it({
"'like' should do truthy evaluation via =="() { "'like' should do truthy evaluation via ==": function () {
test.assert(1 == "1"); test.assert(1 == "1");
test.assert(1); test.assert(1);
}, },
"'equal' should do === evaluation exist"() { "'equal' should do === evaluation exist": function () {
test.assert(1 === 1); test.assert(1 === 1);
test.assert("hello" === "hello"); test.assert("hello" === "hello");
}, },
"you should be able to 'pass' a test"() { "you should be able to 'pass' a test": function () {
test.assert(1); test.assert(1);
}, },
"you should be able to fail' a test too"() { "you should be able to fail' a test too": function () {
try { try {
test.assert(0); test.assert(0);
} catch (e) { } catch (e) {
// correct // correct
} }
}, },
"you should be able to test if something 'exists'"() { "you should be able to test if something 'exists'": function () {
test.assert({}); test.assert({});
test.assert(typeof ({}) === "object"); test.assert(typeof ({}) === "object");
}, },
"should be able to check types"() { "should be able to check types": function () {
test.assert(Array.isArray([])); test.assert(Array.isArray([]));
test.assert(typeof (123) === "number"); test.assert(typeof (123) === "number");

View File

@ -1,6 +1,6 @@
import spec from "./index.spec.js"; import spec from "./index.spec.js";
spec.run(false, (r) => { spec.run(false, function (r) {
let errors = []; let errors = [];
document.body.style.backgroundColor = ( document.body.style.backgroundColor = (