Skip to content
Draft
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
1 change: 1 addition & 0 deletions packages/fs-bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {

export type {
FileSystemBridge,
FileSystemBridgeCapabilities,
FileSystemBridgeOperations,
FileSystemBridgeRmOptions,
FSEntry,
Expand Down
5 changes: 1 addition & 4 deletions packages/ucd-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
"dev": "tsdown --watch",
"clean": "git clean -xdf dist node_modules",
"lint": "eslint .",
"typecheck": "tsc --noEmit",
"playground:http": "tsx --tsconfig=./tsconfig.json ./playgrounds/http-playground.ts",
"playground:node": "tsx --tsconfig=./tsconfig.json ./playgrounds/node-playground.ts",
"playground:memory": "tsx --tsconfig=./tsconfig.json ./playgrounds/memory-playground.ts"
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@luxass/unicode-utils-new": "catalog:prod",
Expand Down
11 changes: 0 additions & 11 deletions packages/ucd-store/playgrounds/__utils.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/ucd-store/playgrounds/http-playground.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/ucd-store/playgrounds/memory-playground.ts

This file was deleted.

108 changes: 0 additions & 108 deletions packages/ucd-store/playgrounds/node-playground.ts

This file was deleted.

136 changes: 136 additions & 0 deletions packages/ucd-store/test/playgrounds/__shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import type { FileSystemBridgeCapabilities } from "@ucdjs/fs-bridge";
import { assertCapability } from "@ucdjs/fs-bridge";
import { expect, it } from "vitest";
import { UCDStore } from "../../src/store";

export interface PlaygroundTestOptions {
/**
* The UCDStore instance to be tested.
*/
store: UCDStore;

/**
* List of required capabilities that the store's filesystem bridge must support.
*/
requiredCapabilities?: (keyof FileSystemBridgeCapabilities)[];

/**
* Whether to run read operation tests.
*/
read?: boolean;

/**
* Whether to run write operation tests.
*/
write?: boolean;

/**
* Whether to run analysis tests.
*/
analyze?: boolean;

/**
* Whether to run directory listing tests.
*/
listdir?: boolean;

/**
* Whether to run mirroring tests.
*/
mirror?: boolean;

/**
* Whether to run cleaning tests.
*/
clean?: boolean;

/**
* Whether to run repair tests.
*/
repair?: boolean;
}

export function runPlaygroundTests(options: PlaygroundTestOptions): void {
const {
store,
read: shouldRunReadTests = true,
write: shouldRunWriteTests = true,
analyze: shouldRunAnalyzeTests = true,
listdir: shouldRunListDirTests = true,
mirror: shouldRunMirrorTests = true,
clean: shouldRunCleanTests = true,
repair: shouldRunRepairTests = true,
} = options;

it("should create a valid UCDStore instance", () => {
expect(store).toBeInstanceOf(UCDStore);
});

it("should have basePath configured", () => {
expect(store.basePath).toBeDefined();
});

it("should have capabilities defined", () => {
expect(store.fs.capabilities).toBeDefined();

if (options.requiredCapabilities != null && options.requiredCapabilities.length > 0) {
for (const cap of options.requiredCapabilities) {
expect(store.fs.capabilities[cap]).toBe(true);
}
}
});

it("should initialize the store", async () => {
expect(store.initialized).toBe(false);

await expect(store.init()).resolves.not.toThrowError();

Check failure on line 86 in packages/ucd-store/test/playgrounds/__shared.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest)

packages/ucd-store/test/playgrounds/http.test.ts > http playground > should initialize the store

AssertionError: promise rejected "BridgeGenericError: Unexpected error in '… { originalError: InternalError: … }" instead of resolving ❯ packages/ucd-store/test/playgrounds/__shared.ts:86:30 Caused by: Caused by: BridgeGenericError: Unexpected error in 'exists' operation: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option. ❯ handleError packages/fs-bridge/src/define.ts:1684:9 ❯ packages/fs-bridge/src/define.ts:121:67 ❯ UCDStore.init packages/ucd-store/src/store.ts:299:19 ❯ packages/ucd-store/test/playgrounds/__shared.ts:86:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { originalError: { stack: 'InternalError: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.\n at applyStrategy (file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:42:15)\n at onUnhandledRequest (/Users/runner/work/ucd/ucd/packages/test-utils/src/msw/vitest-setup.ts:10:11)\n at onUnhandledRequest (file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:68:5)\n at handleRequest (file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/handleRequest.ts:79:11)\n at processTicksAndRejections (node:internal/process/task_queues:105:5)\n at _Emitter.<anonymous> (file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/node/SetupServerCommonApi.ts:60:26)\n at emitAsync (file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/emitAsync.ts:23:5)\n at file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:145:5\n at until (file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/@open-draft[email protected]/node_modules/@open-draft/until/src/until.ts:23:18)\n at handleRequest (file:///Users/runner/work/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:134:18)', message: '[MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.', name: 'InternalError', constructor: 'Function<InternalError>', toString: 'Function<toString>' } } Caused by: Caused by: InternalError: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option. ❯ applyStrategy node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:42:15 ❯ onUnhandledRequest packages/test-utils/src/msw/vitest-setup.ts:10:11 ❯ onUnhandledRequest node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:68:5 ❯ handleRequest node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/handleRequest.ts:79:11 ❯ _Emitter.<anonymous> node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/node/SetupServerCommonApi.ts:60:26 ❯ emitAsync node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/emitAsync.ts:23:5 ❯ node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:145:5 ❯ until node_modules/.pnpm/@open-draft[email protected]/node_modules/@open-draft/until/src/until.ts:23:18 ❯ handleRequest node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:134:18

Check failure on line 86 in packages/ucd-store/test/playgrounds/__shared.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

packages/ucd-store/test/playgrounds/http.test.ts > http playground > should initialize the store

AssertionError: promise rejected "BridgeGenericError: Unexpected error in '… { originalError: InternalError: … }" instead of resolving ❯ packages/ucd-store/test/playgrounds/__shared.ts:86:30 Caused by: Caused by: BridgeGenericError: Unexpected error in 'exists' operation: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option. ❯ handleError packages/fs-bridge/src/define.ts:1684:9 ❯ packages/fs-bridge/src/define.ts:121:67 ❯ UCDStore.init packages/ucd-store/src/store.ts:299:19 ❯ packages/ucd-store/test/playgrounds/__shared.ts:86:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { originalError: { stack: 'InternalError: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.\n at applyStrategy (file:///home/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:42:15)\n at onUnhandledRequest (/home/runner/work/ucd/ucd/packages/test-utils/src/msw/vitest-setup.ts:10:11)\n at onUnhandledRequest (file:///home/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:68:5)\n at handleRequest (file:///home/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/handleRequest.ts:79:11)\n at processTicksAndRejections (node:internal/process/task_queues:105:5)\n at _Emitter.<anonymous> (file:///home/runner/work/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/node/SetupServerCommonApi.ts:60:26)\n at emitAsync (file:///home/runner/work/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/emitAsync.ts:23:5)\n at file:///home/runner/work/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:145:5\n at until (file:///home/runner/work/ucd/ucd/node_modules/.pnpm/@open-draft[email protected]/node_modules/@open-draft/until/src/until.ts:23:18)\n at handleRequest (file:///home/runner/work/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:134:18)', message: '[MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.', name: 'InternalError', constructor: 'Function<InternalError>', toString: 'Function<toString>' } } Caused by: Caused by: InternalError: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option. ❯ applyStrategy node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:42:15 ❯ onUnhandledRequest packages/test-utils/src/msw/vitest-setup.ts:10:11 ❯ onUnhandledRequest node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:68:5 ❯ handleRequest node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/handleRequest.ts:79:11 ❯ _Emitter.<anonymous> node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/node/SetupServerCommonApi.ts:60:26 ❯ emitAsync node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/emitAsync.ts:23:5 ❯ node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:145:5 ❯ until node_modules/.pnpm/@open-draft[email protected]/node_modules/@open-draft/until/src/until.ts:23:18 ❯ handleRequest node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:134:18

Check failure on line 86 in packages/ucd-store/test/playgrounds/__shared.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest)

packages/ucd-store/test/playgrounds/http.test.ts > http playground > should initialize the store

AssertionError: promise rejected "BridgeGenericError: Unexpected error in '… { originalError: InternalError: … }" instead of resolving ❯ packages/ucd-store/test/playgrounds/__shared.ts:86:30 Caused by: Caused by: BridgeGenericError: Unexpected error in 'exists' operation: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option. ❯ handleError packages/fs-bridge/src/define.ts:1684:9 ❯ packages/fs-bridge/src/define.ts:121:67 ❯ UCDStore.init packages/ucd-store/src/store.ts:299:19 ❯ packages/ucd-store/test/playgrounds/__shared.ts:86:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { originalError: { stack: 'InternalError: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.\n at applyStrategy (file:///D:/a/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:42:15)\n at onUnhandledRequest (D:\a\ucd\ucd\packages\test-utils\src\msw\vitest-setup.ts:10:11)\n at onUnhandledRequest (file:///D:/a/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:68:5)\n at handleRequest (file:///D:/a/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/handleRequest.ts:79:11)\n at processTicksAndRejections (node:internal/process/task_queues:105:5)\n at _Emitter.<anonymous> (file:///D:/a/ucd/ucd/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/node/SetupServerCommonApi.ts:60:26)\n at emitAsync (file:///D:/a/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/emitAsync.ts:23:5)\n at file:///D:/a/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:145:5\n at until (file:///D:/a/ucd/ucd/node_modules/.pnpm/@open-draft[email protected]/node_modules/@open-draft/until/src/until.ts:23:18)\n at handleRequest (file:///D:/a/ucd/ucd/node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:134:18)', message: '[MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.', name: 'InternalError', constructor: 'Function<InternalError>', toString: 'Function<toString>' } } Caused by: Caused by: InternalError: [MSW] Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option. ❯ applyStrategy node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:42:15 ❯ onUnhandledRequest packages/test-utils/src/msw/vitest-setup.ts:10:11 ❯ onUnhandledRequest node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/request/onUnhandledRequest.ts:68:5 ❯ handleRequest node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/core/utils/handleRequest.ts:79:11 ❯ _Emitter.<anonymous> node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/msw/src/node/SetupServerCommonApi.ts:60:26 ❯ emitAsync node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/emitAsync.ts:23:5 ❯ node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:145:5 ❯ until node_modules/.pnpm/@open-draft[email protected]/node_modules/@open-draft/until/src/until.ts:23:18 ❯ handleRequest node_modules/.pnpm/@mswjs[email protected]/node_modules/@mswjs/interceptors/src/utils/handleRequest.ts:134:18

expect(store.initialized).toBe(true);
});

it.runIf(store.initialized && shouldRunReadTests)("should support read operations", async () => {
try {
assertCapability(store.fs, ["read", "exists", "listdir"]);

await store.init();

const [arabicShaping, arabicShapingError] = await store.getFile("15.1.0", "ArabicShaping.txt");
expect(arabicShaping).toBeDefined();
expect(arabicShapingError).toBeNull();

expect(arabicShaping).not.toBeNull();
} catch (err) {
expect.fail((err as Error).message);
}
});

it.runIf(store.initialized && shouldRunWriteTests)("should support write operations", async () => {
try {
assertCapability(store.fs, ["exists", "mkdir", "write", "read", "rm"]);

expect.fail("Write operations test not implemented yet");
} catch (err) {
expect.fail((err as Error).message);
}
});

it.runIf(store.initialized && shouldRunAnalyzeTests)("should analyze the store", async () => {
expect.fail("Analyze test not implemented yet");
});

it.runIf(store.initialized && shouldRunListDirTests)("should list files in a version directory", async () => {
expect.fail("List directory test not implemented yet");
});

it.runIf(store.initialized && shouldRunMirrorTests)("should mirror files from remote", async () => {
expect.fail("Mirror test not implemented yet");
});

it.runIf(store.initialized && shouldRunCleanTests)("should clean orphaned files", async () => {
expect.fail("Clean test not implemented yet");
});

it.runIf(store.initialized && shouldRunRepairTests)("should repair missing files", async () => {
expect.fail("Repair test not implemented yet");
});
}
39 changes: 39 additions & 0 deletions packages/ucd-store/test/playgrounds/http.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { mockStoreApi } from "#internal/test-utils/mock-store";
import { UNICODE_VERSION_METADATA } from "@luxass/unicode-utils-new";
import { beforeEach, describe } from "vitest";
import { createHTTPUCDStore } from "../../src/factory";
import { runPlaygroundTests } from "./__shared";

