Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
},
"dependencies": {
"@hono/zod-validator": "^0.7.6",
"@tsndr/cloudflare-worker-jwt": "^3.2.0",
"@tsndr/cloudflare-worker-jwt": "^3.2.1",
"bcryptjs": "^2.4.3",
"hono": "^4.12.18",
"zod": "^4.3.6"
"hono": "^4.12.22",
"zod": "^4.4.3"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "^0.10.10",
"@cloudflare/workers-types": "^4.20250110.0",
"@cloudflare/vitest-pool-workers": "^0.10.15",
"@cloudflare/workers-types": "^4.20260524.1",
"@tabitabi/types": "workspace:*",
"@types/bcryptjs": "^3.0.0",
"@vitest/coverage-v8": "~3.2.4",
"typescript": "^5.6.3",
"typescript": "^5.9.3",
"vitest": "~3.2.4",
"wrangler": "^4.83.0"
"wrangler": "4.83.0"
}
}
120 changes: 120 additions & 0 deletions apps/api/test/cloudflare-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { DatabaseSync, type StatementSync } from 'node:sqlite';

type D1Value = string | number | boolean | null | undefined;

type D1Result<T = unknown> = {
success: boolean;
results?: T[];
meta?: {
changes?: number;
last_row_id?: number | bigint;
};
};

class LocalD1PreparedStatement {
private values: D1Value[] = [];

constructor(
private readonly database: DatabaseSync,
private readonly sql: string,
) {}

bind(...values: D1Value[]) {
this.values = values;
return this;
}

run(): D1Result {
const normalizedSql = this.normalizeSql();

if (this.values.length === 0 && /;\s*\S/.test(normalizedSql.trim().replace(/;\s*$/, ''))) {
this.database.exec(normalizedSql);
return { success: true, meta: { changes: 0 } };
}

const statement = this.prepareStatement(normalizedSql);
const result = statement.run(...this.normalizeValues());
return {
success: true,
meta: {
changes: result.changes,
last_row_id: result.lastInsertRowid,
},
};
}

all<T = Record<string, unknown>>(): D1Result<T> {
const statement = this.prepareStatement(this.normalizeSql());
return {
success: true,
results: statement.all(...this.normalizeValues()) as T[],
};
}

first<T = Record<string, unknown>>(): T | null {
const statement = this.prepareStatement(this.normalizeSql());
return (statement.get(...this.normalizeValues()) as T | undefined) ?? null;
}

private normalizeSql(): string {
return this.sql.replace(/\bTRUE\b/gi, '1').replace(/\bFALSE\b/gi, '0');
}

private normalizeValues() {
return this.values.map((value) => {
if (typeof value === 'boolean') return value ? 1 : 0;
if (value === undefined) return null;
return value;
});
}

private prepareStatement(sql: string): StatementSync {
return this.database.prepare(sql);
}
}

class LocalD1Database {
private readonly database = new DatabaseSync(':memory:');

constructor() {
this.database.exec('PRAGMA foreign_keys = ON;');
}

prepare(sql: string) {
return new LocalD1PreparedStatement(this.database, sql);
}

async batch(statements: LocalD1PreparedStatement[]) {
this.database.exec('BEGIN;');
try {
const results = statements.map((statement) => statement.run());
this.database.exec('COMMIT;');
return results;
} catch (error) {
this.database.exec('ROLLBACK;');
throw error;
}
}
}

export const env = {
DB: new LocalD1Database(),
ALLOWED_ORIGINS: '*',
JWT_SECRET: 'test-secret-for-ci',
};

export function createExecutionContext() {
const promises: Promise<unknown>[] = [];
return {
waitUntil(promise: Promise<unknown>) {
promises.push(promise);
},
passThroughOnException() {},
props: {},
__promises: promises,
};
}

export async function waitOnExecutionContext(ctx: ReturnType<typeof createExecutionContext>) {
await Promise.all(ctx.__promises);
}
18 changes: 9 additions & 9 deletions apps/api/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vitest/config';

