@jlbyte/tester 0.0.0-stage → 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jlongyam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,60 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # Tester
2
+
3
+ Tiny cross-runtime test runner,
4
+ Standard JS only.
5
+
6
+ ## Support
7
+
8
+ - Node
9
+ - Deno
10
+ - Bun
11
+ - browsers
12
+
13
+ ## Usage
14
+
15
+ ### CLI
16
+
17
+ ```js
18
+ import { assert, it, run } from '@jlbyte/tester';
19
+
20
+ it('Sample Test', ()=> {
21
+ assert.equal(1,1)
22
+ });
23
+ it('Shoulf fail', ()=> {
24
+ assert.ok(null, 'aah')
25
+ })
26
+
27
+ run()
28
+ ```
29
+
30
+ ### Browser
31
+
32
+ ```html
33
+ <script type="importmap">
34
+ {
35
+ "imports": {
36
+ "@jlbyte/ansi": "https://cdn.jsdelivr.net/npm/@jlbyte/ansi@1.2.1/+esm",
37
+ "@jlbyte/env": "https://cdn.jsdelivr.net/npm/@jlbyte/env@1.1.0/+esm",
38
+ "@jlbyte/tester": "https://cdn.jsdelivr.net/npm/@jlbyte/tester@1.0.0/+esm"
39
+ }
40
+ }
41
+ </script>
42
+ <link href="https://cdn.jsdelivr.net/npm/@jlbyte/env@1.1.0/dist/tester.css" rel="stylesheet">
43
+ <script type="module">
44
+ import { assert, it, run } from '@jlbyte/tester';
45
+
46
+ it('Sample Test', ()=> {
47
+ assert.equal(1,1)
48
+ });
49
+ it('Shoulf fail', ()=> {
50
+ assert.ok(null, 'aah')
51
+ })
52
+
53
+ await run()
54
+ </script>
55
+ </body>
56
+ ```
57
+
58
+ ## License
59
+
60
+ License [MIT](LICENSE)
@@ -0,0 +1,200 @@
1
+ 'use strict';
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;
package/dist/tester.js ADDED
@@ -0,0 +1,202 @@
1
+ var tester = (function (exports, ansi, env) {
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);
@@ -0,0 +1,196 @@
1
+ import { color, html, style, icon } from '@jlbyte/ansi';
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 };
@@ -0,0 +1,11 @@
1
+ declare function assert(value: any, message: any): void;
2
+ declare namespace assert {
3
+ export { assert as ok };
4
+ export var equal: (actual: any, expected: any, message: any) => void;
5
+ export var _a: (actual: any, expected: any, message: any) => void;
6
+ export { _a as deepEqual };
7
+ export var throws: (fn: any, message: any) => void;
8
+ }
9
+ declare function it(name: any, fn: any): void;
10
+ declare function run(): Promise<void>;
11
+ export { assert, it, run };
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@jlbyte/tester",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "JS Tester library",
5
+ "keywords": [
6
+ "test",
7
+ "tester",
8
+ "assert",
9
+ "test-runner"
10
+ ],
11
+ "homepage": "https://github.com/jlongyam/core",
12
+ "repository": {
13
+ "url": "https://github.com/jlongyam/core",
14
+ "directory": "packages/tester"
15
+ },
16
+ "license": "MIT",
17
+ "author": "jlongyam",
18
+ "devDependencies": {
19
+ "@rollup/plugin-node-resolve": "^16.0.3",
20
+ "@rollup/plugin-terser": "^1.0.2",
21
+ "rollup": "^4.66.0",
22
+ "typescript": "^7.0.2"
23
+ },
24
+ "dependencies": {
25
+ "@jlbyte/ansi": "^1.2.1",
26
+ "@jlbyte/env": "^1.1.0"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "import": "./src/tester.mjs",
31
+ "require": "./dist/env.cjs",
32
+ "browser": "./dist/env.js",
33
+ "types": "./dist/types/env.d.mts"
34
+ }
35
+ },
36
+ "module": "dist/env.mjs",
37
+ "browser": "dist/env.js",
38
+ "types": "dist/types/env.d.mts",
39
+ "files": [
40
+ "README.md",
41
+ "LICENSE",
42
+ "dist"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "main": "index.mjs",
48
+ "scripts": {
49
+ "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",
51
+ "build:types": "tsc --allowJs --declaration --emitDeclarationOnly --rootDir ./dist --outDir ./dist/types ./dist/tester.mjs",
52
+ "build": "npm run build:rollup && npm run build:types"
53
+ }
54
+ }