describe("http playground", async () => {
beforeEach(() => {
mockStoreApi({
responses: {
"/api/v1/versions": [...UNICODE_VERSION_METADATA],
"/api/v1/versions/:version/file-tree": [{
type: "file",
name: "ArabicShaping.txt",
path: "ArabicShaping.txt",
lastModified: 1724601900000,
}],
},
});
});

const store = await createHTTPUCDStore({
baseUrl: "https://api.ucdjs.dev",
versions: ["15.1.0"],
});

runPlaygroundTests({
store,
requiredCapabilities: [
"read",
"exists",
"listdir",
],
repair: false,
mirror: false,
write: false,
clean: false,
});
});
42 changes: 42 additions & 0 deletions packages/ucd-store/test/playgrounds/memory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { mockStoreApi } from "#internal/test-utils/mock-store";
import { UNICODE_VERSION_METADATA } from "@luxass/unicode-utils-new";
import { beforeEach, describe } from "vitest";
import { createUCDStore } from "../../src/factory";
import { createMemoryMockFS } from "../__shared";
import { runPlaygroundTests } from "./__shared";

describe("memory playground", () => {
beforeEach(() => {
mockStoreApi({
responses: {
"/api/v1/versions": [...UNICODE_VERSION_METADATA],
"/api/v1/versions/:version/file-tree": [{
type: "file",
name: "ArabicShaping.txt",
path: "ArabicShaping.txt",
lastModified: 1724601900000,
}],
},
});
});

const memoryFS = createMemoryMockFS();

const store = createUCDStore({
basePath: "/test",
fs: memoryFS,
versions: ["15.1.0"],
});

runPlaygroundTests({
store,
requiredCapabilities: [
"write",
"read",
"mkdir",
"exists",
"listdir",
"rm",
],
});
});
Loading
Loading