export default defineWorkersConfig({
export default defineConfig({
test: {
globals: true,
poolOptions: {
workers: {
wrangler: { configPath: './wrangler.test.toml' },
miniflare: {
d1Databases: ['DB'],
},
},
environment: 'node',
fileParallelism: false,
},
resolve: {
alias: {
'cloudflare:test': fileURLToPath(new URL('./test/cloudflare-test.ts', import.meta.url)),
},
},
});
40 changes: 20 additions & 20 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@
"dependencies": {
"@googlemaps/js-api-loader": "^2.0.2",
"@tabitabi/types": "workspace:*",
"mapbox-gl": "^3.17.0"
"mapbox-gl": "^3.24.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250110.0",
"@playwright/test": "^1.57.0",
"@sveltejs/adapter-cloudflare": "^4.7.4",
"@sveltejs/kit": "^2.60.1",
"@sveltejs/vite-plugin-svelte": "^5.0.4",
"@cloudflare/workers-types": "^4.20260524.1",
"@playwright/test": "^1.60.0",
"@sveltejs/adapter-cloudflare": "^4.9.0",
"@sveltejs/kit": "^2.61.1",
"@sveltejs/vite-plugin-svelte": "^5.1.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/svelte": "^5.2.9",
"@types/google.maps": "^3.58.1",
"@types/mapbox-gl": "^3.4.1",
"@types/node": "^24.10.1",
"autoprefixer": "^10.4.20",
"jsdom": "^27.2.0",
"marked": "^17.0.1",
"postcss": "^8.5.10",
"svelte": "^5.55.7",
"svelte-check": "^4.1.3",
"tailwindcss": "^3.4.17",
"tsx": "^4.21.0",
"typescript": "^5.6.3",
"@testing-library/svelte": "^5.3.1",
"@types/google.maps": "^3.64.1",
"@types/mapbox-gl": "^3.5.0",
"@types/node": "^24.12.4",
"autoprefixer": "^10.5.0",
"jsdom": "^27.4.0",
"marked": "^17.0.6",
"postcss": "^8.5.15",
"svelte": "^5.55.9",
"svelte-check": "^4.4.8",
"tailwindcss": "^3.4.19",
"tsx": "^4.22.3",
"typescript": "^5.9.3",
"vite": "^6.4.2",
"vitest": "~3.2.4",
"wrangler": "^4.83.0"
"wrangler": "4.83.0"
}
}
3 changes: 3 additions & 0 deletions apps/web/src/test/sveltekit-navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function replaceState(_state: string, url: string) {
window.history.replaceState({}, '', url);
}
19 changes: 19 additions & 0 deletions apps/web/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { fileURLToPath } from 'node:url';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { defineConfig } from 'vitest/config';

export default defineConfig({
plugins: [svelte()],
resolve: {
alias: {
'$app/navigation': fileURLToPath(new URL('./src/test/sveltekit-navigation.ts', import.meta.url)),
$lib: fileURLToPath(new URL('./src/lib', import.meta.url)),
},
},
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
environment: 'jsdom',
globals: true,
setupFiles: ['./src/test/setup.ts'],
},
});
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@
"devDependencies": {
"chrome-launcher": "^1.2.1",
"husky": "^9.1.7",
"lighthouse": "^13.0.3",
"lighthouse": "^13.3.0",
"turbo": "^2.9.14",
"wrangler": "^4.83.0"
"wrangler": "4.83.0"
},
"pnpm": {
"overrides": {
"brace-expansion": "5.0.6",
"cookie": "1.1.1",
"esbuild@<0.25.0": "0.25.12",
"miniflare": "4.20260415.0",
"undici": "7.25.0",
"vite": "6.4.2",
"wrangler": "4.83.0"
}
}
}
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"build": "tsc"
},
"devDependencies": {
"typescript": "^5.6.3"
"typescript": "^5.9.3"
}
}
Loading
Loading