Skip to content

Commit 3a62bae

Browse files
committed
feat: add vitest for testing and update package versions across multiple packages
1 parent 4ecd0fa commit 3a62bae

File tree

15 files changed

+185
-13
lines changed

15 files changed

+185
-13
lines changed

packages/client/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"build": "tsc"
8+
"build": "tsc",
9+
"test": "vitest run"
910
},
1011
"dependencies": {
1112
"@objectstack/spec": "workspace:*",
1213
"@objectstack/core": "workspace:*"
1314
},
1415
"devDependencies": {
15-
"typescript": "^5.0.0"
16+
"typescript": "^5.0.0",
17+
"vitest": "^4.0.18"
1618
}
1719
}

packages/client/src/client.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, it, expect, vi } from 'vitest';
2+
import { ObjectStackClient } from './index';
3+
4+
describe('ObjectStackClient', () => {
5+
it('should initialize with correct configuration', () => {
6+
const client = new ObjectStackClient({ baseUrl: 'http://localhost:3000' });
7+
expect(client).toBeDefined();
8+
});
9+
10+
it('should normalize base URL', () => {
11+
const client: any = new ObjectStackClient({ baseUrl: 'http://localhost:3000/' });
12+
expect(client.baseUrl).toBe('http://localhost:3000');
13+
});
14+
15+
it('should make discovery request on connect', async () => {
16+
const fetchMock = vi.fn().mockResolvedValue({
17+
ok: true,
18+
json: async () => ({ routes: { data: '/api/v1/data' } })
19+
});
20+
21+
const client = new ObjectStackClient({
22+
baseUrl: 'http://localhost:3000',
23+
fetch: fetchMock
24+
});
25+
26+
await client.connect();
27+
expect(fetchMock).toHaveBeenCalledWith('http://localhost:3000/api/v1', expect.any(Object));
28+
});
29+
});

packages/client/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
"esModuleInterop": true,
1010
"skipLibCheck": true
1111
},
12-
"include": ["src/**/*"]
12+
"include": ["src/**/*"],
13+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
1314
}

packages/objectql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"build": "tsc",
9-
"test": "echo no tests"
9+
"test": "vitest run"
1010
},
1111
"dependencies": {
1212
"@objectstack/core": "workspace:*",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { SchemaRegistry } from './registry';
3+
4+
describe('SchemaRegistry', () => {
5+
it('should register and retrieve an item', () => {
6+
const item = { name: 'test_object', type: 'object' };
7+
8+
SchemaRegistry.registerItem('object', item, 'name');
9+
10+
const retrieved = SchemaRegistry.getItem('object', 'test_object');
11+
expect(retrieved).toEqual(item);
12+
});
13+
14+
it('should list items by type', () => {
15+
const item1 = { name: 'obj1' };
16+
const item2 = { name: 'obj2' };
17+
18+
SchemaRegistry.registerItem('object', item1, 'name');
19+
SchemaRegistry.registerItem('object', item2, 'name');
20+
21+
const items = SchemaRegistry.listItems('object');
22+
// Note: Registry is singleton, so it might contain previous test items or other items
23+
expect(items.length).toBeGreaterThanOrEqual(2);
24+
expect(items).toContainEqual(item1);
25+
expect(items).toContainEqual(item2);
26+
});
27+
});

packages/objectql/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33
"include": ["src/**/*"],
4-
"exclude": ["node_modules", "dist"],
4+
"exclude": ["node_modules", "dist", "**/*.test.ts"],
55
"compilerOptions": {
66
"outDir": "dist",
77
"rootDir": "src",

packages/plugins/plugin-hono-server/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"build": "tsc"
8+
"build": "tsc",
9+
"test": "vitest run"
910
},
1011
"dependencies": {
1112
"@hono/node-server": "^1.2.0",
@@ -16,6 +17,7 @@
1617
},
1718
"devDependencies": {
1819
"@types/node": "^25.1.0",
19-
"typescript": "^5.0.0"
20+
"typescript": "^5.0.0",
21+
"vitest": "^4.0.18"
2022
}
2123
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { HonoServerPlugin } from './hono-plugin';
3+
import { PluginContext } from '@objectstack/core';
4+
5+
describe('HonoServerPlugin', () => {
6+
let context: any;
7+
let logger: any;
8+
let protocol: any;
9+
10+
beforeEach(() => {
11+
logger = {
12+
info: vi.fn(),
13+
debug: vi.fn(),
14+
warn: vi.fn(),
15+
error: vi.fn()
16+
};
17+
18+
protocol = {
19+
findData: vi.fn(),
20+
createData: vi.fn()
21+
};
22+
23+
context = {
24+
logger,
25+
getService: vi.fn((service) => {
26+
if (service === 'protocol') return protocol;
27+
return null;
28+
}),
29+
registerService: vi.fn(),
30+
hook: vi.fn()
31+
};
32+
});
33+
34+
it('should initialize and register server', async () => {
35+
const plugin = new HonoServerPlugin();
36+
await plugin.init(context as PluginContext);
37+
38+
expect(context.registerService).toHaveBeenCalledWith('http-server', expect.anything());
39+
});
40+
41+
it('should register hook on start', async () => {
42+
const plugin = new HonoServerPlugin();
43+
await plugin.init(context as PluginContext);
44+
await plugin.start(context as PluginContext);
45+
46+
// Should wait for kernel:ready to start server
47+
expect(context.hook).toHaveBeenCalledWith('kernel:ready', expect.any(Function));
48+
});
49+
50+
it('should register CRUD routes', async () => {
51+
const plugin = new HonoServerPlugin();
52+
await plugin.init(context as PluginContext);
53+
await plugin.start(context as PluginContext);
54+
55+
expect(context.getService).toHaveBeenCalledWith('protocol');
56+
});
57+
});

packages/plugins/plugin-hono-server/src/hono-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface HonoPluginOptions {
1515
*/
1616
export class HonoServerPlugin implements Plugin {
1717
name = 'com.objectstack.server.hono';
18-
version = '1.0.0';
18+
version = '0.9.0';
1919

2020
private options: HonoPluginOptions;
2121
private server: HonoHttpServer;

packages/plugins/plugin-hono-server/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"declaration": true,
99
"outDir": "./dist"
1010
},
11-
"include": ["src/**/*"]
11+
"include": ["src/**/*"],
12+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
1213
}

0 commit comments

Comments
 (0)