Skip to content

Commit a8cc9d9

Browse files
committed
test(roam): run vitest in ci
1 parent 7aa6e70 commit a8cc9d9

8 files changed

Lines changed: 144 additions & 98 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Check TypeScript Types
3535
run: npx turbo check-types
3636

37+
- name: Run Tests
38+
run: npx turbo run test --filter=roam --ui stream
39+
3740
lint-changed-files:
3841
if: github.event_name == 'pull_request'
3942
runs-on: ubuntu-latest

apps/roam/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"lint:fix": "eslint . --fix",
1111
"publish": "tsx scripts/publish.ts",
1212
"check-types": "tsc --noEmit --skipLibCheck",
13-
"test": "vitest run src/utils/__tests__",
14-
"test:watch": "vitest src/utils/__tests__"
13+
"test": "vitest run --config vitest.config.mts",
14+
"test:watch": "vitest --config vitest.config.mts"
1515
},
1616
"license": "Apache-2.0",
1717
"devDependencies": {
@@ -21,6 +21,7 @@
2121
"@repo/typescript-config": "workspace:*",
2222
"@types/file-saver": "2.0.5",
2323
"@types/nanoid": "2.0.0",
24+
"@types/node": "^20",
2425
"@types/react": "catalog:roam",
2526
"@types/react-dom": "catalog:roam",
2627
"@types/react-vertical-timeline-component": "^3.3.3",

apps/roam/src/utils/__tests__/datalogUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("replaceDatalogVariables", () => {
7272
[
7373
{
7474
type: "fn-expr",
75-
fn: "identity",
75+
fn: "get",
7676
arguments: [{ type: "variable", value: "node" }],
7777
binding: {
7878
type: "bind-scalar",

apps/roam/src/utils/__tests__/fireQuery.test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { beforeEach, describe, expect, it, vi } from "vitest";
22

3+
type ConditionToDatalogArgs = {
4+
source: string;
5+
target: string;
6+
};
7+
38
vi.mock("~/utils/conditionToDatalog", () => ({
4-
default: vi.fn(({ source, target }) => [
9+
default: vi.fn(({ source, target }: ConditionToDatalogArgs) => [
510
{
611
type: "data-pattern",
712
arguments: [
@@ -73,15 +78,21 @@ describe("fireQuery", () => {
7378
q: vi
7479
.fn()
7580
.mockResolvedValue([
76-
[{ ":node/title": "Local", ":block/uid": "l1" }],
81+
[
82+
{ ":node/title": "Local", ":block/uid": "l1" },
83+
{ ":block/uid": "l1" },
84+
],
7785
]),
7886
},
7987
},
8088
backend: {
8189
q: vi
8290
.fn()
8391
.mockResolvedValue([
84-
[{ ":node/title": "Remote", ":block/uid": "r1" }],
92+
[
93+
{ ":node/title": "Remote", ":block/uid": "r1" },
94+
{ ":block/uid": "r1" },
95+
],
8596
]),
8697
},
8798
fast: {

apps/roam/src/utils/__tests__/queryParsing.test.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import { beforeEach, describe, expect, it, vi } from "vitest";
22

3+
type SettingsTreeNode = {
4+
text: string;
5+
children?: SettingsTreeNode[];
6+
};
7+
8+
type GetSettingValueArgs = {
9+
tree?: SettingsTreeNode[];
10+
key: string;
11+
};
12+
313
vi.mock("roamjs-components/util/getSubTree", () => ({
414
default: vi.fn(),
515
}));
616
vi.mock("roamjs-components/util/getSettingValueFromTree", () => ({
717
default: vi.fn(
8-
({ tree, key }) =>
18+
({ tree = [], key }: GetSettingValueArgs): string =>
919
tree.find((t: { text: string }) => t.text === key)?.children?.[0]?.text ||
1020
"",
1121
),
@@ -42,23 +52,36 @@ describe("parseQuery", () => {
4252
],
4353
};
4454
mockedGetSubTree.mockImplementation(({ key }) => {
45-
if (key === "conditions") return { uid: "conditions-uid", children: [] };
55+
if (key === "conditions") {
56+
return { uid: "conditions-uid", text: "conditions", children: [] };
57+
}
4658
if (key === "selections") {
4759
return {
4860
uid: "selections-uid",
61+
text: "selections",
4962
children: [
50-
{ uid: "sel-node", text: "node", children: [{ text: "Title" }] },
63+
{
64+
uid: "sel-node",
65+
text: "node",
66+
children: [{ uid: "title-label", text: "Title", children: [] }],
67+
},
5168
{
5269
uid: "sel-created",
5370
text: "created",
54-
children: [{ text: "Created" }],
71+
children: [
72+
{ uid: "created-label", text: "Created", children: [] },
73+
],
5574
},
5675
],
5776
};
5877
}
5978
return {
6079
uid: "custom-uid",
61-
children: [{ text: "[:find ?x]" }, { text: "enabled" }],
80+
text: "custom",
81+
children: [
82+
{ uid: "custom-query", text: "[:find ?x]", children: [] },
83+
{ uid: "custom-enabled", text: "enabled", children: [] },
84+
],
6285
};
6386
});
6487

apps/roam/vitest.config.mts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import path from "node:path";
2+
import { fileURLToPath } from "node:url";
3+
import { defineConfig } from "vitest/config";
4+
5+
const dirname = path.dirname(fileURLToPath(import.meta.url));
6+
7+
export default defineConfig({
8+
test: {
9+
environment: "node",
10+
include: ["src/utils/__tests__/**/*.test.ts"],
11+
},
12+
resolve: {
13+
alias: {
14+
"~": path.resolve(dirname, "src"),
15+
},
16+
},
17+
});

0 commit comments

Comments
 (0)