Compare commits

...

15 Commits

Author SHA1 Message Date
Geoff Doty 1bf0aab37e deps & shorter fn syntax 2025-03-24 19:46:45 -04:00
Geoff Doty a71500e31f npm compat 2024-06-16 16:11:39 -04:00
Geoff Doty a6948f9b37 update deps 2024-06-16 16:04:12 -04:00
Geoff Doty efa77cf804
Merge pull request #3 from n2geoff/dependabot/npm_and_yarn/word-wrap-1.2.4
Bump word-wrap from 1.2.3 to 1.2.4
2024-03-02 07:02:10 -06:00
dependabot[bot] 539c71f107
Bump word-wrap from 1.2.3 to 1.2.4
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-19 20:07:23 +00:00
Geoff Doty ac5626cd25 deps 2023-03-15 09:54:36 -04:00
Geoff Doty 0112677df5 npm package naming woes 2022-07-31 11:55:26 -04:00
Geoff Doty 07daa67faf rename for npm 2022-07-31 11:50:54 -04:00
Geoff Doty 0bc6300cbc 1.1.1 2022-07-31 11:48:00 -04:00
Geoff Doty bd7c4e25fa rename package for npm 2022-07-31 11:47:52 -04:00
Geoff Doty 08e4364aea 1.1.0 2022-07-31 01:50:15 -04:00
Geoff Doty 9846dbb618 remove live-server as dep, but call via npx if requested 2022-07-31 01:49:50 -04:00
Geoff Doty 8d880193a5 linting 2022-07-31 01:40:35 -04:00
Geoff Doty 98c7523881 switching to esbuild 2021-01-02 03:42:41 -05:00
Geoff Doty 12233bfb6c update deps 2021-01-01 15:57:07 -05:00
16 changed files with 866 additions and 4771 deletions

View File

@ -1,34 +0,0 @@
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:
```bash
npm test
npm run test
```
## Reporting a bug

View File

@ -1,6 +1,6 @@
The MIT License
Copyright (c) 2018 testit authors
Copyright (c) 2023 Geoff Doty
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

View File

@ -1,6 +1,6 @@
# Test.it
> A minimalistic testing library
> A minimalistic client-side testing library
**Test.it** is a small client-side testing library for people that want to live in code, not in tests. No over engineering here. Inspired by the simplicity of libraries like [Jasmine](https://jasmine.github.io/), but implementation ideas based on [TinyTest](https://github.com/joewalnes/jstinytest)
@ -31,10 +31,10 @@ By default, you can run your tests like
import test from 'testit';
test.it({
'my passing test': function() {
'my passing test'() {
test.assert(true);
},
'my failing test': function() {
'my failing test'() {
test.assert(true === false, 'just wanted to fail fast');
}
}).run();
@ -68,10 +68,10 @@ For Example...
```js
test.it({
'my passing test': function() {
'my passing test'() {
test.assert(true);
}
}, function(results) {
}, (results) => {
if (window.document && document.body) {
document.body.style.backgroundColor = (
results.fail.length ? '#ff9999' : '#99ff99'
@ -112,7 +112,7 @@ putting that above your tests will allow you to write like
```js
test.it({
"my test should work": function() {
"my test should work"() {
assert(true);
}
});
@ -134,4 +134,4 @@ Anyone is welcome to contribute, however, if you decide to get involved, please
## License
[MIT](LICENSE)
[MIT](LICENSE) Geoff Doty

58
dist/testit.js vendored
View File

@ -1,58 +0,0 @@
/*! Test.it v1.0.0 | MIT | https://github.com/n2geoff/testit */
const test = {
"log": console.log,
"version": "v1.0.0",
"_tests": {},
"run": function run(errors, next) {
if(typeof errors !== "boolean") {
next = errors;
errors = true;
}
let tests = this._tests || [];
let failed = [];
let passed = [];
Object.keys(tests).forEach((name) => {
let test = tests[name];
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}`);
}
}
});
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 failed.length ? false : true;
}
},
"it": function it(tests) {
this._tests = tests;
return this;
},
"assert": (expression, msg) => {
try {
if(!expression) {
throw new Error(msg || "Assertion Failed");
}
} catch (e) {
throw new Error(msg);
}
}
};
export default test;

10
dist/testit.min.js vendored
View File

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

7
dist/testit.min.js.map vendored Normal file
View File

@ -0,0 +1,7 @@
{
"version": 3,
"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"],
"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",
"names": ["test", "errors", "next", "tests", "failed", "passed", "name", "err", "expression", "msg", "testit_default"]
}

66
dist/testit.umd.js vendored
View File

@ -1,66 +0,0 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define('umd', factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.umd = factory());
}(this, (function () { 'use strict';
/*! Test.it v1.0.0 | MIT | https://github.com/n2geoff/testit */
const test = {
"log": console.log,
"version": "v1.0.0",
"_tests": {},
"run": function run(errors, next) {
if(typeof errors !== "boolean") {
next = errors;
errors = true;
}
let tests = this._tests || [];
let failed = [];
let passed = [];
Object.keys(tests).forEach((name) => {
let test = tests[name];
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}`);
}
}
});
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 failed.length ? false : true;
}
},
"it": function it(tests) {
this._tests = tests;
return this;
},
"assert": (expression, msg) => {
try {
if(!expression) {
throw new Error(msg || "Assertion Failed");
}
} catch (e) {
throw new Error(msg);
}
}
};
return test;
})));

