@jlbyte/tester 1.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/tester.cjs +1 -200
- package/dist/tester.css +21 -0
- package/dist/tester.js +1 -202
- package/dist/tester.mjs +1 -196
- package/dist/types/tester.d.mts +9 -10
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -35,11 +35,11 @@ run()
|
|
|
35
35
|
"imports": {
|
|
36
36
|
"@jlbyte/ansi": "https://esm.sh/@jlbyte/ansi@1.2.1",
|
|
37
37
|
"@jlbyte/env": "https://esm.sh/@jlbyte/env@1.1.0",
|
|
38
|
-
"@jlbyte/tester": "https://esm.sh/@jlbyte/tester@1.0.
|
|
38
|
+
"@jlbyte/tester": "https://esm.sh/@jlbyte/tester@1.0.4"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
</script>
|
|
42
|
-
<link href="https://esm.sh/@jlbyte/tester@1.
|
|
42
|
+
<link href="https://esm.sh/@jlbyte/tester@1.0.4/dist/tester.css" rel="stylesheet">
|
|
43
43
|
<script type="module">
|
|
44
44
|
import { assert, it, run } from '@jlbyte/tester';
|
|
45
45
|
|
package/dist/tester.cjs
CHANGED
|
@@ -1,200 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var ansi = require('@jlbyte/ansi');
|
|
4
|
-
var env = require('@jlbyte/env');
|
|
5
|
-
|
|
6
|
-
function deepEqual(a, b, seen = new WeakMap()) {
|
|
7
|
-
if (Object.is(a, b)) return true;
|
|
8
|
-
if (a === null || b === null) return false;
|
|
9
|
-
if (typeof a !== 'object' || typeof b !== 'object') return false;
|
|
10
|
-
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
|
|
11
|
-
if (seen.get(a) === b) return true;
|
|
12
|
-
seen.set(a, b);
|
|
13
|
-
|
|
14
|
-
if (a instanceof Date) return a.getTime() === b.getTime();
|
|
15
|
-
if (a instanceof RegExp) return String(a) === String(b);
|
|
16
|
-
if (a instanceof Map) {
|
|
17
|
-
if (a.size !== b.size) return false;
|
|
18
|
-
for (const [k, v] of a) {
|
|
19
|
-
if (!b.has(k) || !deepEqual(v, b.get(k), seen)) return false;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
if (a instanceof Set) {
|
|
24
|
-
if (a.size !== b.size) return false;
|
|
25
|
-
for (const v of a) if (!b.has(v)) return false;
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const aKeys = Reflect.ownKeys(a);
|
|
30
|
-
const bKeys = Reflect.ownKeys(b);
|
|
31
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
32
|
-
for (const key of aKeys) {
|
|
33
|
-
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
34
|
-
if (!deepEqual(a[key], b[key], seen)) return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
class AssertionError extends Error {
|
|
41
|
-
constructor(message, actual, expected) {
|
|
42
|
-
super(message);
|
|
43
|
-
this.name = 'AssertionError';
|
|
44
|
-
this.actual = actual;
|
|
45
|
-
this.expected = expected;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function show(value) {
|
|
50
|
-
const seen = new WeakSet();
|
|
51
|
-
try {
|
|
52
|
-
return JSON.stringify(value, (key, v) => {
|
|
53
|
-
if (v === undefined) return '[undefined]';
|
|
54
|
-
if (typeof v === 'number' && !Number.isFinite(v)) return `[${v}]`;
|
|
55
|
-
if (typeof v === 'bigint') return `[${v}n]`;
|
|
56
|
-
if (typeof v === 'function') return `[Function ${v.name || 'anonymous'}]`;
|
|
57
|
-
if (typeof v === 'symbol') return v.toString();
|
|
58
|
-
if (v instanceof Map) return { '[Map]': [...v] };
|
|
59
|
-
if (v instanceof Set) return { '[Set]': [...v] };
|
|
60
|
-
if (v instanceof RegExp) return String(v);
|
|
61
|
-
if (v && typeof v === 'object') {
|
|
62
|
-
if (seen.has(v)) return '[Circular]';
|
|
63
|
-
seen.add(v);
|
|
64
|
-
}
|
|
65
|
-
return v;
|
|
66
|
-
});
|
|
67
|
-
} catch {
|
|
68
|
-
return String(value);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function assert(value, message) {
|
|
73
|
-
if (!value) throw new AssertionError(message || `Expected ${show(value)} to be truthy`, value, true);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
assert.ok = assert;
|
|
77
|
-
|
|
78
|
-
assert.equal = (actual, expected, message) => {
|
|
79
|
-
if (!Object.is(actual, expected)) {
|
|
80
|
-
throw new AssertionError(message || `Expected ${show(actual)} to be ${show(expected)}`, actual, expected);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
assert.deepEqual = (actual, expected, message) => {
|
|
85
|
-
if (!deepEqual(actual, expected)) {
|
|
86
|
-
throw new AssertionError(message || `Expected ${show(actual)} to deeply equal ${show(expected)}`, actual, expected);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
assert.throws = (fn, message) => {
|
|
91
|
-
try { fn(); } catch { return; }
|
|
92
|
-
throw new AssertionError(message || 'Expected function to throw', undefined, undefined);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const { fg, bg, fgBright } = ansi.color;
|
|
96
|
-
const { cli, browser } = env;
|
|
97
|
-
|
|
98
|
-
let el_tester;
|
|
99
|
-
let el_info_head;
|
|
100
|
-
|
|
101
|
-
if(browser) {
|
|
102
|
-
el_tester = document.createElement('div');
|
|
103
|
-
el_tester.className = 'tester-runner';
|
|
104
|
-
if(!('test_runner_container' in window)) {
|
|
105
|
-
let el_test_runner_container = document.createElement('div');
|
|
106
|
-
el_test_runner_container.id = 'test_runner_container';
|
|
107
|
-
el_test_runner_container.appendChild(el_tester);
|
|
108
|
-
document.body.appendChild(el_test_runner_container);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
test_runner_container.appendChild(el_tester);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
let Test = {
|
|
115
|
-
report: [],
|
|
116
|
-
result: { passed: 0, failed: 0 },
|
|
117
|
-
add: function (name, fn) {
|
|
118
|
-
this.report.push({ name: name, fn: fn });
|
|
119
|
-
},
|
|
120
|
-
run: async function () {
|
|
121
|
-
this.result = { passed: 0, failed: 0 };
|
|
122
|
-
if(browser) {
|
|
123
|
-
var el_group = document.createElement('div');
|
|
124
|
-
el_group.className = 'tester-runner__group';
|
|
125
|
-
el_tester.appendChild(el_group);
|
|
126
|
-
var el_test_head = document.createElement('div');
|
|
127
|
-
el_test_head.className = 'tester-runner__group--head';
|
|
128
|
-
el_test_head.innerHTML += ansi.html(ansi.style.underline('Test'));
|
|
129
|
-
el_group.appendChild(el_test_head);
|
|
130
|
-
}
|
|
131
|
-
if(cli) {
|
|
132
|
-
console.group(`\n${ansi.style.underline('Test')}\n`);
|
|
133
|
-
}
|
|
134
|
-
for (var i = 0; i < this.report.length; i++) {
|
|
135
|
-
var test = this.report[i];
|
|
136
|
-
if(browser) {
|
|
137
|
-
var el_test = document.createElement('div');
|
|
138
|
-
el_test.className = 'tester-runner__group--test';
|
|
139
|
-
el_group.appendChild(el_test);
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
const result = test.fn();
|
|
143
|
-
if (result && typeof result.then === 'function') {
|
|
144
|
-
await result;
|
|
145
|
-
}
|
|
146
|
-
this.result.passed++;
|
|
147
|
-
if(cli) {
|
|
148
|
-
console.log(`${fg.green(ansi.icon.ok)} ${fgBright.blue(test.name)}`);
|
|
149
|
-
}
|
|
150
|
-
if(browser) {
|
|
151
|
-
el_test.innerHTML += ansi.html(`${fg.green(ansi.icon.ok)} ${fgBright.blue(test.name)}`);
|
|
152
|
-
}
|
|
153
|
-
} catch (e) {
|
|
154
|
-
this.result.failed++;
|
|
155
|
-
if(cli) {
|
|
156
|
-
console.log(`${fgBright.red(ansi.icon.fail)} ${fgBright.red(test.name)}`);
|
|
157
|
-
console.groupCollapsed();
|
|
158
|
-
console.log(fgBright.black(e.message));
|
|
159
|
-
console.groupEnd();
|
|
160
|
-
}
|
|
161
|
-
if(browser) {
|
|
162
|
-
el_test.innerHTML += ansi.html(`${fgBright.red(ansi.icon.fail)} ${fgBright.red(test.name)}`);
|
|
163
|
-
var el_test_sub = document.createElement('div');
|
|
164
|
-
el_test_sub.className = 'tester-runner__group--test__sub';
|
|
165
|
-
el_test_sub.innerHTML += ansi.html(fgBright.black(e.message));
|
|
166
|
-
el_test.appendChild(el_test_sub);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if(cli) {
|
|
171
|
-
console.groupEnd();
|
|
172
|
-
console.group(`\n${ansi.style.underline('Result')}\n`);
|
|
173
|
-
console.info(`${bg.green(fgBright.white(` ${this.result.passed} `))} ${fg.green('passed')}, ${bg.red(fgBright.white(` ${this.result.failed} `))} ${fgBright.red('failed')}`);
|
|
174
|
-
console.groupEnd();
|
|
175
|
-
}
|
|
176
|
-
if(browser) {
|
|
177
|
-
var el_info = document.createElement('div');
|
|
178
|
-
el_info.className = 'tester-runner__info';
|
|
179
|
-
el_tester.appendChild(el_info);
|
|
180
|
-
el_info_head = document.createElement('div');
|
|
181
|
-
el_info_head.className = 'tester-runner__info--head';
|
|
182
|
-
el_info_head.innerHTML = ansi.html(ansi.style.underline('Result'));
|
|
183
|
-
el_info.appendChild(el_info_head);
|
|
184
|
-
var el_info_result = document.createElement('div');
|
|
185
|
-
el_info_result.className = 'tester-runner__info--result';
|
|
186
|
-
el_info_result.innerHTML = ansi.html(`${bg.green(fgBright.white(` ${this.result.passed} `))} ${fg.green('passed')}, ${bg.red(fgBright.white(` ${this.result.failed} `))} ${fgBright.red('failed')}`);
|
|
187
|
-
el_info.appendChild(el_info_result);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
function it(name, fn) {
|
|
192
|
-
Test.add(name, fn);
|
|
193
|
-
}
|
|
194
|
-
function run() {
|
|
195
|
-
return Test.run();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
exports.assert = assert;
|
|
199
|
-
exports.it = it;
|
|
200
|
-
exports.run = run;
|
|
1
|
+
"use strict";var e=require("@jlbyte/ansi"),t=require("@jlbyte/env");function n(e,t,r=new WeakMap){if(Object.is(e,t))return!0;if(null===e||null===t)return!1;if("object"!=typeof e||"object"!=typeof t)return!1;if(Object.getPrototypeOf(e)!==Object.getPrototypeOf(t))return!1;if(r.get(e)===t)return!0;if(r.set(e,t),e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return String(e)===String(t);if(e instanceof Map){if(e.size!==t.size)return!1;for(const[i,o]of e)if(!t.has(i)||!n(o,t.get(i),r))return!1;return!0}if(e instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}const i=Reflect.ownKeys(e),o=Reflect.ownKeys(t);if(i.length!==o.length)return!1;for(const o of i){if(!Object.prototype.hasOwnProperty.call(t,o))return!1;if(!n(e[o],t[o],r))return!1}return!0}class r extends Error{constructor(e,t,n){super(e),this.name="AssertionError",this.actual=t,this.expected=n}}function i(e){const t=new WeakSet;try{return JSON.stringify(e,(e,n)=>{if(void 0===n)return"[undefined]";if("number"==typeof n&&!Number.isFinite(n))return`[${n}]`;if("bigint"==typeof n)return`[${n}n]`;if("function"==typeof n)return`[Function ${n.name||"anonymous"}]`;if("symbol"==typeof n)return n.toString();if(n instanceof Map)return{"[Map]":[...n]};if(n instanceof Set)return{"[Set]":[...n]};if(n instanceof RegExp)return String(n);if(n&&"object"==typeof n){if(t.has(n))return"[Circular]";t.add(n)}return n})}catch{return String(e)}}function o(e,t){if(!e)throw new r(t||`Expected ${i(e)} to be truthy`,e,!0)}o.ok=o,o.equal=(e,t,n)=>{if(!Object.is(e,t))throw new r(n||`Expected ${i(e)} to be ${i(t)}`,e,t)},o.deepEqual=(e,t,o)=>{if(!n(e,t))throw new r(o||`Expected ${i(e)} to deeply equal ${i(t)}`,e,t)},o.throws=(e,t)=>{try{e()}catch{return}throw new r(t||"Expected function to throw",void 0,void 0)};const{fg:s,bg:a,fgBright:u}=e.color,{cli:l,browser:c}=t;let d,f;if(c)if(d=document.createElement("div"),d.className="tester-runner","test_runner_container"in window)test_runner_container.appendChild(d);else{let e=document.createElement("div");e.id="test_runner_container",e.appendChild(d),document.body.appendChild(e)}let p={report:[],result:{passed:0,failed:0},add:function(e,t){this.report.push({name:e,fn:t})},run:async function(){if(this.result={passed:0,failed:0},c){var t=document.createElement("div");t.className="tester-runner__group",d.appendChild(t);var n=document.createElement("div");n.className="tester-runner__group--head",n.innerHTML+=e.html(e.style.underline("Test")),t.appendChild(n)}l&&console.group(`\n${e.style.underline("Test")}\n`);for(var r=0;r<this.report.length;r++){var i=this.report[r];if(c){var o=document.createElement("div");o.className="tester-runner__group--test",t.appendChild(o)}try{const t=i.fn();t&&"function"==typeof t.then&&await t,this.result.passed++,l&&console.log(`${s.green(e.icon.ok)} ${u.blue(i.name)}`),c&&(o.innerHTML+=e.html(`${s.green(e.icon.ok)} ${u.blue(i.name)}`))}catch(t){if(this.result.failed++,l&&(console.log(`${u.red(e.icon.fail)} ${u.red(i.name)}`),console.groupCollapsed(),console.log(u.black(t.message)),console.groupEnd()),c){o.innerHTML+=e.html(`${u.red(e.icon.fail)} ${u.red(i.name)}`);var p=document.createElement("div");p.className="tester-runner__group--test__sub",p.innerHTML+=e.html(u.black(t.message)),o.appendChild(p)}}}if(l&&(console.groupEnd(),console.group(`\n${e.style.underline("Result")}\n`),console.info(`${a.green(u.white(` ${this.result.passed} `))} ${s.green("passed")}, ${a.red(u.white(` ${this.result.failed} `))} ${u.red("failed")}`),console.groupEnd()),c){var h=document.createElement("div");h.className="tester-runner__info",d.appendChild(h),f=document.createElement("div"),f.className="tester-runner__info--head",f.innerHTML=e.html(e.style.underline("Result")),h.appendChild(f);var m=document.createElement("div");m.className="tester-runner__info--result",m.innerHTML=e.html(`${a.green(u.white(` ${this.result.passed} `))} ${s.green("passed")}, ${a.red(u.white(` ${this.result.failed} `))} ${u.red("failed")}`),h.appendChild(m)}}};exports.assert=o,exports.it=function(e,t){p.add(e,t)},exports.run=function(){return p.run()};
|
package/dist/tester.css
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#test_runner_container {
|
|
2
|
+
padding: 8px;
|
|
3
|
+
background-color: #0f0f0f;
|
|
4
|
+
color: silver;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.tester-runner {
|
|
8
|
+
font: normal 16px/1.5 ui-monospace, monospace;
|
|
9
|
+
padding: 16px;
|
|
10
|
+
white-space: pre;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.tester-runner__group,
|
|
14
|
+
.tester-runner__group--head,
|
|
15
|
+
.tester-runner__info--head {
|
|
16
|
+
margin-bottom: 1em;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.tester-runner__group--test__sub {
|
|
20
|
+
margin-left: 1em;
|
|
21
|
+
}
|
package/dist/tester.js
CHANGED
|
@@ -1,202 +1 @@
|
|
|
1
|
-
var tester = (function (
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
function deepEqual(a, b, seen = new WeakMap()) {
|
|
5
|
-
if (Object.is(a, b)) return true;
|
|
6
|
-
if (a === null || b === null) return false;
|
|
7
|
-
if (typeof a !== 'object' || typeof b !== 'object') return false;
|
|
8
|
-
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
|
|
9
|
-
if (seen.get(a) === b) return true;
|
|
10
|
-
seen.set(a, b);
|
|
11
|
-
|
|
12
|
-
if (a instanceof Date) return a.getTime() === b.getTime();
|
|
13
|
-
if (a instanceof RegExp) return String(a) === String(b);
|
|
14
|
-
if (a instanceof Map) {
|
|
15
|
-
if (a.size !== b.size) return false;
|
|
16
|
-
for (const [k, v] of a) {
|
|
17
|
-
if (!b.has(k) || !deepEqual(v, b.get(k), seen)) return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (a instanceof Set) {
|
|
22
|
-
if (a.size !== b.size) return false;
|
|
23
|
-
for (const v of a) if (!b.has(v)) return false;
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const aKeys = Reflect.ownKeys(a);
|
|
28
|
-
const bKeys = Reflect.ownKeys(b);
|
|
29
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
30
|
-
for (const key of aKeys) {
|
|
31
|
-
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
32
|
-
if (!deepEqual(a[key], b[key], seen)) return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class AssertionError extends Error {
|
|
39
|
-
constructor(message, actual, expected) {
|
|
40
|
-
super(message);
|
|
41
|
-
this.name = 'AssertionError';
|
|
42
|
-
this.actual = actual;
|
|
43
|
-
this.expected = expected;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function show(value) {
|
|
48
|
-
const seen = new WeakSet();
|
|
49
|
-
try {
|
|
50
|
-
return JSON.stringify(value, (key, v) => {
|
|
51
|
-
if (v === undefined) return '[undefined]';
|
|
52
|
-
if (typeof v === 'number' && !Number.isFinite(v)) return `[${v}]`;
|
|
53
|
-
if (typeof v === 'bigint') return `[${v}n]`;
|
|
54
|
-
if (typeof v === 'function') return `[Function ${v.name || 'anonymous'}]`;
|
|
55
|
-
if (typeof v === 'symbol') return v.toString();
|
|
56
|
-
if (v instanceof Map) return { '[Map]': [...v] };
|
|
57
|
-
if (v instanceof Set) return { '[Set]': [...v] };
|
|
58
|
-
if (v instanceof RegExp) return String(v);
|
|
59
|
-
if (v && typeof v === 'object') {
|
|
60
|
-
if (seen.has(v)) return '[Circular]';
|
|
61
|
-
seen.add(v);
|
|
62
|
-
}
|
|
63
|
-
return v;
|
|
64
|
-
});
|
|
65
|
-
} catch {
|
|
66
|
-
return String(value);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function assert(value, message) {
|
|
71
|
-
if (!value) throw new AssertionError(message || `Expected ${show(value)} to be truthy`, value, true);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
assert.ok = assert;
|
|
75
|
-
|
|
76
|
-
assert.equal = (actual, expected, message) => {
|
|
77
|
-
if (!Object.is(actual, expected)) {
|
|
78
|
-
throw new AssertionError(message || `Expected ${show(actual)} to be ${show(expected)}`, actual, expected);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
assert.deepEqual = (actual, expected, message) => {
|
|
83
|
-
if (!deepEqual(actual, expected)) {
|
|
84
|
-
throw new AssertionError(message || `Expected ${show(actual)} to deeply equal ${show(expected)}`, actual, expected);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
assert.throws = (fn, message) => {
|
|
89
|
-
try { fn(); } catch { return; }
|
|
90
|
-
throw new AssertionError(message || 'Expected function to throw', undefined, undefined);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const { fg, bg, fgBright } = ansi.color;
|
|
94
|
-
const { cli, browser } = env;
|
|
95
|
-
|
|
96
|
-
let el_tester;
|
|
97
|
-
let el_info_head;
|
|
98
|
-
|
|
99
|
-
if(browser) {
|
|
100
|
-
el_tester = document.createElement('div');
|
|
101
|
-
el_tester.className = 'tester-runner';
|
|
102
|
-
if(!('test_runner_container' in window)) {
|
|
103
|
-
let el_test_runner_container = document.createElement('div');
|
|
104
|
-
el_test_runner_container.id = 'test_runner_container';
|
|
105
|
-
el_test_runner_container.appendChild(el_tester);
|
|
106
|
-
document.body.appendChild(el_test_runner_container);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
test_runner_container.appendChild(el_tester);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
let Test = {
|
|
113
|
-
report: [],
|
|
114
|
-
result: { passed: 0, failed: 0 },
|
|
115
|
-
add: function (name, fn) {
|
|
116
|
-
this.report.push({ name: name, fn: fn });
|
|
117
|
-
},
|
|
118
|
-
run: async function () {
|
|
119
|
-
this.result = { passed: 0, failed: 0 };
|
|
120
|
-
if(browser) {
|
|
121
|
-
var el_group = document.createElement('div');
|
|
122
|
-
el_group.className = 'tester-runner__group';
|
|
123
|
-
el_tester.appendChild(el_group);
|
|
124
|
-
var el_test_head = document.createElement('div');
|
|
125
|
-
el_test_head.className = 'tester-runner__group--head';
|
|
126
|
-
el_test_head.innerHTML += ansi.html(ansi.style.underline('Test'));
|
|
127
|
-
el_group.appendChild(el_test_head);
|
|
128
|
-
}
|
|
129
|
-
if(cli) {
|
|
130
|
-
console.group(`\n${ansi.style.underline('Test')}\n`);
|
|
131
|
-
}
|
|
132
|
-
for (var i = 0; i < this.report.length; i++) {
|
|
133
|
-
var test = this.report[i];
|
|
134
|
-
if(browser) {
|
|
135
|
-
var el_test = document.createElement('div');
|
|
136
|
-
el_test.className = 'tester-runner__group--test';
|
|
137
|
-
el_group.appendChild(el_test);
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
const result = test.fn();
|
|
141
|
-
if (result && typeof result.then === 'function') {
|
|
142
|
-
await result;
|
|
143
|
-
}
|
|
144
|
-
this.result.passed++;
|
|
145
|
-
if(cli) {
|
|
146
|
-
console.log(`${fg.green(ansi.icon.ok)} ${fgBright.blue(test.name)}`);
|
|
147
|
-
}
|
|
148
|
-
if(browser) {
|
|
149
|
-
el_test.innerHTML += ansi.html(`${fg.green(ansi.icon.ok)} ${fgBright.blue(test.name)}`);
|
|
150
|
-
}
|
|
151
|
-
} catch (e) {
|
|
152
|
-
this.result.failed++;
|
|
153
|
-
if(cli) {
|
|
154
|
-
console.log(`${fgBright.red(ansi.icon.fail)} ${fgBright.red(test.name)}`);
|
|
155
|
-
console.groupCollapsed();
|
|
156
|
-
console.log(fgBright.black(e.message));
|
|
157
|
-
console.groupEnd();
|
|
158
|
-
}
|
|
159
|
-
if(browser) {
|
|
160
|
-
el_test.innerHTML += ansi.html(`${fgBright.red(ansi.icon.fail)} ${fgBright.red(test.name)}`);
|
|
161
|
-
var el_test_sub = document.createElement('div');
|
|
162
|
-
el_test_sub.className = 'tester-runner__group--test__sub';
|
|
163
|
-
el_test_sub.innerHTML += ansi.html(fgBright.black(e.message));
|
|
164
|
-
el_test.appendChild(el_test_sub);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if(cli) {
|
|
169
|
-
console.groupEnd();
|
|
170
|
-
console.group(`\n${ansi.style.underline('Result')}\n`);
|
|
171
|
-
console.info(`${bg.green(fgBright.white(` ${this.result.passed} `))} ${fg.green('passed')}, ${bg.red(fgBright.white(` ${this.result.failed} `))} ${fgBright.red('failed')}`);
|
|
172
|
-
console.groupEnd();
|
|
173
|
-
}
|
|
174
|
-
if(browser) {
|
|
175
|
-
var el_info = document.createElement('div');
|
|
176
|
-
el_info.className = 'tester-runner__info';
|
|
177
|
-
el_tester.appendChild(el_info);
|
|
178
|
-
el_info_head = document.createElement('div');
|
|
179
|
-
el_info_head.className = 'tester-runner__info--head';
|
|
180
|
-
el_info_head.innerHTML = ansi.html(ansi.style.underline('Result'));
|
|
181
|
-
el_info.appendChild(el_info_head);
|
|
182
|
-
var el_info_result = document.createElement('div');
|
|
183
|
-
el_info_result.className = 'tester-runner__info--result';
|
|
184
|
-
el_info_result.innerHTML = ansi.html(`${bg.green(fgBright.white(` ${this.result.passed} `))} ${fg.green('passed')}, ${bg.red(fgBright.white(` ${this.result.failed} `))} ${fgBright.red('failed')}`);
|
|
185
|
-
el_info.appendChild(el_info_result);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
function it(name, fn) {
|
|
190
|
-
Test.add(name, fn);
|
|
191
|
-
}
|
|
192
|
-
function run() {
|
|
193
|
-
return Test.run();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
exports.assert = assert;
|
|
197
|
-
exports.it = it;
|
|
198
|
-
exports.run = run;
|
|
199
|
-
|
|
200
|
-
return exports;
|
|
201
|
-
|
|
202
|
-
})({}, ansi, env);
|
|
1
|
+
var tester=function(e,t,n){"use strict";function r(e,t,n=new WeakMap){if(Object.is(e,t))return!0;if(null===e||null===t)return!1;if("object"!=typeof e||"object"!=typeof t)return!1;if(Object.getPrototypeOf(e)!==Object.getPrototypeOf(t))return!1;if(n.get(e)===t)return!0;if(n.set(e,t),e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return String(e)===String(t);if(e instanceof Map){if(e.size!==t.size)return!1;for(const[i,o]of e)if(!t.has(i)||!r(o,t.get(i),n))return!1;return!0}if(e instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}const i=Reflect.ownKeys(e),o=Reflect.ownKeys(t);if(i.length!==o.length)return!1;for(const o of i){if(!Object.prototype.hasOwnProperty.call(t,o))return!1;if(!r(e[o],t[o],n))return!1}return!0}class i extends Error{constructor(e,t,n){super(e),this.name="AssertionError",this.actual=t,this.expected=n}}function o(e){const t=new WeakSet;try{return JSON.stringify(e,(e,n)=>{if(void 0===n)return"[undefined]";if("number"==typeof n&&!Number.isFinite(n))return`[${n}]`;if("bigint"==typeof n)return`[${n}n]`;if("function"==typeof n)return`[Function ${n.name||"anonymous"}]`;if("symbol"==typeof n)return n.toString();if(n instanceof Map)return{"[Map]":[...n]};if(n instanceof Set)return{"[Set]":[...n]};if(n instanceof RegExp)return String(n);if(n&&"object"==typeof n){if(t.has(n))return"[Circular]";t.add(n)}return n})}catch{return String(e)}}function s(e,t){if(!e)throw new i(t||`Expected ${o(e)} to be truthy`,e,!0)}s.ok=s,s.equal=(e,t,n)=>{if(!Object.is(e,t))throw new i(n||`Expected ${o(e)} to be ${o(t)}`,e,t)},s.deepEqual=(e,t,n)=>{if(!r(e,t))throw new i(n||`Expected ${o(e)} to deeply equal ${o(t)}`,e,t)},s.throws=(e,t)=>{try{e()}catch{return}throw new i(t||"Expected function to throw",void 0,void 0)};const{fg:a,bg:u,fgBright:l}=t.color,{cli:c,browser:d}=n;let f,p;if(d)if(f=document.createElement("div"),f.className="tester-runner","test_runner_container"in window)test_runner_container.appendChild(f);else{let e=document.createElement("div");e.id="test_runner_container",e.appendChild(f),document.body.appendChild(e)}let h={report:[],result:{passed:0,failed:0},add:function(e,t){this.report.push({name:e,fn:t})},run:async function(){if(this.result={passed:0,failed:0},d){var e=document.createElement("div");e.className="tester-runner__group",f.appendChild(e);var n=document.createElement("div");n.className="tester-runner__group--head",n.innerHTML+=t.html(t.style.underline("Test")),e.appendChild(n)}c&&console.group(`\n${t.style.underline("Test")}\n`);for(var r=0;r<this.report.length;r++){var i=this.report[r];if(d){var o=document.createElement("div");o.className="tester-runner__group--test",e.appendChild(o)}try{const e=i.fn();e&&"function"==typeof e.then&&await e,this.result.passed++,c&&console.log(`${a.green(t.icon.ok)} ${l.blue(i.name)}`),d&&(o.innerHTML+=t.html(`${a.green(t.icon.ok)} ${l.blue(i.name)}`))}catch(e){if(this.result.failed++,c&&(console.log(`${l.red(t.icon.fail)} ${l.red(i.name)}`),console.groupCollapsed(),console.log(l.black(e.message)),console.groupEnd()),d){o.innerHTML+=t.html(`${l.red(t.icon.fail)} ${l.red(i.name)}`);var s=document.createElement("div");s.className="tester-runner__group--test__sub",s.innerHTML+=t.html(l.black(e.message)),o.appendChild(s)}}}if(c&&(console.groupEnd(),console.group(`\n${t.style.underline("Result")}\n`),console.info(`${u.green(l.white(` ${this.result.passed} `))} ${a.green("passed")}, ${u.red(l.white(` ${this.result.failed} `))} ${l.red("failed")}`),console.groupEnd()),d){var h=document.createElement("div");h.className="tester-runner__info",f.appendChild(h),p=document.createElement("div"),p.className="tester-runner__info--head",p.innerHTML=t.html(t.style.underline("Result")),h.appendChild(p);var m=document.createElement("div");m.className="tester-runner__info--result",m.innerHTML=t.html(`${u.green(l.white(` ${this.result.passed} `))} ${a.green("passed")}, ${u.red(l.white(` ${this.result.failed} `))} ${l.red("failed")}`),h.appendChild(m)}}};return e.assert=s,e.it=function(e,t){h.add(e,t)},e.run=function(){return h.run()},e}({},ansi,env);
|
package/dist/tester.mjs
CHANGED
|
@@ -1,196 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import env from '@jlbyte/env';
|
|
3
|
-
|
|
4
|
-
function deepEqual(a, b, seen = new WeakMap()) {
|
|
5
|
-
if (Object.is(a, b)) return true;
|
|
6
|
-
if (a === null || b === null) return false;
|
|
7
|
-
if (typeof a !== 'object' || typeof b !== 'object') return false;
|
|
8
|
-
if (Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
|
|
9
|
-
if (seen.get(a) === b) return true;
|
|
10
|
-
seen.set(a, b);
|
|
11
|
-
|
|
12
|
-
if (a instanceof Date) return a.getTime() === b.getTime();
|
|
13
|
-
if (a instanceof RegExp) return String(a) === String(b);
|
|
14
|
-
if (a instanceof Map) {
|
|
15
|
-
if (a.size !== b.size) return false;
|
|
16
|
-
for (const [k, v] of a) {
|
|
17
|
-
if (!b.has(k) || !deepEqual(v, b.get(k), seen)) return false;
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (a instanceof Set) {
|
|
22
|
-
if (a.size !== b.size) return false;
|
|
23
|
-
for (const v of a) if (!b.has(v)) return false;
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const aKeys = Reflect.ownKeys(a);
|
|
28
|
-
const bKeys = Reflect.ownKeys(b);
|
|
29
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
30
|
-
for (const key of aKeys) {
|
|
31
|
-
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
32
|
-
if (!deepEqual(a[key], b[key], seen)) return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
class AssertionError extends Error {
|
|
39
|
-
constructor(message, actual, expected) {
|
|
40
|
-
super(message);
|
|
41
|
-
this.name = 'AssertionError';
|
|
42
|
-
this.actual = actual;
|
|
43
|
-
this.expected = expected;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function show(value) {
|
|
48
|
-
const seen = new WeakSet();
|
|
49
|
-
try {
|
|
50
|
-
return JSON.stringify(value, (key, v) => {
|
|
51
|
-
if (v === undefined) return '[undefined]';
|
|
52
|
-
if (typeof v === 'number' && !Number.isFinite(v)) return `[${v}]`;
|
|
53
|
-
if (typeof v === 'bigint') return `[${v}n]`;
|
|
54
|
-
if (typeof v === 'function') return `[Function ${v.name || 'anonymous'}]`;
|
|
55
|
-
if (typeof v === 'symbol') return v.toString();
|
|
56
|
-
if (v instanceof Map) return { '[Map]': [...v] };
|
|
57
|
-
if (v instanceof Set) return { '[Set]': [...v] };
|
|
58
|
-
if (v instanceof RegExp) return String(v);
|
|
59
|
-
if (v && typeof v === 'object') {
|
|
60
|
-
if (seen.has(v)) return '[Circular]';
|
|
61
|
-
seen.add(v);
|
|
62
|
-
}
|
|
63
|
-
return v;
|
|
64
|
-
});
|
|
65
|
-
} catch {
|
|
66
|
-
return String(value);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function assert(value, message) {
|
|
71
|
-
if (!value) throw new AssertionError(message || `Expected ${show(value)} to be truthy`, value, true);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
assert.ok = assert;
|
|
75
|
-
|
|
76
|
-
assert.equal = (actual, expected, message) => {
|
|
77
|
-
if (!Object.is(actual, expected)) {
|
|
78
|
-
throw new AssertionError(message || `Expected ${show(actual)} to be ${show(expected)}`, actual, expected);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
assert.deepEqual = (actual, expected, message) => {
|
|
83
|
-
if (!deepEqual(actual, expected)) {
|
|
84
|
-
throw new AssertionError(message || `Expected ${show(actual)} to deeply equal ${show(expected)}`, actual, expected);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
assert.throws = (fn, message) => {
|
|
89
|
-
try { fn(); } catch { return; }
|
|
90
|
-
throw new AssertionError(message || 'Expected function to throw', undefined, undefined);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const { fg, bg, fgBright } = color;
|
|
94
|
-
const { cli, browser } = env;
|
|
95
|
-
|
|
96
|
-
let el_tester;
|
|
97
|
-
let el_info_head;
|
|
98
|
-
|
|
99
|
-
if(browser) {
|
|
100
|
-
el_tester = document.createElement('div');
|
|
101
|
-
el_tester.className = 'tester-runner';
|
|
102
|
-
if(!('test_runner_container' in window)) {
|
|
103
|
-
let el_test_runner_container = document.createElement('div');
|
|
104
|
-
el_test_runner_container.id = 'test_runner_container';
|
|
105
|
-
el_test_runner_container.appendChild(el_tester);
|
|
106
|
-
document.body.appendChild(el_test_runner_container);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
test_runner_container.appendChild(el_tester);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
let Test = {
|
|
113
|
-
report: [],
|
|
114
|
-
result: { passed: 0, failed: 0 },
|
|
115
|
-
add: function (name, fn) {
|
|
116
|
-
this.report.push({ name: name, fn: fn });
|
|
117
|
-
},
|
|
118
|
-
run: async function () {
|
|
119
|
-
this.result = { passed: 0, failed: 0 };
|
|
120
|
-
if(browser) {
|
|
121
|
-
var el_group = document.createElement('div');
|
|
122
|
-
el_group.className = 'tester-runner__group';
|
|
123
|
-
el_tester.appendChild(el_group);
|
|
124
|
-
var el_test_head = document.createElement('div');
|
|
125
|
-
el_test_head.className = 'tester-runner__group--head';
|
|
126
|
-
el_test_head.innerHTML += html(style.underline('Test'));
|
|
127
|
-
el_group.appendChild(el_test_head);
|
|
128
|
-
}
|
|
129
|
-
if(cli) {
|
|
130
|
-
console.group(`\n${style.underline('Test')}\n`);
|
|
131
|
-
}
|
|
132
|
-
for (var i = 0; i < this.report.length; i++) {
|
|
133
|
-
var test = this.report[i];
|
|
134
|
-
if(browser) {
|
|
135
|
-
var el_test = document.createElement('div');
|
|
136
|
-
el_test.className = 'tester-runner__group--test';
|
|
137
|
-
el_group.appendChild(el_test);
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
const result = test.fn();
|
|
141
|
-
if (result && typeof result.then === 'function') {
|
|
142
|
-
await result;
|
|
143
|
-
}
|
|
144
|
-
this.result.passed++;
|
|
145
|
-
if(cli) {
|
|
146
|
-
console.log(`${fg.green(icon.ok)} ${fgBright.blue(test.name)}`);
|
|
147
|
-
}
|
|
148
|
-
if(browser) {
|
|
149
|
-
el_test.innerHTML += html(`${fg.green(icon.ok)} ${fgBright.blue(test.name)}`);
|
|
150
|
-
}
|
|
151
|
-
} catch (e) {
|
|
152
|
-
this.result.failed++;
|
|
153
|
-
if(cli) {
|
|
154
|
-
console.log(`${fgBright.red(icon.fail)} ${fgBright.red(test.name)}`);
|
|
155
|
-
console.groupCollapsed();
|
|
156
|
-
console.log(fgBright.black(e.message));
|
|
157
|
-
console.groupEnd();
|
|
158
|
-
}
|
|
159
|
-
if(browser) {
|
|
160
|
-
el_test.innerHTML += html(`${fgBright.red(icon.fail)} ${fgBright.red(test.name)}`);
|
|
161
|
-
var el_test_sub = document.createElement('div');
|
|
162
|
-
el_test_sub.className = 'tester-runner__group--test__sub';
|
|
163
|
-
el_test_sub.innerHTML += html(fgBright.black(e.message));
|
|
164
|
-
el_test.appendChild(el_test_sub);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if(cli) {
|
|
169
|
-
console.groupEnd();
|
|
170
|
-
console.group(`\n${style.underline('Result')}\n`);
|
|
171
|
-
console.info(`${bg.green(fgBright.white(` ${this.result.passed} `))} ${fg.green('passed')}, ${bg.red(fgBright.white(` ${this.result.failed} `))} ${fgBright.red('failed')}`);
|
|
172
|
-
console.groupEnd();
|
|
173
|
-
}
|
|
174
|
-
if(browser) {
|
|
175
|
-
var el_info = document.createElement('div');
|
|
176
|
-
el_info.className = 'tester-runner__info';
|
|
177
|
-
el_tester.appendChild(el_info);
|
|
178
|
-
el_info_head = document.createElement('div');
|
|
179
|
-
el_info_head.className = 'tester-runner__info--head';
|
|
180
|
-
el_info_head.innerHTML = html(style.underline('Result'));
|
|
181
|
-
el_info.appendChild(el_info_head);
|
|
182
|
-
var el_info_result = document.createElement('div');
|
|
183
|
-
el_info_result.className = 'tester-runner__info--result';
|
|
184
|
-
el_info_result.innerHTML = html(`${bg.green(fgBright.white(` ${this.result.passed} `))} ${fg.green('passed')}, ${bg.red(fgBright.white(` ${this.result.failed} `))} ${fgBright.red('failed')}`);
|
|
185
|
-
el_info.appendChild(el_info_result);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
function it(name, fn) {
|
|
190
|
-
Test.add(name, fn);
|
|
191
|
-
}
|
|
192
|
-
function run() {
|
|
193
|
-
return Test.run();
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export { assert, it, run };
|
|
1
|
+
import{color as e,html as t,style as n,icon as r}from"@jlbyte/ansi";import i from"@jlbyte/env";function o(e,t,n=new WeakMap){if(Object.is(e,t))return!0;if(null===e||null===t)return!1;if("object"!=typeof e||"object"!=typeof t)return!1;if(Object.getPrototypeOf(e)!==Object.getPrototypeOf(t))return!1;if(n.get(e)===t)return!0;if(n.set(e,t),e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return String(e)===String(t);if(e instanceof Map){if(e.size!==t.size)return!1;for(const[r,i]of e)if(!t.has(r)||!o(i,t.get(r),n))return!1;return!0}if(e instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}const r=Reflect.ownKeys(e),i=Reflect.ownKeys(t);if(r.length!==i.length)return!1;for(const i of r){if(!Object.prototype.hasOwnProperty.call(t,i))return!1;if(!o(e[i],t[i],n))return!1}return!0}class s extends Error{constructor(e,t,n){super(e),this.name="AssertionError",this.actual=t,this.expected=n}}function a(e){const t=new WeakSet;try{return JSON.stringify(e,(e,n)=>{if(void 0===n)return"[undefined]";if("number"==typeof n&&!Number.isFinite(n))return`[${n}]`;if("bigint"==typeof n)return`[${n}n]`;if("function"==typeof n)return`[Function ${n.name||"anonymous"}]`;if("symbol"==typeof n)return n.toString();if(n instanceof Map)return{"[Map]":[...n]};if(n instanceof Set)return{"[Set]":[...n]};if(n instanceof RegExp)return String(n);if(n&&"object"==typeof n){if(t.has(n))return"[Circular]";t.add(n)}return n})}catch{return String(e)}}function u(e,t){if(!e)throw new s(t||`Expected ${a(e)} to be truthy`,e,!0)}u.ok=u,u.equal=(e,t,n)=>{if(!Object.is(e,t))throw new s(n||`Expected ${a(e)} to be ${a(t)}`,e,t)},u.deepEqual=(e,t,n)=>{if(!o(e,t))throw new s(n||`Expected ${a(e)} to deeply equal ${a(t)}`,e,t)},u.throws=(e,t)=>{try{e()}catch{return}throw new s(t||"Expected function to throw",void 0,void 0)};const{fg:c,bg:l,fgBright:d}=e,{cli:f,browser:p}=i;let h,m;if(p)if(h=document.createElement("div"),h.className="tester-runner","test_runner_container"in window)test_runner_container.appendChild(h);else{let e=document.createElement("div");e.id="test_runner_container",e.appendChild(h),document.body.appendChild(e)}let g={report:[],result:{passed:0,failed:0},add:function(e,t){this.report.push({name:e,fn:t})},run:async function(){if(this.result={passed:0,failed:0},p){var e=document.createElement("div");e.className="tester-runner__group",h.appendChild(e);var i=document.createElement("div");i.className="tester-runner__group--head",i.innerHTML+=t(n.underline("Test")),e.appendChild(i)}f&&console.group(`\n${n.underline("Test")}\n`);for(var o=0;o<this.report.length;o++){var s=this.report[o];if(p){var a=document.createElement("div");a.className="tester-runner__group--test",e.appendChild(a)}try{const e=s.fn();e&&"function"==typeof e.then&&await e,this.result.passed++,f&&console.log(`${c.green(r.ok)} ${d.blue(s.name)}`),p&&(a.innerHTML+=t(`${c.green(r.ok)} ${d.blue(s.name)}`))}catch(e){if(this.result.failed++,f&&(console.log(`${d.red(r.fail)} ${d.red(s.name)}`),console.groupCollapsed(),console.log(d.black(e.message)),console.groupEnd()),p){a.innerHTML+=t(`${d.red(r.fail)} ${d.red(s.name)}`);var u=document.createElement("div");u.className="tester-runner__group--test__sub",u.innerHTML+=t(d.black(e.message)),a.appendChild(u)}}}if(f&&(console.groupEnd(),console.group(`\n${n.underline("Result")}\n`),console.info(`${l.green(d.white(` ${this.result.passed} `))} ${c.green("passed")}, ${l.red(d.white(` ${this.result.failed} `))} ${d.red("failed")}`),console.groupEnd()),p){var g=document.createElement("div");g.className="tester-runner__info",h.appendChild(g),m=document.createElement("div"),m.className="tester-runner__info--head",m.innerHTML=t(n.underline("Result")),g.appendChild(m);var $=document.createElement("div");$.className="tester-runner__info--result",$.innerHTML=t(`${l.green(d.white(` ${this.result.passed} `))} ${c.green("passed")}, ${l.red(d.white(` ${this.result.failed} `))} ${d.red("failed")}`),g.appendChild($)}}};function $(e,t){g.add(e,t)}function y(){return g.run()}export{u as assert,$ as it,y as run};
|
package/dist/types/tester.d.mts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
declare function
|
|
2
|
-
declare namespace
|
|
3
|
-
export {
|
|
4
|
-
export var equal: (
|
|
5
|
-
export var
|
|
6
|
-
export
|
|
7
|
-
export var throws: (fn: any, message: any) => void;
|
|
1
|
+
declare function u(e: any, t: any): void;
|
|
2
|
+
declare namespace u {
|
|
3
|
+
export { u as ok };
|
|
4
|
+
export var equal: (e: any, t: any, n: any) => void;
|
|
5
|
+
export var deepEqual: (e: any, t: any, n: any) => void;
|
|
6
|
+
export var throws: (e: any, t: any) => void;
|
|
8
7
|
}
|
|
9
|
-
declare function
|
|
10
|
-
declare function
|
|
11
|
-
export { assert, it, run };
|
|
8
|
+
declare function $(e: any, t: any): void;
|
|
9
|
+
declare function y(): Promise<void>;
|
|
10
|
+
export { u as assert, $ as it, y as run };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jlbyte/tester",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "JS Tester library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"test",
|
|
@@ -27,16 +27,13 @@
|
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
|
-
"import": "./
|
|
30
|
+
"import": "./dist/tester.mjs",
|
|
31
31
|
"require": "./dist/tester.cjs",
|
|
32
|
-
"browser": "./dist/tester.js",
|
|
33
32
|
"types": "./dist/types/tester.d.mts"
|
|
34
33
|
}
|
|
35
34
|
},
|
|
36
35
|
"main": "./dist/tester.cjs",
|
|
37
|
-
"
|
|
38
|
-
"browser": "dist/tester.js",
|
|
39
|
-
"types": "dist/types/tester.d.mts",
|
|
36
|
+
"browser": "./dist/tester.js",
|
|
40
37
|
"files": [
|
|
41
38
|
"README.md",
|
|
42
39
|
"LICENSE",
|
|
@@ -47,8 +44,9 @@
|
|
|
47
44
|
},
|
|
48
45
|
"scripts": {
|
|
49
46
|
"usage": "node usage/test.mjs",
|
|
50
|
-
"build:rollup": "rollup --input=./src/tester.mjs --dir ./dist --format es --entryFileNames \"[name].mjs\" -p node-resolve -e bowser,@jlbyte/ansi,@jlbyte/env && rollup --input=./src/tester.mjs --dir ./dist --format cjs --entryFileNames \"[name].cjs\" -p node-resolve -e bowser,@jlbyte/ansi,@jlbyte/env && rollup --input=./src/tester.mjs --dir ./dist --name tester --format iife --entryFileNames \"[name].js\" -p node-resolve -e bowser,@jlbyte/ansi,@jlbyte/env -g bowser:bowser,ansi:ansi,env:env",
|
|
47
|
+
"build:rollup": "rollup --input=./src/tester.mjs --dir ./dist --format es --entryFileNames \"[name].mjs\" -p node-resolve,terser -e bowser,@jlbyte/ansi,@jlbyte/env && rollup --input=./src/tester.mjs --dir ./dist --format cjs --entryFileNames \"[name].cjs\" -p node-resolve,terser -e bowser,@jlbyte/ansi,@jlbyte/env && rollup --input=./src/tester.mjs --dir ./dist --name tester --format iife --entryFileNames \"[name].js\" -p node-resolve,terser -e bowser,@jlbyte/ansi,@jlbyte/env -g bowser:bowser,ansi:ansi,env:env",
|
|
51
48
|
"build:types": "tsc --allowJs --declaration --emitDeclarationOnly --rootDir ./dist --outDir ./dist/types ./dist/tester.mjs",
|
|
52
|
-
"build": "
|
|
49
|
+
"build:css": "cp src/tester.css dist/tester.css",
|
|
50
|
+
"build": "npm run build:rollup && npm run build:types && npm run build:css"
|
|
53
51
|
}
|
|
54
52
|
}
|