@davidsouther/jiffies 1.0.0 → 1.1.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/build/assert.d.ts +23 -23
- package/build/assert.js +33 -33
- package/build/case.d.ts +1 -1
- package/build/case.js +5 -5
- package/build/components/button_bar.d.ts +8 -8
- package/build/components/button_bar.js +27 -27
- package/build/components/inline_edit.d.ts +12 -12
- package/build/components/inline_edit.js +48 -48
- package/build/components/logger.d.ts +6 -7
- package/build/components/logger.js +22 -22
- package/build/components/select.d.ts +13 -10
- package/build/components/select.js +3 -3
- package/build/components/test.d.ts +1 -1
- package/build/components/test.js +2 -2
- package/build/components/virtual_scroll.d.ts +40 -41
- package/build/components/virtual_scroll.js +94 -94
- package/build/components/virtual_scroll.test.d.ts +1 -1
- package/build/components/virtual_scroll.test.js +21 -21
- package/build/context.d.ts +15 -15
- package/build/context.js +43 -43
- package/build/context.test.d.ts +1 -1
- package/build/context.test.js +46 -46
- package/build/debounce.d.ts +1 -1
- package/build/debounce.js +7 -7
- package/build/display.d.ts +5 -5
- package/build/display.js +11 -11
- package/build/dom/css/border.d.ts +11 -11
- package/build/dom/css/border.js +27 -27
- package/build/dom/css/constants.d.ts +31 -31
- package/build/dom/css/constants.js +28 -28
- package/build/dom/css/core.d.ts +5 -5
- package/build/dom/css/core.js +24 -24
- package/build/dom/css/fstyle.d.ts +5 -5
- package/build/dom/css/fstyle.js +32 -32
- package/build/dom/css/sizing.d.ts +5 -5
- package/build/dom/css/sizing.js +10 -10
- package/build/dom/dom.d.ts +26 -27
- package/build/dom/dom.js +95 -95
- package/build/dom/fc.d.ts +14 -14
- package/build/dom/fc.js +36 -35
- package/build/dom/fc.test.d.ts +1 -1
- package/build/dom/fc.test.js +21 -21
- package/build/dom/form/form.app.d.ts +1 -1
- package/build/dom/form/form.app.js +23 -23
- package/build/dom/form/form.d.ts +26 -26
- package/build/dom/form/form.js +34 -34
- package/build/dom/form/form.test.js +1 -1
- package/build/dom/html.d.ts +113 -117
- package/build/dom/html.js +114 -114
- package/build/dom/html.test.d.ts +1 -1
- package/build/dom/html.test.js +58 -58
- package/build/dom/provide.d.ts +3 -3
- package/build/dom/provide.js +7 -7
- package/build/dom/router/link.d.ts +6 -6
- package/build/dom/router/link.js +3 -3
- package/build/dom/router/router.d.ts +12 -12
- package/build/dom/router/router.js +49 -49
- package/build/dom/svg.d.ts +64 -64
- package/build/dom/svg.js +65 -65
- package/build/dom/test.d.ts +1 -1
- package/build/dom/test.js +2 -2
- package/build/dom/types/css.d.ts +6612 -6612
- package/build/dom/types/css.js +23 -23
- package/build/dom/types/dom.js +1 -1
- package/build/dom/types/html.d.ts +616 -616
- package/build/dom/types/html.js +1 -1
- package/build/dom/xml.d.ts +1 -1
- package/build/dom/xml.js +4 -5
- package/build/equal.d.ts +5 -5
- package/build/equal.js +37 -37
- package/build/equal.test.d.ts +1 -1
- package/build/equal.test.js +20 -20
- package/build/flags.d.ts +7 -7
- package/build/flags.js +48 -48
- package/build/flags.test.d.ts +1 -1
- package/build/flags.test.js +35 -35
- package/build/fs.d.ts +48 -48
- package/build/fs.js +144 -144
- package/build/fs.test.d.ts +1 -1
- package/build/fs.test.js +43 -43
- package/build/generator.d.ts +1 -1
- package/build/generator.js +10 -10
- package/build/generator.test.d.ts +1 -1
- package/build/generator.test.js +24 -24
- package/build/is_browser.d.ts +1 -1
- package/build/is_browser.js +1 -1
- package/build/loader.d.mts +22 -22
- package/build/loader.mjs +35 -35
- package/build/lock.d.ts +1 -1
- package/build/lock.js +23 -23
- package/build/lock.test.d.ts +1 -1
- package/build/lock.test.js +16 -16
- package/build/log.d.ts +26 -26
- package/build/log.js +46 -46
- package/build/observable/observable.d.ts +83 -0
- package/build/observable/observable.js +148 -0
- package/build/observable/observable.test.d.ts +1 -0
- package/build/observable/observable.test.js +21 -0
- package/build/range.d.ts +1 -1
- package/build/range.js +7 -7
- package/build/result.d.ts +31 -31
- package/build/result.js +65 -65
- package/build/result.test.d.ts +1 -1
- package/build/result.test.js +71 -71
- package/build/safe.d.ts +1 -1
- package/build/safe.js +10 -10
- package/build/scope/describe.d.ts +18 -14
- package/build/scope/describe.js +61 -52
- package/build/scope/display/console.d.ts +2 -2
- package/build/scope/display/console.js +21 -21
- package/build/scope/display/dom.d.ts +3 -3
- package/build/scope/display/dom.js +26 -26
- package/build/scope/display/junit.d.ts +2 -2
- package/build/scope/display/junit.js +17 -17
- package/build/scope/execute.d.ts +12 -12
- package/build/scope/execute.js +85 -85
- package/build/scope/expect.d.ts +23 -23
- package/build/scope/expect.js +108 -108
- package/build/scope/fix.d.ts +4 -4
- package/build/scope/fix.js +22 -22
- package/build/scope/index.d.ts +3 -3
- package/build/scope/index.js +3 -3
- package/build/scope/scope.d.ts +17 -17
- package/build/scope/scope.js +1 -1
- package/build/server/http/apps.d.ts +5 -5
- package/build/server/http/apps.js +23 -23
- package/build/server/http/css.d.ts +5 -5
- package/build/server/http/css.js +50 -47
- package/build/server/http/index.d.ts +21 -21
- package/build/server/http/index.js +73 -73
- package/build/server/http/response.d.ts +4 -4
- package/build/server/http/response.js +40 -40
- package/build/server/http/sitemap.d.ts +2 -2
- package/build/server/http/sitemap.js +42 -42
- package/build/server/http/static.d.ts +2 -2
- package/build/server/http/static.js +21 -21
- package/build/server/http/typescript.d.ts +5 -5
- package/build/server/http/typescript.js +40 -40
- package/build/server/main.d.ts +2 -2
- package/build/server/main.js +9 -9
- package/build/test.d.mts +2 -2
- package/build/test.mjs +23 -23
- package/build/test_all.d.ts +7 -7
- package/build/test_all.js +18 -18
- package/build/transpile.d.mts +3 -3
- package/build/transpile.mjs +18 -18
- package/package.json +3 -3
- package/src/components/logger.ts +2 -3
- package/src/components/virtual_scroll.test.ts +4 -4
- package/src/components/virtual_scroll.ts +8 -8
- package/src/diff.test.ts +48 -0
- package/src/diff.ts +84 -0
- package/src/dom/dom.ts +73 -61
- package/src/dom/fc.ts +10 -9
- package/src/dom/html.test.ts +5 -5
- package/src/dom/html.ts +7 -10
- package/src/dom/observable.test.ts +43 -0
- package/src/dom/observable.ts +11 -0
- package/src/dom/router/router.ts +4 -4
- package/src/dom/test.ts +5 -1
- package/src/dom/xml.ts +1 -2
- package/src/index.html +6 -3
- package/src/observable/_notes +21 -8
- package/src/observable/event.ts +93 -0
- package/src/observable/observable.test.ts +73 -0
- package/src/observable/observable.ts +403 -0
- package/src/scope/describe.ts +14 -1
- package/src/scope/display/dom.ts +2 -2
- package/src/scope/execute.ts +2 -5
- package/src/server/http/css.ts +3 -1
- package/src/test_all.ts +10 -8
- package/src/observable/observable._js +0 -175
package/build/scope/execute.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { afterall, aftereach, beforeall, beforeeach, rootCases, } from "./describe.js";
|
|
2
|
-
export async function execute(prefix = "", cases = rootCases()) {
|
|
3
|
-
const beforeallfn = cases[beforeall] ?? (() => { });
|
|
4
|
-
const beforeeachfn = cases[beforeeach] ?? (() => { });
|
|
5
|
-
const afterallfn = cases[afterall] ?? (() => { });
|
|
6
|
-
const aftereachfn = cases[aftereach] ?? (() => { });
|
|
7
|
-
const result = { executed: 0, passed: 0, failed: 0, total: 0 };
|
|
8
|
-
try {
|
|
9
|
-
await beforeallfn();
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
result["_beforeAll"] = { error: e };
|
|
13
|
-
return result;
|
|
14
|
-
}
|
|
15
|
-
for (const [title, block] of Object.entries(cases)) {
|
|
16
|
-
if (typeof title === "symbol") {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
if (block instanceof Function) {
|
|
20
|
-
try {
|
|
21
|
-
result.executed += 1;
|
|
22
|
-
await beforeeachfn();
|
|
23
|
-
await block();
|
|
24
|
-
await aftereachfn();
|
|
25
|
-
result.passed += 1;
|
|
26
|
-
result[title] = { passed: true };
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
result.failed += 1;
|
|
30
|
-
result[title] = { error: /** @type Error */ e };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else if (block) {
|
|
34
|
-
const run = await execute(title, block);
|
|
35
|
-
result.executed += run.executed;
|
|
36
|
-
result.passed += run.passed;
|
|
37
|
-
result.failed += run.failed;
|
|
38
|
-
result[title] = run;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
await afterallfn();
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
result["_afterAll"] = { error: e };
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
export function getError({ error }) {
|
|
50
|
-
if (typeof error == "string") {
|
|
51
|
-
return error;
|
|
52
|
-
}
|
|
53
|
-
else if (error.message) {
|
|
54
|
-
return error.stack;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return "unknown error";
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function makeResult(test, result) {
|
|
61
|
-
if (result.error)
|
|
62
|
-
return [
|
|
63
|
-
{
|
|
64
|
-
test,
|
|
65
|
-
stack: getError(result),
|
|
66
|
-
stats: { executed: 1, failed: 1 },
|
|
67
|
-
},
|
|
68
|
-
];
|
|
69
|
-
if (result.passed === true) {
|
|
70
|
-
return [{ test, stats: { executed: 1, failed: 0 } }];
|
|
71
|
-
}
|
|
72
|
-
return flattenResults(result, test);
|
|
73
|
-
}
|
|
74
|
-
export function flattenResults(results, prefix = "") {
|
|
75
|
-
const arrow = prefix == "" ? "" : " -> ";
|
|
76
|
-
let errorList = [];
|
|
77
|
-
for (const [title, result] of Object.entries(results).filter(([key]) => !["executed", "passed", "failed"].includes(key))) {
|
|
78
|
-
const test = `${prefix}${arrow}${title}`;
|
|
79
|
-
if (typeof result == "number")
|
|
80
|
-
continue;
|
|
81
|
-
const flatResult = makeResult(test, result);
|
|
82
|
-
errorList = errorList.concat(flatResult);
|
|
83
|
-
}
|
|
84
|
-
return errorList;
|
|
85
|
-
}
|
|
1
|
+
import { afterall, aftereach, beforeall, beforeeach, rootCases, } from "./describe.js";
|
|
2
|
+
export async function execute(prefix = "", cases = rootCases()) {
|
|
3
|
+
const beforeallfn = cases[beforeall] ?? (() => { });
|
|
4
|
+
const beforeeachfn = cases[beforeeach] ?? (() => { });
|
|
5
|
+
const afterallfn = cases[afterall] ?? (() => { });
|
|
6
|
+
const aftereachfn = cases[aftereach] ?? (() => { });
|
|
7
|
+
const result = { executed: 0, passed: 0, failed: 0, total: 0 };
|
|
8
|
+
try {
|
|
9
|
+
await beforeallfn();
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
result["_beforeAll"] = { error: e };
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
for (const [title, block] of Object.entries(cases)) {
|
|
16
|
+
if (typeof title === "symbol") {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (block instanceof Function) {
|
|
20
|
+
try {
|
|
21
|
+
result.executed += 1;
|
|
22
|
+
await beforeeachfn();
|
|
23
|
+
await block();
|
|
24
|
+
await aftereachfn();
|
|
25
|
+
result.passed += 1;
|
|
26
|
+
result[title] = { passed: true };
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
result.failed += 1;
|
|
30
|
+
result[title] = { error: /** @type Error */ e };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (block) {
|
|
34
|
+
const run = await execute(title, block);
|
|
35
|
+
result.executed += run.executed;
|
|
36
|
+
result.passed += run.passed;
|
|
37
|
+
result.failed += run.failed;
|
|
38
|
+
result[title] = run;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
await afterallfn();
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
result["_afterAll"] = { error: e };
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
export function getError({ error }) {
|
|
50
|
+
if (typeof error == "string") {
|
|
51
|
+
return error;
|
|
52
|
+
}
|
|
53
|
+
else if (error.message) {
|
|
54
|
+
return error.stack;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return "unknown error";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function makeResult(test, result) {
|
|
61
|
+
if (result.error)
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
test,
|
|
65
|
+
stack: getError(result),
|
|
66
|
+
stats: { executed: 1, failed: 1 },
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
if (result.passed === true) {
|
|
70
|
+
return [{ test, stats: { executed: 1, failed: 0 } }];
|
|
71
|
+
}
|
|
72
|
+
return flattenResults(result, test);
|
|
73
|
+
}
|
|
74
|
+
export function flattenResults(results, prefix = "") {
|
|
75
|
+
const arrow = prefix == "" ? "" : " -> ";
|
|
76
|
+
let errorList = [];
|
|
77
|
+
for (const [title, result] of Object.entries(results).filter(([key]) => !["executed", "passed", "failed"].includes(key))) {
|
|
78
|
+
const test = `${prefix}${arrow}${title}`;
|
|
79
|
+
if (typeof result == "number")
|
|
80
|
+
continue;
|
|
81
|
+
const flatResult = makeResult(test, result);
|
|
82
|
+
errorList = errorList.concat(flatResult);
|
|
83
|
+
}
|
|
84
|
+
return errorList;
|
|
85
|
+
}
|
package/build/scope/expect.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export declare class Matcher<T> {
|
|
2
|
-
actual: T;
|
|
3
|
-
constructor(actual: T);
|
|
4
|
-
get not(): Matcher<T>;
|
|
5
|
-
toBe(expected: T): void;
|
|
6
|
-
toEqual(expected: T, partial?: boolean): void;
|
|
7
|
-
toMatch(expected: RegExp | string): void;
|
|
8
|
-
toMatchObject(expected: Partial<T>): void;
|
|
9
|
-
toBeNull(): void;
|
|
10
|
-
toThrow(message?: string): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class NotMatcher<T> {
|
|
13
|
-
actual: T;
|
|
14
|
-
constructor(actual: T);
|
|
15
|
-
get not(): Matcher<T>;
|
|
16
|
-
toBe(expected: T): void;
|
|
17
|
-
toEqual(expected: T): void;
|
|
18
|
-
toMatch(expected: RegExp | string): void;
|
|
19
|
-
toMatchObject(expected: Partial<T>): void;
|
|
20
|
-
toBeNull(): void;
|
|
21
|
-
toThrow(message?: string): void;
|
|
22
|
-
}
|
|
23
|
-
export declare function expect<T>(t: T): Matcher<T>;
|
|
1
|
+
export declare class Matcher<T> {
|
|
2
|
+
actual: T;
|
|
3
|
+
constructor(actual: T);
|
|
4
|
+
get not(): Matcher<T>;
|
|
5
|
+
toBe(expected: T): void;
|
|
6
|
+
toEqual(expected: T, partial?: boolean): void;
|
|
7
|
+
toMatch(expected: RegExp | string): void;
|
|
8
|
+
toMatchObject(expected: Partial<T>): void;
|
|
9
|
+
toBeNull(): void;
|
|
10
|
+
toThrow(message?: string): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class NotMatcher<T> {
|
|
13
|
+
actual: T;
|
|
14
|
+
constructor(actual: T);
|
|
15
|
+
get not(): Matcher<T>;
|
|
16
|
+
toBe(expected: T): void;
|
|
17
|
+
toEqual(expected: T): void;
|
|
18
|
+
toMatch(expected: RegExp | string): void;
|
|
19
|
+
toMatchObject(expected: Partial<T>): void;
|
|
20
|
+
toBeNull(): void;
|
|
21
|
+
toThrow(message?: string): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function expect<T>(t: T): Matcher<T>;
|
package/build/scope/expect.js
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { assert } from "../assert.js";
|
|
2
|
-
import { display } from "../display.js";
|
|
3
|
-
import { equals } from "../equal.js";
|
|
4
|
-
export class Matcher {
|
|
5
|
-
actual;
|
|
6
|
-
constructor(actual) {
|
|
7
|
-
this.actual = actual;
|
|
8
|
-
}
|
|
9
|
-
get not() {
|
|
10
|
-
return new NotMatcher(this.actual);
|
|
11
|
-
}
|
|
12
|
-
toBe(expected) {
|
|
13
|
-
assert(this.actual === expected, () => `${this.actual} !== ${expected}`);
|
|
14
|
-
}
|
|
15
|
-
toEqual(expected, partial = false) {
|
|
16
|
-
assert(equals(this.actual, expected, partial), () => `Objects are not equivalent: ${display(this.actual)}, ${display(expected)}`);
|
|
17
|
-
}
|
|
18
|
-
toMatch(expected) {
|
|
19
|
-
assert(typeof this.actual === "string", () => "Must have string for regexp match");
|
|
20
|
-
// @ts-expect-error
|
|
21
|
-
const actual = this.actual;
|
|
22
|
-
if (typeof expected === "string") {
|
|
23
|
-
assert(actual.includes(expected), () => `${actual} does not include ${expected}`);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
assert(expected.test(actual), () => `${actual} does not match ${expected}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
toMatchObject(expected) {
|
|
30
|
-
for (const [k, v] of Object.entries(expected)) {
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
const actual = this.actual[k];
|
|
33
|
-
assert(equals(actual, v, true), () => `Comparing ${k}, properties not equal: ${display(actual)}, ${display(v)}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
toBeNull() {
|
|
37
|
-
assert(this.actual === null, () => `Expected null, got ${JSON.stringify(this.actual)}`);
|
|
38
|
-
}
|
|
39
|
-
toThrow(message = "") {
|
|
40
|
-
let didThrow = false;
|
|
41
|
-
let result = undefined;
|
|
42
|
-
try {
|
|
43
|
-
// @ts-expect-error
|
|
44
|
-
result = this.actual();
|
|
45
|
-
}
|
|
46
|
-
catch ({ message: e }) {
|
|
47
|
-
assert(
|
|
48
|
-
// @ts-expect-error
|
|
49
|
-
(e ?? "").match(message), () => `Expected thrown message to match ${message}, got ${e}`);
|
|
50
|
-
didThrow = true;
|
|
51
|
-
}
|
|
52
|
-
assert(didThrow, () => `Expected throw but got ${JSON.stringify(result)}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export class NotMatcher {
|
|
56
|
-
actual;
|
|
57
|
-
constructor(actual) {
|
|
58
|
-
this.actual = actual;
|
|
59
|
-
}
|
|
60
|
-
get not() {
|
|
61
|
-
return new Matcher(this.actual);
|
|
62
|
-
}
|
|
63
|
-
toBe(expected) {
|
|
64
|
-
assert(this.actual !== expected, () => `${this.actual} === ${expected}`);
|
|
65
|
-
}
|
|
66
|
-
toEqual(expected) {
|
|
67
|
-
assert(!equals(this.actual, expected), () => `Objects are equivalent: ${JSON.stringify(this.actual)}, ${JSON.stringify(expected)}`);
|
|
68
|
-
}
|
|
69
|
-
toMatch(expected) {
|
|
70
|
-
assert(typeof this.actual === "string", () => "Must have string for regexp match");
|
|
71
|
-
// @ts-expect-error
|
|
72
|
-
const actual = this.actual;
|
|
73
|
-
if (typeof expected === "string") {
|
|
74
|
-
assert(!actual.includes(expected), () => `${actual} includes ${expected}`);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
assert(!expected.test(actual), () => `${actual} matches ${expected}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
toMatchObject(expected) {
|
|
81
|
-
for (const [k, v] of Object.entries(expected)) {
|
|
82
|
-
// @ts-expect-error
|
|
83
|
-
const actual = this.actual[k];
|
|
84
|
-
assert(!equals(actual, v), () => `Comparing ${k}, properties equal: ${JSON.stringify(actual)}, ${JSON.stringify(v)}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
toBeNull() {
|
|
88
|
-
assert(this.actual !== null, () => `Expected not null`);
|
|
89
|
-
}
|
|
90
|
-
toThrow(message = "") {
|
|
91
|
-
let didThrow = false;
|
|
92
|
-
let result = undefined;
|
|
93
|
-
try {
|
|
94
|
-
// @ts-expect-error
|
|
95
|
-
result = this.actual();
|
|
96
|
-
}
|
|
97
|
-
catch ({ message: e }) {
|
|
98
|
-
assert(
|
|
99
|
-
// @ts-expect-error
|
|
100
|
-
(e ?? "").match(message), () => `Expected thrown message to match ${message}, got ${e}`);
|
|
101
|
-
didThrow = true;
|
|
102
|
-
}
|
|
103
|
-
assert(!didThrow, () => `Expected throw but got ${JSON.stringify(result)}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
export function expect(t) {
|
|
107
|
-
return new Matcher(t);
|
|
108
|
-
}
|
|
1
|
+
import { assert } from "../assert.js";
|
|
2
|
+
import { display } from "../display.js";
|
|
3
|
+
import { equals } from "../equal.js";
|
|
4
|
+
export class Matcher {
|
|
5
|
+
actual;
|
|
6
|
+
constructor(actual) {
|
|
7
|
+
this.actual = actual;
|
|
8
|
+
}
|
|
9
|
+
get not() {
|
|
10
|
+
return new NotMatcher(this.actual);
|
|
11
|
+
}
|
|
12
|
+
toBe(expected) {
|
|
13
|
+
assert(this.actual === expected, () => `${this.actual} !== ${expected}`);
|
|
14
|
+
}
|
|
15
|
+
toEqual(expected, partial = false) {
|
|
16
|
+
assert(equals(this.actual, expected, partial), () => `Objects are not equivalent: ${display(this.actual)}, ${display(expected)}`);
|
|
17
|
+
}
|
|
18
|
+
toMatch(expected) {
|
|
19
|
+
assert(typeof this.actual === "string", () => "Must have string for regexp match");
|
|
20
|
+
// @ts-expect-error
|
|
21
|
+
const actual = this.actual;
|
|
22
|
+
if (typeof expected === "string") {
|
|
23
|
+
assert(actual.includes(expected), () => `${actual} does not include ${expected}`);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
assert(expected.test(actual), () => `${actual} does not match ${expected}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
toMatchObject(expected) {
|
|
30
|
+
for (const [k, v] of Object.entries(expected)) {
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
const actual = this.actual[k];
|
|
33
|
+
assert(equals(actual, v, true), () => `Comparing ${k}, properties not equal: ${display(actual)}, ${display(v)}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
toBeNull() {
|
|
37
|
+
assert(this.actual === null, () => `Expected null, got ${JSON.stringify(this.actual)}`);
|
|
38
|
+
}
|
|
39
|
+
toThrow(message = "") {
|
|
40
|
+
let didThrow = false;
|
|
41
|
+
let result = undefined;
|
|
42
|
+
try {
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
result = this.actual();
|
|
45
|
+
}
|
|
46
|
+
catch ({ message: e }) {
|
|
47
|
+
assert(
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
(e ?? "").match(message), () => `Expected thrown message to match ${message}, got ${e}`);
|
|
50
|
+
didThrow = true;
|
|
51
|
+
}
|
|
52
|
+
assert(didThrow, () => `Expected throw but got ${JSON.stringify(result)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class NotMatcher {
|
|
56
|
+
actual;
|
|
57
|
+
constructor(actual) {
|
|
58
|
+
this.actual = actual;
|
|
59
|
+
}
|
|
60
|
+
get not() {
|
|
61
|
+
return new Matcher(this.actual);
|
|
62
|
+
}
|
|
63
|
+
toBe(expected) {
|
|
64
|
+
assert(this.actual !== expected, () => `${this.actual} === ${expected}`);
|
|
65
|
+
}
|
|
66
|
+
toEqual(expected) {
|
|
67
|
+
assert(!equals(this.actual, expected), () => `Objects are equivalent: ${JSON.stringify(this.actual)}, ${JSON.stringify(expected)}`);
|
|
68
|
+
}
|
|
69
|
+
toMatch(expected) {
|
|
70
|
+
assert(typeof this.actual === "string", () => "Must have string for regexp match");
|
|
71
|
+
// @ts-expect-error
|
|
72
|
+
const actual = this.actual;
|
|
73
|
+
if (typeof expected === "string") {
|
|
74
|
+
assert(!actual.includes(expected), () => `${actual} includes ${expected}`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
assert(!expected.test(actual), () => `${actual} matches ${expected}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
toMatchObject(expected) {
|
|
81
|
+
for (const [k, v] of Object.entries(expected)) {
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
const actual = this.actual[k];
|
|
84
|
+
assert(!equals(actual, v), () => `Comparing ${k}, properties equal: ${JSON.stringify(actual)}, ${JSON.stringify(v)}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
toBeNull() {
|
|
88
|
+
assert(this.actual !== null, () => `Expected not null`);
|
|
89
|
+
}
|
|
90
|
+
toThrow(message = "") {
|
|
91
|
+
let didThrow = false;
|
|
92
|
+
let result = undefined;
|
|
93
|
+
try {
|
|
94
|
+
// @ts-expect-error
|
|
95
|
+
result = this.actual();
|
|
96
|
+
}
|
|
97
|
+
catch ({ message: e }) {
|
|
98
|
+
assert(
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
(e ?? "").match(message), () => `Expected thrown message to match ${message}, got ${e}`);
|
|
101
|
+
didThrow = true;
|
|
102
|
+
}
|
|
103
|
+
assert(!didThrow, () => `Expected throw but got ${JSON.stringify(result)}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function expect(t) {
|
|
107
|
+
return new Matcher(t);
|
|
108
|
+
}
|
package/build/scope/fix.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Given a value with numbers, attempt to fix all numbers to 1 decimal point.
|
|
3
|
-
*/
|
|
4
|
-
export declare function fix<T>(n: T): T;
|
|
1
|
+
/**
|
|
2
|
+
* Given a value with numbers, attempt to fix all numbers to 1 decimal point.
|
|
3
|
+
*/
|
|
4
|
+
export declare function fix<T>(n: T): T;
|
package/build/scope/fix.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Given a value with numbers, attempt to fix all numbers to 1 decimal point.
|
|
3
|
-
*/
|
|
4
|
-
export function fix(n) {
|
|
5
|
-
if (typeof n === "number") {
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
return +n.toFixed(1);
|
|
8
|
-
}
|
|
9
|
-
if (n !== Object(n)) {
|
|
10
|
-
// A primitive
|
|
11
|
-
return n;
|
|
12
|
-
}
|
|
13
|
-
if (n instanceof Array) {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
return n.map(fix);
|
|
16
|
-
}
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
return mapreduce(fix, n);
|
|
19
|
-
}
|
|
20
|
-
function mapreduce(fn, iter) {
|
|
21
|
-
return Object.entries(iter).reduce((acc, [k, v]) => ((acc[k] = fn(v)), acc), {});
|
|
22
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Given a value with numbers, attempt to fix all numbers to 1 decimal point.
|
|
3
|
+
*/
|
|
4
|
+
export function fix(n) {
|
|
5
|
+
if (typeof n === "number") {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
return +n.toFixed(1);
|
|
8
|
+
}
|
|
9
|
+
if (n !== Object(n)) {
|
|
10
|
+
// A primitive
|
|
11
|
+
return n;
|
|
12
|
+
}
|
|
13
|
+
if (n instanceof Array) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
return n.map(fix);
|
|
16
|
+
}
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
return mapreduce(fix, n);
|
|
19
|
+
}
|
|
20
|
+
function mapreduce(fn, iter) {
|
|
21
|
+
return Object.entries(iter).reduce((acc, [k, v]) => ((acc[k] = fn(v)), acc), {});
|
|
22
|
+
}
|
package/build/scope/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { expect } from "./expect.js";
|
|
2
|
-
export { fix } from "./fix.js";
|
|
3
|
-
export { afterAll, afterEach, beforeAll, beforeEach, cleanState, describe, it, } from "./describe.js";
|
|
1
|
+
export { expect } from "./expect.js";
|
|
2
|
+
export { fix } from "./fix.js";
|
|
3
|
+
export { afterAll, afterEach, beforeAll, beforeEach, cleanState, describe, it, } from "./describe.js";
|
package/build/scope/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { expect } from "./expect.js";
|
|
2
|
-
export { fix } from "./fix.js";
|
|
3
|
-
export { afterAll, afterEach, beforeAll, beforeEach, cleanState, describe, it, } from "./describe.js";
|
|
1
|
+
export { expect } from "./expect.js";
|
|
2
|
+
export { fix } from "./fix.js";
|
|
3
|
+
export { afterAll, afterEach, beforeAll, beforeEach, cleanState, describe, it, } from "./describe.js";
|
package/build/scope/scope.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export interface TestCase {
|
|
2
|
-
[k: string]: Function | TestCase;
|
|
3
|
-
[k: symbol]: Function;
|
|
4
|
-
}
|
|
5
|
-
export interface TestResult {
|
|
6
|
-
executed: number;
|
|
7
|
-
passed: number;
|
|
8
|
-
failed: number;
|
|
9
|
-
[k: string]: TestResult | TestSummary | number;
|
|
10
|
-
}
|
|
11
|
-
export declare type TestSummary = TestFailed | TestPassed;
|
|
12
|
-
export interface TestFailed {
|
|
13
|
-
error: unknown;
|
|
14
|
-
}
|
|
15
|
-
export interface TestPassed {
|
|
16
|
-
passed: true;
|
|
17
|
-
}
|
|
1
|
+
export interface TestCase {
|
|
2
|
+
[k: string]: Function | TestCase;
|
|
3
|
+
[k: symbol]: Function;
|
|
4
|
+
}
|
|
5
|
+
export interface TestResult {
|
|
6
|
+
executed: number;
|
|
7
|
+
passed: number;
|
|
8
|
+
failed: number;
|
|
9
|
+
[k: string]: TestResult | TestSummary | number;
|
|
10
|
+
}
|
|
11
|
+
export declare type TestSummary = TestFailed | TestPassed;
|
|
12
|
+
export interface TestFailed {
|
|
13
|
+
error: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface TestPassed {
|
|
16
|
+
passed: true;
|
|
17
|
+
}
|
package/build/scope/scope.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MiddlewareFactory } from "./index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Searches up the request path until the first index is found.
|
|
4
|
-
*/
|
|
5
|
-
export declare const findIndex: MiddlewareFactory;
|
|
1
|
+
import { MiddlewareFactory } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Searches up the request path until the first index is found.
|
|
4
|
+
*/
|
|
5
|
+
export declare const findIndex: MiddlewareFactory;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import * as fs from "fs/promises";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { fileResponse } from "./response.js";
|
|
4
|
-
/**
|
|
5
|
-
* Searches up the request path until the first index is found.
|
|
6
|
-
*/
|
|
7
|
-
export const findIndex = async ({ root }) => async (req) => {
|
|
8
|
-
let filename = path.join(root, req.url ?? "");
|
|
9
|
-
if (path.basename(filename).match(/\.[a-z]{1,3}$/)) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
while (filename.startsWith(root)) {
|
|
13
|
-
const index = path.join(filename, "index.html");
|
|
14
|
-
try {
|
|
15
|
-
const stat = await fs.stat(index);
|
|
16
|
-
return fileResponse(index, stat);
|
|
17
|
-
}
|
|
18
|
-
catch (e) {
|
|
19
|
-
filename = path.dirname(filename);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
};
|
|
1
|
+
import * as fs from "fs/promises";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { fileResponse } from "./response.js";
|
|
4
|
+
/**
|
|
5
|
+
* Searches up the request path until the first index is found.
|
|
6
|
+
*/
|
|
7
|
+
export const findIndex = async ({ root }) => async (req) => {
|
|
8
|
+
let filename = path.join(root, req.url ?? "");
|
|
9
|
+
if (path.basename(filename).match(/\.[a-z]{1,3}$/)) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
while (filename.startsWith(root)) {
|
|
13
|
+
const index = path.join(filename, "index.html");
|
|
14
|
+
try {
|
|
15
|
+
const stat = await fs.stat(index);
|
|
16
|
+
return fileResponse(index, stat);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
filename = path.dirname(filename);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MiddlewareFactory } from "./index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Serves .css files statically. Finds .sass files and transpiles them to css.
|
|
4
|
-
*/
|
|
5
|
-
export declare const cssFileServer: MiddlewareFactory;
|
|
1
|
+
import { MiddlewareFactory } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Serves .css files statically. Finds .sass files and transpiles them to css.
|
|
4
|
+
*/
|
|
5
|
+
export declare const cssFileServer: MiddlewareFactory;
|