View File

@ -1 +0,0 @@
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define("umd",e):(t="undefined"!=typeof globalThis?globalThis:t||self).umd=e()}(this,function(){"use strict";const t={log:console.log,version:"v1.0.0",_tests:{},run:function(e,n){"boolean"!=typeof e&&(n=e,e=!0);let o=this._tests||[],s=[],i=[];return Object.keys(o).forEach(t=>{let n=o[t];try{n(),i.push(`\n+OK ${t}`)}catch(n){e?s.push(`\n-ERR ${t} \n --- \n ${n.stack} \n ---`):s.push(`\n-ERR ${t}`)}}),"function"==typeof n?n({pass:i,fail:s}):(t.log(...i,...s),t.log(`\n# tests ${s.length+i.length} pass ${i.length} fail ${s.length}`),!s.length)},it:function(t){return this._tests=t,this},assert:(t,e)=>{try{if(!t)throw new Error(e||"Assertion Failed")}catch(t){throw new Error(e)}}};return t});

26
eslint.config.mjs Normal file
View File

@ -0,0 +1,26 @@
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: {},
}];

View File

@ -1,26 +0,0 @@
const gulp = require("gulp");
const minify = require("gulp-minify");
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"))
});

5259
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,20 @@
{
"name": "testit",
"version": "1.0.0",
"description": "minimalistic testing library",
"name": "testit.run",
"version": "1.2.0",
"description": "minimalistic client-side testing library",
"main": "src/testit.js",
"type": "module",
"directories": {
"test": "test"
},
"scripts": {
"build": "npx gulp default",
"build": "npx esbuild src/testit.js --minify --sourcemap --format=esm --outfile=dist/testit.min.js",
"lint": "npx eslint src/testit.js",
"test": "npx live-server --open=test/ --port=5000"
},
"dependencies": {},
"devDependencies": {
"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",
"live-server": "^1.2.1"
"eslint": "^9.23.0"
},
"repository": {
"type": "git",

View File

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

View File

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

View File

@ -1,6 +1,6 @@
import spec from "./index.spec.js";
spec.run(false, function (r) {
spec.run(false, (r) => {
let errors = [];
document.body.style.backgroundColor = (
@ -10,6 +10,6 @@ spec.run(false, function (r) {
r.pass.forEach((p) => errors.push(`<br>${p}`));
r.fail.forEach((f) => errors.push(`<br><b>${f}</b>`));
document.querySelector('#errors').innerHTML = errors;
document.querySelector('#summary').innerHTML = `| 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} |`;
});