@davidsouther/jiffies 2.2.4 → 2.3.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 +1 -1
- package/lib/cjs/assert.d.ts +2 -2
- package/lib/cjs/awaitable.d.ts +1 -1
- package/lib/cjs/components/button_bar.d.ts +2 -2
- package/lib/cjs/components/inline_edit.d.ts +2 -2
- package/lib/cjs/components/logger.d.ts +1 -1
- package/lib/cjs/components/select.d.ts +4 -7
- package/lib/cjs/components/test.d.ts +1 -1
- package/lib/cjs/components/virtual_scroll.d.ts +6 -4
- package/lib/cjs/context.d.ts +5 -9
- package/lib/cjs/debounce.d.ts +1 -1
- package/lib/cjs/diff.d.ts +2 -2
- package/lib/cjs/display.d.ts +1 -1
- package/lib/cjs/dom/css/border.d.ts +2 -2
- package/lib/cjs/dom/css/constants.d.ts +3 -3
- package/lib/cjs/dom/css/core.d.ts +1 -1
- package/lib/cjs/dom/css/fstyle.d.ts +2 -2
- package/lib/cjs/dom/css/sizing.d.ts +2 -2
- package/lib/cjs/dom/dom.d.ts +8 -8
- package/lib/cjs/dom/fc.d.ts +8 -12
- package/lib/cjs/dom/form/form.d.ts +5 -6
- package/lib/cjs/dom/html.d.ts +112 -113
- package/lib/cjs/dom/observable.d.ts +1 -1
- package/lib/cjs/dom/provide.d.ts +1 -1
- package/lib/cjs/dom/router/router.d.ts +2 -2
- package/lib/cjs/dom/svg.d.ts +64 -64
- package/lib/cjs/dom/types/css.d.ts +10 -32
- package/lib/cjs/dom/types/html.d.ts +4 -6
- package/lib/cjs/equal.d.ts +8 -5
- package/lib/cjs/flags.d.ts +1 -1
- package/lib/cjs/fs.d.ts +3 -3
- package/lib/cjs/fs_node.d.ts +1 -1
- package/lib/cjs/lock.d.ts +1 -1
- package/lib/cjs/log.d.ts +9 -9
- package/lib/cjs/observable/event.d.ts +2 -2
- package/lib/cjs/observable/observable.d.ts +37 -35
- package/lib/cjs/result.d.ts +21 -21
- package/lib/cjs/safe.d.ts +1 -1
- package/lib/cjs/scope/describe.d.ts +4 -4
- package/lib/cjs/scope/display/console.d.ts +1 -1
- package/lib/cjs/scope/display/dom.d.ts +2 -2
- package/lib/cjs/scope/display/junit.d.ts +1 -1
- package/lib/cjs/scope/execute.d.ts +2 -2
- package/lib/cjs/scope/index.d.ts +3 -3
- package/lib/cjs/scope/scope.d.ts +3 -3
- package/lib/cjs/scope/state.d.ts +1 -1
- package/lib/cjs/server/http/apps.d.ts +1 -1
- package/lib/cjs/server/http/css.d.ts +1 -1
- package/lib/cjs/server/http/index.d.ts +4 -9
- package/lib/cjs/server/http/response.d.ts +3 -3
- package/lib/cjs/server/http/sitemap.d.ts +1 -1
- package/lib/cjs/server/http/static.d.ts +1 -1
- package/lib/cjs/server/http/typescript.d.ts +1 -1
- package/lib/cjs/test_all.d.ts +9 -9
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/assert.d.ts +2 -2
- package/lib/esm/awaitable.d.ts +1 -1
- package/lib/esm/components/button_bar.d.ts +2 -2
- package/lib/esm/components/inline_edit.d.ts +2 -2
- package/lib/esm/components/logger.d.ts +1 -1
- package/lib/esm/components/select.d.ts +3 -3
- package/lib/esm/components/test.d.ts +1 -1
- package/lib/esm/components/virtual_scroll.d.ts +6 -4
- package/lib/esm/context.d.ts +5 -9
- package/lib/esm/debounce.d.ts +1 -2
- package/lib/esm/diff.d.ts +2 -2
- package/lib/esm/display.d.ts +1 -1
- package/lib/esm/dom/css/border.d.ts +2 -2
- package/lib/esm/dom/css/constants.d.ts +3 -3
- package/lib/esm/dom/css/core.d.ts +1 -1
- package/lib/esm/dom/css/fstyle.d.ts +2 -2
- package/lib/esm/dom/css/sizing.d.ts +2 -2
- package/lib/esm/dom/dom.d.ts +8 -8
- package/lib/esm/dom/fc.d.ts +8 -12
- package/lib/esm/dom/form/form.d.ts +5 -6
- package/lib/esm/dom/html.d.ts +112 -113
- package/lib/esm/dom/observable.d.ts +1 -1
- package/lib/esm/dom/provide.d.ts +1 -1
- package/lib/esm/dom/router/router.d.ts +2 -2
- package/lib/esm/dom/svg.d.ts +64 -64
- package/lib/esm/dom/types/css.d.ts +10 -32
- package/lib/esm/dom/types/html.d.ts +4 -6
- package/lib/esm/equal.d.ts +8 -5
- package/lib/esm/flags.d.ts +1 -1
- package/lib/esm/fs.d.ts +3 -3
- package/lib/esm/fs_node.d.ts +1 -1
- package/lib/esm/lock.d.ts +1 -1
- package/lib/esm/log.d.ts +9 -9
- package/lib/esm/observable/event.d.ts +2 -2
- package/lib/esm/observable/observable.d.ts +37 -35
- package/lib/esm/result.d.ts +21 -21
- package/lib/esm/safe.d.ts +1 -1
- package/lib/esm/scope/describe.d.ts +4 -4
- package/lib/esm/scope/display/console.d.ts +1 -1
- package/lib/esm/scope/display/dom.d.ts +2 -2
- package/lib/esm/scope/display/junit.d.ts +1 -1
- package/lib/esm/scope/execute.d.ts +2 -2
- package/lib/esm/scope/index.d.ts +3 -3
- package/lib/esm/scope/scope.d.ts +3 -3
- package/lib/esm/scope/state.d.ts +1 -1
- package/lib/esm/server/http/apps.d.ts +1 -1
- package/lib/esm/server/http/css.d.ts +1 -1
- package/lib/esm/server/http/index.d.ts +4 -9
- package/lib/esm/server/http/response.d.ts +3 -3
- package/lib/esm/server/http/sitemap.d.ts +1 -1
- package/lib/esm/server/http/static.d.ts +1 -1
- package/lib/esm/server/http/typescript.d.ts +1 -1
- package/lib/esm/test_all.d.ts +9 -9
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -9
- package/src/assert.ts +5 -5
- package/src/components/button_bar.ts +28 -30
- package/src/components/inline_edit.ts +8 -7
- package/src/components/logger.ts +6 -6
- package/src/components/select.ts +7 -7
- package/src/components/test.ts +5 -0
- package/src/components/virtual_scroll.test.ts +9 -6
- package/src/components/virtual_scroll.ts +29 -24
- package/src/context.test.ts +4 -4
- package/src/context.ts +16 -11
- package/src/debounce.ts +9 -3
- package/src/diff.test.ts +4 -4
- package/src/diff.ts +14 -16
- package/src/dom/css/border.ts +11 -11
- package/src/dom/css/core.ts +1 -1
- package/src/dom/css/fstyle.ts +4 -4
- package/src/dom/css/sizing.ts +1 -1
- package/src/dom/dom.ts +57 -47
- package/src/dom/fc.test.ts +8 -8
- package/src/dom/fc.ts +32 -35
- package/src/dom/form/form.app.ts +9 -9
- package/src/dom/form/form.ts +25 -16
- package/src/dom/form/index.html +3 -2
- package/src/dom/html.test.ts +12 -10
- package/src/dom/html.ts +2 -3
- package/src/dom/observable.test.ts +6 -6
- package/src/dom/observable.ts +2 -2
- package/src/dom/provide.ts +1 -1
- package/src/dom/router/link.ts +3 -3
- package/src/dom/router/router.ts +5 -5
- package/src/dom/svg.ts +7 -6
- package/src/dom/test.ts +3 -0
- package/src/dom/types/css.ts +43 -61
- package/src/dom/types/html.ts +2 -4
- package/src/dom/xml.ts +2 -2
- package/src/equal.test.ts +3 -3
- package/src/equal.ts +27 -14
- package/src/flags.test.ts +2 -2
- package/src/flags.ts +2 -2
- package/src/fs.test.ts +5 -5
- package/src/fs.ts +26 -20
- package/src/fs_node.ts +4 -4
- package/src/fs_win.test.ts +1 -1
- package/src/generator.test.ts +4 -3
- package/src/generator.ts +1 -1
- package/src/hooks/_notes +4 -1
- package/src/index.html +7 -7
- package/src/lock.test.ts +4 -4
- package/src/lock.ts +8 -7
- package/src/log.ts +28 -18
- package/src/observable/event.ts +7 -7
- package/src/observable/observable.test.ts +3 -3
- package/src/observable/observable.ts +71 -52
- package/src/result.test.ts +7 -10
- package/src/result.ts +51 -47
- package/src/safe.ts +1 -1
- package/src/scope/describe.ts +12 -11
- package/src/scope/display/console.ts +4 -4
- package/src/scope/display/dom.ts +9 -9
- package/src/scope/display/junit.ts +21 -24
- package/src/scope/execute.ts +17 -12
- package/src/scope/expect.ts +22 -22
- package/src/scope/fix.ts +10 -7
- package/src/scope/index.ts +3 -3
- package/src/scope/scope.ts +2 -2
- package/src/scope/state.ts +2 -2
- package/src/server/http/apps.ts +5 -5
- package/src/server/http/css.ts +10 -26
- package/src/server/http/index.ts +30 -24
- package/src/server/http/response.ts +12 -5
- package/src/server/http/sitemap.ts +8 -8
- package/src/server/http/static.ts +9 -6
- package/src/server/http/typescript.ts +25 -25
- package/src/server/main.ts +7 -4
- package/src/test.mjs +8 -8
- package/src/test_all.ts +16 -13
- package/src/transpile.mjs +6 -18
- package/build/pico.css +0 -2466
- package/build/pico.css.map +0 -1
- package/lib/cjs/assert.js +0 -46
- package/lib/cjs/awaitable.js +0 -2
- package/lib/cjs/case.js +0 -9
- package/lib/cjs/components/button_bar.js +0 -29
- package/lib/cjs/components/inline_edit.js +0 -51
- package/lib/cjs/components/logger.js +0 -27
- package/lib/cjs/components/select.js +0 -6
- package/lib/cjs/components/test.js +0 -7
- package/lib/cjs/components/virtual_scroll.js +0 -102
- package/lib/cjs/components/virtual_scroll.test.js +0 -22
- package/lib/cjs/context.js +0 -48
- package/lib/cjs/context.test.js +0 -48
- package/lib/cjs/debounce.js +0 -12
- package/lib/cjs/diff.js +0 -58
- package/lib/cjs/diff.test.js +0 -41
- package/lib/cjs/display.js +0 -16
- package/lib/cjs/dom/css/border.js +0 -33
- package/lib/cjs/dom/css/constants.js +0 -31
- package/lib/cjs/dom/css/core.js +0 -31
- package/lib/cjs/dom/css/fstyle.js +0 -36
- package/lib/cjs/dom/css/sizing.js +0 -14
- package/lib/cjs/dom/dom.js +0 -110
- package/lib/cjs/dom/fc.js +0 -39
- package/lib/cjs/dom/fc.test.js +0 -23
- package/lib/cjs/dom/form/form.app.js +0 -27
- package/lib/cjs/dom/form/form.js +0 -49
- package/lib/cjs/dom/form/form.test.js +0 -1
- package/lib/cjs/dom/html.js +0 -119
- package/lib/cjs/dom/html.test.js +0 -60
- package/lib/cjs/dom/observable.js +0 -10
- package/lib/cjs/dom/observable.test.js +0 -35
- package/lib/cjs/dom/provide.js +0 -12
- package/lib/cjs/dom/router/link.js +0 -7
- package/lib/cjs/dom/router/router.js +0 -55
- package/lib/cjs/dom/svg.js +0 -69
- package/lib/cjs/dom/test.js +0 -13
- package/lib/cjs/dom/types/css.js +0 -24
- package/lib/cjs/dom/types/dom.js +0 -1
- package/lib/cjs/dom/types/html.js +0 -2
- package/lib/cjs/dom/xml.js +0 -8
- package/lib/cjs/equal.js +0 -48
- package/lib/cjs/equal.test.js +0 -22
- package/lib/cjs/flags.js +0 -52
- package/lib/cjs/flags.test.js +0 -37
- package/lib/cjs/fs.js +0 -235
- package/lib/cjs/fs.test.js +0 -86
- package/lib/cjs/fs_node.js +0 -50
- package/lib/cjs/fs_win.test.js +0 -10
- package/lib/cjs/generator.js +0 -14
- package/lib/cjs/generator.test.js +0 -26
- package/lib/cjs/is_browser.js +0 -4
- package/lib/cjs/loader-register.d.mts +0 -1
- package/lib/cjs/loader-register.d.ts +0 -1
- package/lib/cjs/loader-register.js +0 -4
- package/lib/cjs/loader-register.mjs +0 -4
- package/lib/cjs/loader.d.mts +0 -23
- package/lib/cjs/loader.mjs +0 -41
- package/lib/cjs/lock.js +0 -27
- package/lib/cjs/lock.test.js +0 -18
- package/lib/cjs/log.js +0 -98
- package/lib/cjs/observable/event.js +0 -61
- package/lib/cjs/observable/observable.js +0 -363
- package/lib/cjs/observable/observable.test.js +0 -65
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/range.js +0 -11
- package/lib/cjs/result.js +0 -80
- package/lib/cjs/result.test.js +0 -78
- package/lib/cjs/safe.js +0 -14
- package/lib/cjs/scope/describe.js +0 -73
- package/lib/cjs/scope/display/console.js +0 -25
- package/lib/cjs/scope/display/dom.js +0 -30
- package/lib/cjs/scope/display/junit.js +0 -21
- package/lib/cjs/scope/execute.js +0 -91
- package/lib/cjs/scope/expect.js +0 -110
- package/lib/cjs/scope/fix.js +0 -26
- package/lib/cjs/scope/index.js +0 -15
- package/lib/cjs/scope/scope.js +0 -2
- package/lib/cjs/scope/state.js +0 -12
- package/lib/cjs/server/http/apps.js +0 -27
- package/lib/cjs/server/http/css.js +0 -54
- package/lib/cjs/server/http/index.js +0 -77
- package/lib/cjs/server/http/response.js +0 -45
- package/lib/cjs/server/http/sitemap.js +0 -46
- package/lib/cjs/server/http/static.js +0 -25
- package/lib/cjs/server/http/typescript.js +0 -44
- package/lib/cjs/server/main.js +0 -14
- package/lib/cjs/test.mjs +0 -28
- package/lib/cjs/test_all.js +0 -30
- package/lib/cjs/transpile.mjs +0 -22
- package/lib/esm/assert.js +0 -38
- package/lib/esm/awaitable.js +0 -1
- package/lib/esm/case.js +0 -5
- package/lib/esm/components/button_bar.js +0 -27
- package/lib/esm/components/inline_edit.js +0 -48
- package/lib/esm/components/logger.js +0 -22
- package/lib/esm/components/select.js +0 -3
- package/lib/esm/components/test.js +0 -3
- package/lib/esm/components/virtual_scroll.js +0 -94
- package/lib/esm/components/virtual_scroll.test.js +0 -20
- package/lib/esm/context.js +0 -43
- package/lib/esm/context.test.js +0 -46
- package/lib/esm/debounce.js +0 -8
- package/lib/esm/diff.js +0 -54
- package/lib/esm/diff.test.js +0 -39
- package/lib/esm/display.js +0 -11
- package/lib/esm/dom/css/border.js +0 -27
- package/lib/esm/dom/css/constants.js +0 -28
- package/lib/esm/dom/css/core.js +0 -24
- package/lib/esm/dom/css/fstyle.js +0 -32
- package/lib/esm/dom/css/sizing.js +0 -10
- package/lib/esm/dom/dom.js +0 -104
- package/lib/esm/dom/fc.js +0 -35
- package/lib/esm/dom/fc.test.js +0 -21
- package/lib/esm/dom/form/form.app.js +0 -23
- package/lib/esm/dom/form/form.js +0 -34
- package/lib/esm/dom/form/form.test.js +0 -1
- package/lib/esm/dom/html.js +0 -114
- package/lib/esm/dom/html.test.js +0 -58
- package/lib/esm/dom/observable.js +0 -6
- package/lib/esm/dom/observable.test.js +0 -33
- package/lib/esm/dom/provide.js +0 -7
- package/lib/esm/dom/router/link.js +0 -3
- package/lib/esm/dom/router/router.js +0 -52
- package/lib/esm/dom/svg.js +0 -65
- package/lib/esm/dom/test.js +0 -9
- package/lib/esm/dom/types/css.js +0 -23
- package/lib/esm/dom/types/dom.js +0 -1
- package/lib/esm/dom/types/html.js +0 -1
- package/lib/esm/dom/xml.js +0 -4
- package/lib/esm/equal.js +0 -41
- package/lib/esm/equal.test.js +0 -20
- package/lib/esm/flags.js +0 -48
- package/lib/esm/flags.test.js +0 -35
- package/lib/esm/fs.js +0 -226
- package/lib/esm/fs.test.js +0 -84
- package/lib/esm/fs_node.js +0 -45
- package/lib/esm/fs_win.test.js +0 -8
- package/lib/esm/generator.js +0 -10
- package/lib/esm/generator.test.js +0 -24
- package/lib/esm/is_browser.js +0 -1
- package/lib/esm/loader-register.d.mts +0 -1
- package/lib/esm/loader-register.mjs +0 -2
- package/lib/esm/loader.d.mts +0 -23
- package/lib/esm/loader.mjs +0 -36
- package/lib/esm/lock.js +0 -23
- package/lib/esm/lock.test.js +0 -16
- package/lib/esm/log.js +0 -88
- package/lib/esm/observable/event.js +0 -46
- package/lib/esm/observable/observable.js +0 -343
- package/lib/esm/observable/observable.test.js +0 -63
- package/lib/esm/range.js +0 -7
- package/lib/esm/result.js +0 -65
- package/lib/esm/result.test.js +0 -76
- package/lib/esm/safe.js +0 -10
- package/lib/esm/scope/describe.js +0 -60
- package/lib/esm/scope/display/console.js +0 -21
- package/lib/esm/scope/display/dom.js +0 -26
- package/lib/esm/scope/display/junit.js +0 -17
- package/lib/esm/scope/execute.js +0 -85
- package/lib/esm/scope/expect.js +0 -104
- package/lib/esm/scope/fix.js +0 -22
- package/lib/esm/scope/index.js +0 -3
- package/lib/esm/scope/scope.js +0 -1
- package/lib/esm/scope/state.js +0 -8
- package/lib/esm/server/http/apps.js +0 -23
- package/lib/esm/server/http/css.js +0 -50
- package/lib/esm/server/http/index.js +0 -73
- package/lib/esm/server/http/response.js +0 -40
- package/lib/esm/server/http/sitemap.js +0 -42
- package/lib/esm/server/http/static.js +0 -21
- package/lib/esm/server/http/typescript.js +0 -40
- package/lib/esm/server/main.js +0 -12
- package/lib/esm/test.mjs +0 -26
- package/lib/esm/test_all.js +0 -28
- package/lib/esm/transpile.mjs +0 -18
- package/src/components/test.js +0 -3
- package/src/loader-register.mjs +0 -3
- package/src/loader.mjs +0 -46
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_LOGGER } from "../log.js";
|
|
2
|
-
export const Observable = {
|
|
3
|
-
of(...ts) {
|
|
4
|
-
const subject = new Subject();
|
|
5
|
-
(async function next() {
|
|
6
|
-
if (subject.cold) {
|
|
7
|
-
subject.onWarm(next);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (ts.length === 0) {
|
|
11
|
-
subject.complete();
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const t = ts.shift();
|
|
15
|
-
await subject.next(t);
|
|
16
|
-
next();
|
|
17
|
-
})();
|
|
18
|
-
return subject;
|
|
19
|
-
},
|
|
20
|
-
combineLatest(o1, o2) {
|
|
21
|
-
let latestSubject = new Subject();
|
|
22
|
-
let o1LatestSet = false;
|
|
23
|
-
let o1Latest;
|
|
24
|
-
let o2LatestSet = false;
|
|
25
|
-
let o2Latest;
|
|
26
|
-
function next() {
|
|
27
|
-
if (o1LatestSet && o2LatestSet) {
|
|
28
|
-
latestSubject.next([o1Latest, o2Latest]);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function error(e) {
|
|
32
|
-
latestSubject.error(e);
|
|
33
|
-
}
|
|
34
|
-
function complete() {
|
|
35
|
-
latestSubject.complete();
|
|
36
|
-
o1sub.unsubscribe();
|
|
37
|
-
o2sub.unsubscribe();
|
|
38
|
-
}
|
|
39
|
-
let o1sub = o1.subscribe({
|
|
40
|
-
next(t) {
|
|
41
|
-
o1Latest = t;
|
|
42
|
-
o1LatestSet = true;
|
|
43
|
-
next();
|
|
44
|
-
},
|
|
45
|
-
error,
|
|
46
|
-
complete,
|
|
47
|
-
});
|
|
48
|
-
let o2sub = o2.subscribe({
|
|
49
|
-
next(t) {
|
|
50
|
-
o2Latest = t;
|
|
51
|
-
o2LatestSet = true;
|
|
52
|
-
next();
|
|
53
|
-
},
|
|
54
|
-
error,
|
|
55
|
-
complete,
|
|
56
|
-
});
|
|
57
|
-
return latestSubject;
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
export const AsyncScheduler = {
|
|
61
|
-
execute(fn) {
|
|
62
|
-
return Promise.all(fn()).then(() => undefined);
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
export const SyncScheduler = {
|
|
66
|
-
execute(fn) {
|
|
67
|
-
fn();
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
export class Subject {
|
|
71
|
-
scheduler;
|
|
72
|
-
#coldWaiters = new Set();
|
|
73
|
-
#subscribers = new Set();
|
|
74
|
-
#complete = false;
|
|
75
|
-
get $() {
|
|
76
|
-
return this;
|
|
77
|
-
}
|
|
78
|
-
get hot() {
|
|
79
|
-
return this.#subscribers.size > 0;
|
|
80
|
-
}
|
|
81
|
-
get cold() {
|
|
82
|
-
return !this.hot;
|
|
83
|
-
}
|
|
84
|
-
constructor(scheduler = AsyncScheduler) {
|
|
85
|
-
this.scheduler = scheduler;
|
|
86
|
-
}
|
|
87
|
-
onWarm(fn) {
|
|
88
|
-
if (this.cold)
|
|
89
|
-
this.#coldWaiters.add(fn);
|
|
90
|
-
}
|
|
91
|
-
next(t) {
|
|
92
|
-
if (this.#complete)
|
|
93
|
-
throw new Error("Cannot call next on a completed subject");
|
|
94
|
-
return this.scheduler.execute(() => [...this.#subscribers].map((s) => s.next?.(t)));
|
|
95
|
-
}
|
|
96
|
-
error(e) {
|
|
97
|
-
if (this.#complete)
|
|
98
|
-
throw new Error("Cannot call error on a completed subject");
|
|
99
|
-
return this.scheduler.execute(() => [...this.#subscribers].map((s) => s.error?.(e)));
|
|
100
|
-
}
|
|
101
|
-
complete() {
|
|
102
|
-
if (this.#complete)
|
|
103
|
-
throw new Error("Cannot call complete on a completed subject");
|
|
104
|
-
this.#complete = true;
|
|
105
|
-
const finished = this.scheduler.execute(() => [...this.#subscribers].map((s) => s.complete?.()));
|
|
106
|
-
this.#subscribers.clear(); // Free subscribers for garbage collection
|
|
107
|
-
return finished;
|
|
108
|
-
}
|
|
109
|
-
subscribe(subscriber) {
|
|
110
|
-
if (this.#complete)
|
|
111
|
-
throw new Error("Cannot call subscribe on a completed subject");
|
|
112
|
-
if (subscriber instanceof Function) {
|
|
113
|
-
subscriber = { next: subscriber };
|
|
114
|
-
}
|
|
115
|
-
this.#subscribers.add(subscriber);
|
|
116
|
-
[...this.#coldWaiters].forEach((w) => w());
|
|
117
|
-
this.#coldWaiters.clear();
|
|
118
|
-
return {
|
|
119
|
-
unsubscribe: () => this.#subscribers.delete(subscriber),
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
pipe(...os) {
|
|
123
|
-
this.subscribe(os[0]);
|
|
124
|
-
for (let i = 1; i < os.length; i++) {
|
|
125
|
-
os[i - 1].subscribe(os[i]);
|
|
126
|
-
}
|
|
127
|
-
return os[os.length - 1];
|
|
128
|
-
}
|
|
129
|
-
filter(fn) {
|
|
130
|
-
return this.pipe(operator.filter(fn));
|
|
131
|
-
}
|
|
132
|
-
distinct(fn = Object.is) {
|
|
133
|
-
return this.pipe(operator.distinct(fn));
|
|
134
|
-
}
|
|
135
|
-
map(fn) {
|
|
136
|
-
return this.pipe(operator.map(fn));
|
|
137
|
-
}
|
|
138
|
-
reduce(fn, init) {
|
|
139
|
-
return this.pipe(operator.reduce(fn, init));
|
|
140
|
-
}
|
|
141
|
-
replay(n) {
|
|
142
|
-
return this.pipe(operator.replay(n));
|
|
143
|
-
}
|
|
144
|
-
tap(s) {
|
|
145
|
-
return this.pipe(operator.tap(s));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
export class BehaviorSubject extends Subject {
|
|
149
|
-
#current;
|
|
150
|
-
constructor(t, scheduler) {
|
|
151
|
-
super(scheduler);
|
|
152
|
-
this.#current = t;
|
|
153
|
-
}
|
|
154
|
-
next(t) {
|
|
155
|
-
this.#current = t;
|
|
156
|
-
return super.next(t);
|
|
157
|
-
}
|
|
158
|
-
subscribe(subscriber) {
|
|
159
|
-
if (subscriber instanceof Function) {
|
|
160
|
-
subscriber = { next: subscriber };
|
|
161
|
-
}
|
|
162
|
-
subscriber.next?.(this.#current);
|
|
163
|
-
return super.subscribe(subscriber);
|
|
164
|
-
}
|
|
165
|
-
get current() {
|
|
166
|
-
return this.#current;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
export class ReplaySubject extends Subject {
|
|
170
|
-
n;
|
|
171
|
-
#history = [];
|
|
172
|
-
constructor(n, scheduler) {
|
|
173
|
-
super(scheduler);
|
|
174
|
-
this.n = n;
|
|
175
|
-
}
|
|
176
|
-
next(t) {
|
|
177
|
-
this.#history.push(t);
|
|
178
|
-
if (this.#history.length > this.n) {
|
|
179
|
-
this.#history.shift();
|
|
180
|
-
}
|
|
181
|
-
return super.next(t);
|
|
182
|
-
}
|
|
183
|
-
subscribe(subscriber) {
|
|
184
|
-
if (subscriber instanceof Function) {
|
|
185
|
-
subscriber = { next: subscriber };
|
|
186
|
-
}
|
|
187
|
-
const history = [...this.#history];
|
|
188
|
-
(function send() {
|
|
189
|
-
if (history.length == 0)
|
|
190
|
-
return;
|
|
191
|
-
const t = history.shift();
|
|
192
|
-
subscriber.next?.(t);
|
|
193
|
-
new Promise(send);
|
|
194
|
-
})();
|
|
195
|
-
return super.subscribe(subscriber);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
export function eventListener() {
|
|
199
|
-
const observable = new Subject();
|
|
200
|
-
function listener(e) {
|
|
201
|
-
e.preventDefault();
|
|
202
|
-
observable.next(e);
|
|
203
|
-
}
|
|
204
|
-
return [observable, listener];
|
|
205
|
-
}
|
|
206
|
-
export class EventHandler extends Subject {
|
|
207
|
-
eventFn;
|
|
208
|
-
constructor(eventFn) {
|
|
209
|
-
super();
|
|
210
|
-
this.eventFn = eventFn;
|
|
211
|
-
}
|
|
212
|
-
next(e) {
|
|
213
|
-
e.preventDefault();
|
|
214
|
-
super.next(e);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
export const watch = (logger = DEFAULT_LOGGER) => (observable) => {
|
|
218
|
-
observable.tap({
|
|
219
|
-
next(t) {
|
|
220
|
-
logger.info(t);
|
|
221
|
-
},
|
|
222
|
-
complete() {
|
|
223
|
-
logger.info("Observable completed");
|
|
224
|
-
},
|
|
225
|
-
error(e) {
|
|
226
|
-
logger.warn(e);
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
class MapOperator extends Subject {
|
|
231
|
-
mapFn;
|
|
232
|
-
constructor(mapFn) {
|
|
233
|
-
super();
|
|
234
|
-
this.mapFn = mapFn;
|
|
235
|
-
}
|
|
236
|
-
next(t) {
|
|
237
|
-
return super.next(this.mapFn(t));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
class FilterOperator extends Subject {
|
|
241
|
-
filterFn;
|
|
242
|
-
constructor(filterFn) {
|
|
243
|
-
super();
|
|
244
|
-
this.filterFn = filterFn;
|
|
245
|
-
}
|
|
246
|
-
next(t) {
|
|
247
|
-
return this.filterFn(t) ? super.next(t) : undefined;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
class DistinctOperator extends Subject {
|
|
251
|
-
distinctFn;
|
|
252
|
-
#prior = undefined;
|
|
253
|
-
constructor(distinctFn = Object.is) {
|
|
254
|
-
super();
|
|
255
|
-
this.distinctFn = distinctFn;
|
|
256
|
-
}
|
|
257
|
-
next(t) {
|
|
258
|
-
if (this.#prior === undefined) {
|
|
259
|
-
this.#prior = t;
|
|
260
|
-
return super.next(t);
|
|
261
|
-
}
|
|
262
|
-
const same = this.distinctFn(this.#prior, t);
|
|
263
|
-
if (!same) {
|
|
264
|
-
this.#prior = t;
|
|
265
|
-
return super.next(t);
|
|
266
|
-
}
|
|
267
|
-
return undefined;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
class ReduceOperator extends BehaviorSubject {
|
|
271
|
-
fn;
|
|
272
|
-
constructor(fn, init) {
|
|
273
|
-
super(init);
|
|
274
|
-
this.fn = fn;
|
|
275
|
-
}
|
|
276
|
-
next(t) {
|
|
277
|
-
return super.next(this.fn(this.current, t));
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
export class TakeUntilOperator extends Subject {
|
|
281
|
-
constructor(o) {
|
|
282
|
-
super();
|
|
283
|
-
o.subscribe(() => this.complete());
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
export class TapOperator extends Subject {
|
|
287
|
-
subscriber;
|
|
288
|
-
constructor(fn) {
|
|
289
|
-
super();
|
|
290
|
-
this.subscriber = fn instanceof Function ? { next: fn } : fn;
|
|
291
|
-
}
|
|
292
|
-
next(t) {
|
|
293
|
-
this.subscriber.next?.(t);
|
|
294
|
-
return super.next(t);
|
|
295
|
-
}
|
|
296
|
-
error(e) {
|
|
297
|
-
this.subscriber.error?.(e);
|
|
298
|
-
return super.error(e);
|
|
299
|
-
}
|
|
300
|
-
complete() {
|
|
301
|
-
this.subscriber.complete?.();
|
|
302
|
-
return super.complete();
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
class FirstOperator extends Subject {
|
|
306
|
-
next(t) {
|
|
307
|
-
const next = super.next(t);
|
|
308
|
-
this.complete();
|
|
309
|
-
return next;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
class LastOperator extends Subject {
|
|
313
|
-
#latest;
|
|
314
|
-
next(t) {
|
|
315
|
-
this.#latest = t;
|
|
316
|
-
}
|
|
317
|
-
complete() {
|
|
318
|
-
if (this.#latest !== undefined) {
|
|
319
|
-
super.next(this.#latest);
|
|
320
|
-
}
|
|
321
|
-
return super.complete();
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
export const filter = (fn) => new FilterOperator(fn);
|
|
325
|
-
export const distinct = (fn) => new DistinctOperator(fn ?? Object.is);
|
|
326
|
-
export const first = () => new FirstOperator();
|
|
327
|
-
export const last = () => new LastOperator();
|
|
328
|
-
export const map = (fn) => new MapOperator(fn);
|
|
329
|
-
export const replay = (n) => new ReplaySubject(n);
|
|
330
|
-
export const reduce = (fn, init) => new ReduceOperator(fn, init);
|
|
331
|
-
export const takeUntil = (o) => new TakeUntilOperator(o);
|
|
332
|
-
export const tap = (fn) => new TapOperator(fn);
|
|
333
|
-
export const operator = {
|
|
334
|
-
filter,
|
|
335
|
-
distinct,
|
|
336
|
-
first,
|
|
337
|
-
last,
|
|
338
|
-
map,
|
|
339
|
-
replay,
|
|
340
|
-
reduce,
|
|
341
|
-
takeUntil,
|
|
342
|
-
tap,
|
|
343
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "../scope/index.js";
|
|
2
|
-
import { Observable, Subject, filter, map } from "./observable.js";
|
|
3
|
-
describe("Observables", () => {
|
|
4
|
-
describe("basics", () => {
|
|
5
|
-
it("can create and observe a scalar subject", async () => {
|
|
6
|
-
const subject = new Subject();
|
|
7
|
-
let resolved = 42;
|
|
8
|
-
subject.subscribe({
|
|
9
|
-
next: (n) => {
|
|
10
|
-
resolved = n;
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
expect(resolved).toBe(42);
|
|
14
|
-
await subject.next(64);
|
|
15
|
-
expect(resolved).toBe(64);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
describe("creation", () => {
|
|
19
|
-
it("builds an observable of items", async () => {
|
|
20
|
-
const stream = Observable.of(2, 4, 8, 16);
|
|
21
|
-
let values = [];
|
|
22
|
-
await new Promise((resolve) => {
|
|
23
|
-
stream.subscribe({
|
|
24
|
-
next: (n) => {
|
|
25
|
-
values.unshift(n);
|
|
26
|
-
},
|
|
27
|
-
complete: () => {
|
|
28
|
-
resolve();
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
expect(values).toEqual([16, 8, 4, 2]);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe("pipes", () => {
|
|
36
|
-
it("runs a pipe", async () => {
|
|
37
|
-
const subject = new Subject();
|
|
38
|
-
let resolved = 0;
|
|
39
|
-
const inflate = (i) => (n) => n + i;
|
|
40
|
-
const biggerThan = (i) => (n) => n > i;
|
|
41
|
-
const assign = (n) => {
|
|
42
|
-
resolved = n;
|
|
43
|
-
};
|
|
44
|
-
subject.pipe(map(inflate(22)), filter(biggerThan(70))).subscribe(assign);
|
|
45
|
-
expect(resolved).toBe(0);
|
|
46
|
-
await subject.next(42);
|
|
47
|
-
expect(resolved).toBe(0);
|
|
48
|
-
await subject.next(50);
|
|
49
|
-
expect(resolved).toBe(72);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe("Subject", () => {
|
|
53
|
-
it("is callable", async () => {
|
|
54
|
-
const subject = new Subject();
|
|
55
|
-
let resolved = 0;
|
|
56
|
-
subject.subscribe((n) => {
|
|
57
|
-
resolved = n;
|
|
58
|
-
});
|
|
59
|
-
await subject.next(42);
|
|
60
|
-
expect(resolved).toBe(42);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
package/lib/esm/range.js
DELETED
package/lib/esm/result.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export const isNone = (s) => s === null;
|
|
2
|
-
export const isSome = (s) => s != null;
|
|
3
|
-
export function None(_) {
|
|
4
|
-
return null;
|
|
5
|
-
}
|
|
6
|
-
export function Some(t) {
|
|
7
|
-
return t;
|
|
8
|
-
}
|
|
9
|
-
export const isOk = (t) => Object.prototype.hasOwnProperty.call(t ?? {}, "ok");
|
|
10
|
-
export const isErr = (e) => Object.prototype.hasOwnProperty.call(e, "err");
|
|
11
|
-
export const isResult = (t) => isOk(t) || isErr(t);
|
|
12
|
-
export function Ok(t) {
|
|
13
|
-
return isOk(t)
|
|
14
|
-
? t.ok
|
|
15
|
-
: {
|
|
16
|
-
ok: t,
|
|
17
|
-
map(fn) {
|
|
18
|
-
return fn(Ok(this));
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export function Err(e) {
|
|
23
|
-
return (e.err ?? {
|
|
24
|
-
err: e,
|
|
25
|
-
map(_fn) {
|
|
26
|
-
return this;
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export function unwrap(t) {
|
|
31
|
-
if (isNone(t)) {
|
|
32
|
-
throw new Error(`Attempted to unwrap None`);
|
|
33
|
-
}
|
|
34
|
-
if (isErr(t)) {
|
|
35
|
-
throw Err(t);
|
|
36
|
-
}
|
|
37
|
-
if (isOk(t)) {
|
|
38
|
-
return Ok(t);
|
|
39
|
-
}
|
|
40
|
-
return t;
|
|
41
|
-
}
|
|
42
|
-
export function unwrapOr(t, def) {
|
|
43
|
-
if (isNone(t)) {
|
|
44
|
-
return def;
|
|
45
|
-
}
|
|
46
|
-
if (isErr(t)) {
|
|
47
|
-
return def;
|
|
48
|
-
}
|
|
49
|
-
if (isOk(t)) {
|
|
50
|
-
return Ok(t);
|
|
51
|
-
}
|
|
52
|
-
return t;
|
|
53
|
-
}
|
|
54
|
-
export function unwrapOrElse(t, def) {
|
|
55
|
-
if (isNone(t)) {
|
|
56
|
-
return def();
|
|
57
|
-
}
|
|
58
|
-
if (isErr(t)) {
|
|
59
|
-
return def();
|
|
60
|
-
}
|
|
61
|
-
if (isOk(t)) {
|
|
62
|
-
return Ok(t);
|
|
63
|
-
}
|
|
64
|
-
return t;
|
|
65
|
-
}
|
package/lib/esm/result.test.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Err, None, Ok, Some, unwrap, unwrapOr, unwrapOrElse, } from "./result.js";
|
|
2
|
-
import { describe, it } from "./scope/describe.js";
|
|
3
|
-
import { expect } from "./scope/expect.js";
|
|
4
|
-
describe("Result", () => {
|
|
5
|
-
it("converts Nones", () => {
|
|
6
|
-
const a = None();
|
|
7
|
-
expect(a).toBeNull();
|
|
8
|
-
const b = None();
|
|
9
|
-
expect(b).toBeNull();
|
|
10
|
-
const c = Some(a);
|
|
11
|
-
expect(c).toBeNull();
|
|
12
|
-
const d = Some(b);
|
|
13
|
-
expect(d).toBeNull();
|
|
14
|
-
});
|
|
15
|
-
it("converts Somes", () => {
|
|
16
|
-
const a = Some("a");
|
|
17
|
-
expect(a).toBe("a");
|
|
18
|
-
const b = Some(a);
|
|
19
|
-
expect(b).toBe("a");
|
|
20
|
-
});
|
|
21
|
-
it("converts Errs", () => {
|
|
22
|
-
const a = Err(new Error("a error"));
|
|
23
|
-
const b = Err(a);
|
|
24
|
-
expect(b).toMatchObject({ message: "a error" });
|
|
25
|
-
// Assign Err to Result
|
|
26
|
-
const c = a;
|
|
27
|
-
});
|
|
28
|
-
it("converts Oks", () => {
|
|
29
|
-
const a = Ok("a ok");
|
|
30
|
-
const b = Ok(a);
|
|
31
|
-
expect(b).toBe("a ok");
|
|
32
|
-
// Assign ok to Result
|
|
33
|
-
const c = a;
|
|
34
|
-
});
|
|
35
|
-
it("unwraps", () => {
|
|
36
|
-
const a = Some("some");
|
|
37
|
-
const b = None();
|
|
38
|
-
const c = Ok("ok");
|
|
39
|
-
const d = Err(new Error("err"));
|
|
40
|
-
const e = "else";
|
|
41
|
-
expect(unwrap(a)).toBe("some");
|
|
42
|
-
expect(unwrap(c)).toBe("ok");
|
|
43
|
-
expect(() => unwrap(b)).toThrow("Attempted to unwrap None");
|
|
44
|
-
expect(() => unwrap(d)).toThrow("err");
|
|
45
|
-
expect(unwrap(e)).toBe("else");
|
|
46
|
-
});
|
|
47
|
-
it("unwrapsOrs", () => {
|
|
48
|
-
const a = Some("some");
|
|
49
|
-
const b = None();
|
|
50
|
-
const c = Ok("ok");
|
|
51
|
-
const d = Err(new Error("err"));
|
|
52
|
-
const e = "else";
|
|
53
|
-
expect(unwrapOr(a, "z")).toBe("some");
|
|
54
|
-
expect(unwrapOr(c, "z")).toBe("ok");
|
|
55
|
-
expect(unwrapOr(b, "z")).toBe("z");
|
|
56
|
-
expect(unwrapOr(d, "z")).toBe("z");
|
|
57
|
-
expect(unwrapOr(e, "z")).toBe("else");
|
|
58
|
-
});
|
|
59
|
-
it("unwrapsOrElse", () => {
|
|
60
|
-
const a = Some("some");
|
|
61
|
-
const b = None();
|
|
62
|
-
const c = Ok("ok");
|
|
63
|
-
const d = Err(new Error("err"));
|
|
64
|
-
const e = "else";
|
|
65
|
-
expect(unwrapOrElse(a, () => "z")).toBe("some");
|
|
66
|
-
expect(unwrapOrElse(c, () => "z")).toBe("ok");
|
|
67
|
-
expect(unwrapOrElse(b, () => "z")).toBe("z");
|
|
68
|
-
expect(unwrapOrElse(d, () => "z")).toBe("z");
|
|
69
|
-
expect(unwrapOrElse(e, () => "z")).toBe("else");
|
|
70
|
-
});
|
|
71
|
-
it("allows Result<void> with Ok()", () => {
|
|
72
|
-
let a;
|
|
73
|
-
a = Ok();
|
|
74
|
-
expect(unwrap(a)).toBe(undefined);
|
|
75
|
-
});
|
|
76
|
-
});
|
package/lib/esm/safe.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { assert } from "../assert.js";
|
|
2
|
-
import { getLogger } from "../log.js";
|
|
3
|
-
import * as state from "./state.js";
|
|
4
|
-
export const beforeall = Symbol("beforeAll");
|
|
5
|
-
export const beforeeach = Symbol("beforeEach");
|
|
6
|
-
export const afterall = Symbol("afterAll");
|
|
7
|
-
export const aftereach = Symbol("afterEach");
|
|
8
|
-
const logger = getLogger("scope");
|
|
9
|
-
const CASES = {};
|
|
10
|
-
let cases = [CASES];
|
|
11
|
-
let totalCases = 0;
|
|
12
|
-
let skippedCases = 0;
|
|
13
|
-
function push(title) {
|
|
14
|
-
const next = (cases[0][title] = cases[0][title] ?? {});
|
|
15
|
-
cases.unshift(next);
|
|
16
|
-
}
|
|
17
|
-
function pop() {
|
|
18
|
-
cases.shift();
|
|
19
|
-
}
|
|
20
|
-
export function rootCases() {
|
|
21
|
-
return CASES;
|
|
22
|
-
}
|
|
23
|
-
export function getTotalCases() {
|
|
24
|
-
return totalCases;
|
|
25
|
-
}
|
|
26
|
-
export function getSkippedCases() {
|
|
27
|
-
return skippedCases;
|
|
28
|
-
}
|
|
29
|
-
export function describe(title, block) {
|
|
30
|
-
logger.debug(`describe(${title})`);
|
|
31
|
-
push(title);
|
|
32
|
-
block();
|
|
33
|
-
pop();
|
|
34
|
-
}
|
|
35
|
-
export function it(title, block) {
|
|
36
|
-
logger.debug(`it(${title})`);
|
|
37
|
-
assert(cases[0][title] == undefined, `Block already has test ${title}`);
|
|
38
|
-
totalCases += 1;
|
|
39
|
-
cases[0][title] = block;
|
|
40
|
-
}
|
|
41
|
-
it.skip = (title, _block) => {
|
|
42
|
-
logger.debug(`it.skip(${title})`);
|
|
43
|
-
totalCases += 1;
|
|
44
|
-
skippedCases += 1;
|
|
45
|
-
};
|
|
46
|
-
export function beforeEach(fn) {
|
|
47
|
-
cases[0][beforeeach] = fn;
|
|
48
|
-
}
|
|
49
|
-
export function beforeAll(fn) {
|
|
50
|
-
cases[0][beforeall] = fn;
|
|
51
|
-
}
|
|
52
|
-
export function afterEach(fn) {
|
|
53
|
-
cases[0][aftereach] = fn;
|
|
54
|
-
}
|
|
55
|
-
export function afterAll(fn) {
|
|
56
|
-
cases[0][afterall] = fn;
|
|
57
|
-
}
|
|
58
|
-
export function cleanState(init, runner = beforeEach) {
|
|
59
|
-
return state.cleanState(init, runner);
|
|
60
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../../log.js";
|
|
2
|
-
import { getTotalCases } from "../describe.js";
|
|
3
|
-
import { flattenResults } from "../execute.js";
|
|
4
|
-
const logger = getLogger("Scope Test Runner");
|
|
5
|
-
export function onConsole(results) {
|
|
6
|
-
const { executed, failed } = results;
|
|
7
|
-
logger.info("Executed test suite.", {
|
|
8
|
-
executed,
|
|
9
|
-
total: getTotalCases(),
|
|
10
|
-
failed,
|
|
11
|
-
});
|
|
12
|
-
const flat = flattenResults(results);
|
|
13
|
-
for (const { test } of flat) {
|
|
14
|
-
logger.debug(test);
|
|
15
|
-
}
|
|
16
|
-
for (const { test, stack } of flat) {
|
|
17
|
-
if (stack) {
|
|
18
|
-
logger.error(test, { stack });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { isHTMLLogger, makeHTMLLogger } from "../../components/logger.js";
|
|
2
|
-
import { DEFAULT_LOGGER, LEVEL } from "../../log.js";
|
|
3
|
-
import { getTotalCases } from "../describe.js";
|
|
4
|
-
import { flattenResults } from "../execute.js";
|
|
5
|
-
export function displayStatistics(results, root = document.body) {
|
|
6
|
-
const { executed, failed } = results;
|
|
7
|
-
const logger = (() => {
|
|
8
|
-
try {
|
|
9
|
-
return makeHTMLLogger(`Executed ${executed} of ${getTotalCases()}; ${failed} failed.`);
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
return DEFAULT_LOGGER;
|
|
13
|
-
}
|
|
14
|
-
})();
|
|
15
|
-
logger.level = LEVEL.DEBUG;
|
|
16
|
-
const flat = flattenResults(results);
|
|
17
|
-
for (const { test, stack } of flat) {
|
|
18
|
-
if (stack) {
|
|
19
|
-
logger.info(test);
|
|
20
|
-
logger.debug(`${stack}`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (isHTMLLogger(logger)) {
|
|
24
|
-
root.appendChild(logger.root);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { xml } from "../../dom/xml.js";
|
|
2
|
-
import { flattenResults } from "../execute.js";
|
|
3
|
-
const cases = (results) => Object.entries(results).filter(([key]) => !["executed", "passed", "failed"].includes(key));
|
|
4
|
-
export function asXML(results) {
|
|
5
|
-
return (`<?xml version="1.0" encoding="UTF-8" ?>` +
|
|
6
|
-
xml("testsuites", { tests: results.executed, failures: results.failed }, cases(results).map(([title, children]) => testsuite(title, children.executed, children.failed, flattenResults(children)))));
|
|
7
|
-
}
|
|
8
|
-
function testsuite(name, tests, failures, cases) {
|
|
9
|
-
const id = name.replace("s+", "_");
|
|
10
|
-
return xml("testsuite", { id, name, tests, failures }, cases.map(({ test, stack }) => testcase({ name: `${name} ${test}` }, stack ? [stack] : [])));
|
|
11
|
-
}
|
|
12
|
-
function testcase({ name, id = name.replace(/\s+/g, "_"), time = "0.00", }, failures) {
|
|
13
|
-
return xml("testcase", { id, name, time }, failures.map((stack) => failure({ text: stack })));
|
|
14
|
-
}
|
|
15
|
-
function failure({ text, message = text.split("\n")[0], }) {
|
|
16
|
-
return xml("failure", { message }, [`<![CDATA[${text}]]>`]);
|
|
17
|
-
}
|