Skip to content

Commit ca7b661

Browse files
committed
Switched to coverage with instanbul because it can ignore type-only modules; more types test
1 parent 92ce571 commit ca7b661

File tree

11 files changed

+377
-52
lines changed

11 files changed

+377
-52
lines changed

chartlets.js/package-lock.json

Lines changed: 290 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chartlets.js/packages/demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@typescript-eslint/eslint-plugin": "^7.18.0",
4444
"@typescript-eslint/parser": "^7.18.0",
4545
"@vitejs/plugin-react-swc": "^3.7.0",
46-
"@vitest/coverage-v8": "^2.1.1",
46+
"@vitest/coverage-istanbul": "^2.1.8",
4747
"eslint": "^8.57.1",
4848
"eslint-plugin-react-hooks": "^4.6.2",
4949
"eslint-plugin-react-refresh": "^0.4.12",

chartlets.js/packages/lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"@typescript-eslint/eslint-plugin": "^7.18.0",
8383
"@typescript-eslint/parser": "^7.18.0",
8484
"@vitejs/plugin-react-swc": "^3.7.0",
85-
"@vitest/coverage-v8": "^2.1.1",
85+
"@vitest/coverage-istanbul": "^2.1.8",
8686
"canvas": "^2.11.2",
8787
"eslint": "^8.57.1",
8888
"eslint-plugin-react-hooks": "^4.6.2",

