oof
This commit is contained in:
6
web/test/__mocks__/drizzle-orm-libsql-migrator.js
Normal file
6
web/test/__mocks__/drizzle-orm-libsql-migrator.js
Normal file
@@ -0,0 +1,6 @@
|
||||
function migrate() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
export { migrate };
|
||||
export default { migrate };
|
||||
23
web/test/__mocks__/drizzle-orm-libsql.js
Normal file
23
web/test/__mocks__/drizzle-orm-libsql.js
Normal file
@@ -0,0 +1,23 @@
|
||||
function drizzle() {
|
||||
return {
|
||||
select: () => ({
|
||||
from: () => ({
|
||||
where: () => ({ limit: () => Promise.resolve([]) }),
|
||||
}),
|
||||
}),
|
||||
insert: () => ({
|
||||
values: () => ({ returning: () => Promise.resolve([{ id: "mock-id" }]) }),
|
||||
}),
|
||||
update: () => ({
|
||||
set: () => ({
|
||||
where: () => ({ returning: () => Promise.resolve([{ id: "mock-id" }]) }),
|
||||
}),
|
||||
}),
|
||||
delete: () => ({
|
||||
where: () => ({ returning: () => Promise.resolve([]) }),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export { drizzle };
|
||||
export default { drizzle };
|
||||
95
web/test/__mocks__/drizzle-orm-sqlite-core.js
Normal file
95
web/test/__mocks__/drizzle-orm-sqlite-core.js
Normal file
@@ -0,0 +1,95 @@
|
||||
// drizzle-orm/sqlite-core mock - captures column info
|
||||
const tableRegistry = new Map();
|
||||
|
||||
function createColumn(name) {
|
||||
let self;
|
||||
const handler = {
|
||||
get(target, prop) {
|
||||
if (prop === 'name') return name;
|
||||
if (prop === '_isColumn') return true;
|
||||
if (prop === Symbol.toStringTag) return 'Object';
|
||||
return function() { return self; };
|
||||
},
|
||||
apply() { return self; },
|
||||
};
|
||||
self = new Proxy(function colFn() { return self; }, handler);
|
||||
return self;
|
||||
}
|
||||
|
||||
const allColumns = [];
|
||||
|
||||
function sqliteTable(tableName, schema, indexesFn) {
|
||||
// Collect columns from schema object
|
||||
const columns = [];
|
||||
if (schema && typeof schema === "object") {
|
||||
for (const key of Object.keys(schema)) {
|
||||
const col = schema[key];
|
||||
if (col && typeof col === "function" && col.name !== undefined) {
|
||||
columns.push({ name: col.name });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect indexes from third argument
|
||||
const indexes = [];
|
||||
if (indexesFn && typeof indexesFn === "function") {
|
||||
const idxDefs = indexesFn({});
|
||||
if (idxDefs && typeof idxDefs === "object") {
|
||||
for (const key of Object.keys(idxDefs)) {
|
||||
indexes.push({ name: key });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const table = {
|
||||
drizzleName: tableName,
|
||||
_columns: columns,
|
||||
_indexes: indexes,
|
||||
};
|
||||
tableRegistry.set(tableName, table);
|
||||
return table;
|
||||
}
|
||||
|
||||
function textFn(name) {
|
||||
const col = createColumn(name);
|
||||
allColumns.push(col);
|
||||
return col;
|
||||
}
|
||||
|
||||
function integerFn(name) {
|
||||
const col = createColumn(name);
|
||||
allColumns.push(col);
|
||||
return col;
|
||||
}
|
||||
|
||||
function realFn(name) {
|
||||
const col = createColumn(name);
|
||||
allColumns.push(col);
|
||||
return col;
|
||||
}
|
||||
|
||||
function createChainable() {
|
||||
let self;
|
||||
self = new Proxy(function fn() { return self; }, {
|
||||
get() { return self; },
|
||||
apply() { return self; },
|
||||
});
|
||||
return self;
|
||||
}
|
||||
|
||||
const uniqueIndex = createChainable();
|
||||
const index = createChainable();
|
||||
const pgTable = createChainable();
|
||||
|
||||
function getTableConfig(table) {
|
||||
const name = table?.drizzleName || "";
|
||||
const registered = tableRegistry.get(name);
|
||||
return {
|
||||
name,
|
||||
schema: undefined,
|
||||
columns: registered?._columns || [],
|
||||
indexes: registered?._indexes || [],
|
||||
};
|
||||
}
|
||||
|
||||
export { sqliteTable, pgTable, textFn as text, integerFn as integer, realFn as real, uniqueIndex, index, getTableConfig };
|
||||
28
web/test/__mocks__/drizzle-orm.js
Normal file
28
web/test/__mocks__/drizzle-orm.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// drizzle-orm mock - chainable proxies
|
||||
function createChainable() {
|
||||
return new Proxy(function() {}, {
|
||||
apply() { return createChainable(); },
|
||||
get() { return createChainable(); },
|
||||
});
|
||||
}
|
||||
|
||||
const eq = createChainable();
|
||||
const and = createChainable();
|
||||
const or = createChainable();
|
||||
const not = createChainable();
|
||||
const inArray = createChainable();
|
||||
const gte = createChainable();
|
||||
const lte = createChainable();
|
||||
const gt = createChainable();
|
||||
const lt = createChainable();
|
||||
const like = createChainable();
|
||||
const ilike = createChainable();
|
||||
const isNull = createChainable();
|
||||
const isNotNull = createChainable();
|
||||
const desc = createChainable();
|
||||
const asc = createChainable();
|
||||
const count = createChainable();
|
||||
const sql = createChainable();
|
||||
const relations = createChainable();
|
||||
|
||||
export { eq, and, or, not, inArray, gte, lte, gt, lt, like, ilike, isNull, isNotNull, desc, asc, count, sql, relations };
|
||||
8
web/test/__mocks__/libsql.js
Normal file
8
web/test/__mocks__/libsql.js
Normal file
@@ -0,0 +1,8 @@
|
||||
function createClient() {
|
||||
return {
|
||||
close() {},
|
||||
};
|
||||
}
|
||||
|
||||
export { createClient };
|
||||
export default { createClient };
|
||||
15
web/test/__mocks__/ws.js
Normal file
15
web/test/__mocks__/ws.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const WebSocket = {
|
||||
OPEN: 1,
|
||||
CONNECTING: 0,
|
||||
CLOSING: 2,
|
||||
CLOSED: 3,
|
||||
};
|
||||
|
||||
class MockWebSocketServer {
|
||||
clients = new Set();
|
||||
on() {}
|
||||
close(cb) { cb?.(); }
|
||||
}
|
||||
|
||||
export { MockWebSocketServer as WebSocketServer, WebSocket };
|
||||
export default { WebSocketServer: MockWebSocketServer, WebSocket };
|
||||
92
web/test/setup.ts
Normal file
92
web/test/setup.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { vi } from "vitest";
|
||||
|
||||
// Mock ws module - ESM interop issue with WebSocket named export
|
||||
vi.mock("ws", () => {
|
||||
class MockWebSocketServer {
|
||||
clients = new Set();
|
||||
on() {}
|
||||
close(cb) { cb?.(); }
|
||||
}
|
||||
|
||||
const WebSocket = {
|
||||
OPEN: 1,
|
||||
CONNECTING: 0,
|
||||
CLOSING: 2,
|
||||
CLOSED: 3,
|
||||
};
|
||||
|
||||
return {
|
||||
WebSocketServer: MockWebSocketServer,
|
||||
WebSocket,
|
||||
};
|
||||
});
|
||||
|
||||
// Mock three module - WebGL not available in jsdom
|
||||
vi.mock("three", () => {
|
||||
class MockWebGLRenderer {
|
||||
domElement = document.createElement("canvas");
|
||||
setSize() {}
|
||||
setPixelRatio() {}
|
||||
setClearColor() {}
|
||||
render() {}
|
||||
dispose() {}
|
||||
}
|
||||
|
||||
class MockScene {
|
||||
add() {}
|
||||
}
|
||||
|
||||
class MockPerspectiveCamera {
|
||||
position = { z: 0 };
|
||||
updateProjectionMatrix() {}
|
||||
}
|
||||
|
||||
class MockPlaneGeometry {
|
||||
attributes = { position: { count: 1 } };
|
||||
computeVertexNormals() {}
|
||||
dispose() {}
|
||||
setAttribute() {}
|
||||
}
|
||||
|
||||
class MockBufferAttribute {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
class MockShaderMaterial {
|
||||
dispose() {}
|
||||
}
|
||||
|
||||
class MockMesh {
|
||||
rotation = { set() {} };
|
||||
scale = { set() {}, multiplyScalar() {} };
|
||||
position = { y: 0 };
|
||||
}
|
||||
|
||||
class MockVector3 {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
class MockVector4 {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
class MockTimer {
|
||||
update() {}
|
||||
getDelta() { return 0.016; }
|
||||
getElapsed() { return 0; }
|
||||
}
|
||||
|
||||
return {
|
||||
WebGLRenderer: MockWebGLRenderer,
|
||||
Scene: MockScene,
|
||||
PerspectiveCamera: MockPerspectiveCamera,
|
||||
PlaneGeometry: MockPlaneGeometry,
|
||||
BufferAttribute: MockBufferAttribute,
|
||||
ShaderMaterial: MockShaderMaterial,
|
||||
Mesh: MockMesh,
|
||||
Vector3: MockVector3,
|
||||
Vector4: MockVector4,
|
||||
Timer: MockTimer,
|
||||
DoubleSide: 2,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user