* perf: use only one WASM alloc for xxhash * perf(deps): lazy load mercury-parser and use googleapis/youtube instead of heavy googleapis * perf(dx): lazy load dev registry speed up npm dev script * perf: close playwright browser on destroy * fix: show exception msg in prod * revert: "perf: use only one WASM alloc for xxhash" This reverts commit 01ecdd48d09a046dce05f440814dcbec0323a7de. * perf: use only one WASM alloc for xxhash * test: add claim for worker * fix: missing piece from 8dd9c9a * feat: add namespace to the chunkfilename * fix: keep var naming
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
import type { Next } from 'hono';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import api from '@/api';
|
|
import { handler as allHandler } from '@/api/namespace/all';
|
|
import { handler as oneHandler } from '@/api/namespace/one';
|
|
import { namespaces } from '@/registry';
|
|
|
|
const noopNext: Next = () => Promise.resolve();
|
|
|
|
const createCtx = (param: Record<string, string> = {}) =>
|
|
({
|
|
req: {
|
|
valid: () => param,
|
|
},
|
|
json: (data: unknown) => data,
|
|
}) as any;
|
|
|
|
describe('api/namespace', () => {
|
|
const nestedKey = Object.keys(namespaces).find((key) => key.includes('/')) as string;
|
|
|
|
it('returns all namespaces', async () => {
|
|
const result = await allHandler(createCtx(), noopNext);
|
|
expect(result).toBe(namespaces);
|
|
});
|
|
|
|
it('returns a single namespace', async () => {
|
|
const result = await oneHandler(createCtx({ namespace: 'test' }), noopNext);
|
|
expect(result).toBe(namespaces.test);
|
|
});
|
|
|
|
it('returns a nested namespace', async () => {
|
|
expect(nestedKey).toBeDefined();
|
|
const [namespace, sub] = nestedKey.split('/');
|
|
const result = await oneHandler(createCtx({ namespace, sub }), noopNext);
|
|
expect(result).toBe(namespaces[nestedKey]);
|
|
});
|
|
|
|
it('serves a single namespace over HTTP', async () => {
|
|
expect(namespaces.github).toBeDefined();
|
|
const response = await api.request('/namespace/github');
|
|
expect(response.status).toBe(200);
|
|
expect(await response.json()).toEqual(namespaces.github);
|
|
});
|
|
|
|
it('serves a nested namespace over HTTP', async () => {
|
|
expect(nestedKey).toBeDefined();
|
|
const response = await api.request(`/namespace/${nestedKey}`);
|
|
expect(response.status).toBe(200);
|
|
expect(await response.json()).toEqual(namespaces[nestedKey]);
|
|
});
|
|
});
|