chartlets.js/packages/lib/src/component/Children.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ describe("Children", () => {
1818
// Note, the following 3 lines test that document is empty
1919
// but there is always one empty "div" in it.
2020
expect(document.body.firstElementChild).not.toBe(null);
21-
expect(document.body.firstElementChild.tagName).toBe("DIV");
22-
expect(document.body.firstElementChild.firstElementChild).toBe(null);
21+
expect(document.body.firstElementChild!.tagName).toBe("DIV");
22+
expect(document.body.firstElementChild!.firstElementChild).toBe(null);
2323
}
2424

2525
it("should not render undefined nodes", () => {
@@ -33,13 +33,13 @@ describe("Children", () => {
3333
});
3434

3535
it("should render all child types", () => {
36-
const Div: FC<ComponentProps & { text: string }> = ({ text }) => (
37-
<div>{text}</div>
38-
);
39-
registry.register("Div", Div);
36+
interface DivProps extends ComponentProps {
37+
text: string;
38+
}
39+
const Div: FC<DivProps> = ({ text }) => <div>{text}</div>;
40+
registry.register("Div", Div as FC<ComponentProps>);
4041
const divProps = {
4142
type: "Div",
42-
id: "root",
4343
text: "Hello",
4444
onChange: () => {},
4545
};

chartlets.js/packages/lib/src/component/Component.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ describe("Component", () => {
2727
});
2828

2929
it("should render a known component", () => {
30-
const Div: FC<ComponentProps & { text: string }> = ({ text }) => (
31-
<div>{text}</div>
32-
);
33-
registry.register("Div", Div);
30+
interface DivProps extends ComponentProps {
31+
text: string;
32+
}
33+
const Div: FC<DivProps> = ({ text }) => <div>{text}</div>;
34+
registry.register("Div", Div as FC<ComponentProps>);
3435
const divProps = {
3536
type: "Div",
3637
id: "root",

chartlets.js/packages/lib/src/plugins/mui/Box.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from "vitest";
22
import { render, screen } from "@testing-library/react";
3-
import { Box } from "./Box";
43
import type { ComponentChangeHandler } from "@/types/state/event";
4+
import { Box } from "./Box";
55

66
describe("Box", () => {
77
it("should render the Box component", () => {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, it, expect } from "vitest";
2+
import {
3+
isComponentChannel,
4+
isContainerChannel,
5+
isHostChannel,
6+
} from "./channel";
7+
8+
describe("Test that isComponentChannel()", () => {
9+
it("works", () => {
10+
expect(isComponentChannel({ id: "ok_btn", property: "checked" })).toBe(
11+
true,
12+
);
13+
expect(isComponentChannel({ id: "@container", property: "visible" })).toBe(
14+
false,
15+
);
16+
expect(
17+
isComponentChannel({ id: "@app", property: "selectedDatasetId" }),
18+
).toBe(false);
19+
});
20+
});
21+
22+
describe("Test that isContainerChannel()", () => {
23+
it("works", () => {
24+
expect(isContainerChannel({ id: "ok_btn", property: "checked" })).toBe(
25+
false,
26+
);
27+
expect(isContainerChannel({ id: "@container", property: "visible" })).toBe(
28+
true,
29+
);
30+
expect(
31+
isContainerChannel({ id: "@app", property: "selectedDatasetId" }),
32+
).toBe(false);
33+
});
34+
});
35+
36+
describe("Test that isHostChannel()", () => {
37+
it("works", () => {
38+
expect(isHostChannel({ id: "ok_btn", property: "checked" })).toBe(false);
39+
expect(isHostChannel({ id: "@container", property: "visible" })).toBe(
40+
false,
41+
);
42+
expect(isHostChannel({ id: "@app", property: "selectedDatasetId" })).toBe(
43+
true,
44+
);
45+
});
46+
});

chartlets.js/packages/lib/src/types/state/component.test.ts renamed to chartlets.js/packages/lib/src/types/state/component.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ describe("isComponentState", () => {
88
expect(isComponentState({})).toBe(false);
99
expect(isComponentState("Button")).toBe(false);
1010
expect(isComponentState({ type: 2 })).toBe(false);
11+
expect(isComponentState(new Event("click"))).toBe(false);
12+
expect(isComponentState(<span />)).toBe(false);
1113
});
1214
});
1315

@@ -18,5 +20,7 @@ describe("isContainerState", () => {
1820
expect(isContainerState({})).toBe(false);
1921
expect(isContainerState("Button")).toBe(false);
2022
expect(isContainerState({ type: 2 })).toBe(false);
23+
expect(isComponentState(new Event("click"))).toBe(false);
24+
expect(isComponentState(<span />)).toBe(false);
2125
});
2226
});

chartlets.js/packages/lib/src/types/state/component.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@ import { type CSSProperties } from "react";
22
import { isObject } from "@/utils/isObject";
33
import { isString } from "@/utils/isString";
44

5-
export type ComponentType =
6-
| "Box"
7-
| "Button"
8-
| "Checkbox"
9-
| "Plot"
10-
| "Select"
11-
| "Typography";
12-
135
export type ComponentNode =
146
| ComponentState
157
| string
@@ -38,7 +30,14 @@ export interface ContainerState extends ComponentState {
3830
}
3931

4032
export function isComponentState(object: unknown): object is ComponentState {
41-
return isObject(object) && isString(object.type);
33+
return (
34+
isObject(object) &&
35+
isString(object.type) &&
36+
// objects that are not created from classes
37+
object.constructor.name === "Object" &&
38+
// not React elements
39+
!object["$$typeof"]
40+
);
4241
}
4342

4443
export function isContainerState(object: unknown): object is ContainerState {

chartlets.js/packages/lib/src/types/state/options.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import { describe, it, expect } from "vitest";
2-
import { isMutableHostStore } from "./options";
2+
import {
3+
type HostStore,
4+
type MutableHostStore,
5+
isHostStore,
6+
isMutableHostStore,
7+
} from "./options";
38

4-
const hostStore = {
9+
const hostStore: HostStore = {
510
get: (name: string) => name,
611
subscribe: (_cb: () => void) => {},
712
};
813

9-
const mutableHostStore = {
14+
const mutableHostStore: MutableHostStore = {
1015
...hostStore,
1116
set: (_name: string, _value: unknown) => {},
1217
};
1318

1419
describe("isHostStore", () => {
1520
it("should work", () => {
16-
expect(isMutableHostStore({})).toBe(false);
17-
expect(isMutableHostStore(hostStore)).toBe(true);
18-
expect(isMutableHostStore(mutableHostStore)).toBe(true);
21+
expect(isHostStore({})).toBe(false);
22+
expect(isHostStore(hostStore)).toBe(true);
23+
expect(isHostStore(mutableHostStore)).toBe(true);
1924
});
2025
});
2126

0 commit comments

Comments
 (0)