diff --git a/package-lock.json b/package-lock.json index 4da4715..44bd8c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31264,8 +31264,6 @@ "@rdfjs/types": "^1.0.1", "@testing-library/react": "^14.1.2", "start-server-and-test": "^2.0.3", - "ts-node": "^10.9.2", - "tsx": "^4.19.4", "whatwg-fetch": "^3.6.20" } }, @@ -31395,6 +31393,7 @@ }, "devDependencies": { "@ldo/rdf-utils": "^1.0.0-alpha.9", + "@ldo/test-solid-server": "^1.0.0-alpha.9", "@rdfjs/types": "^1.0.1", "@testing-library/react": "^14.1.2", "jest-environment-jsdom": "^29.7.0", diff --git a/packages/solid-type-index/jest.config.js b/packages/solid-type-index/jest.config.js deleted file mode 100644 index 7557fd2..0000000 --- a/packages/solid-type-index/jest.config.js +++ /dev/null @@ -1,7 +0,0 @@ -const sharedConfig = require("../../jest.config.js"); -module.exports = { - ...sharedConfig, - rootDir: "./", - testEnvironment: "jsdom", - setupFiles: ["/jest.setup.ts"], -}; diff --git a/packages/solid-type-index/jest.setup.ts b/packages/solid-type-index/jest.setup.ts deleted file mode 100644 index b0bd26f..0000000 --- a/packages/solid-type-index/jest.setup.ts +++ /dev/null @@ -1 +0,0 @@ -import "@inrupt/jest-jsdom-polyfills"; diff --git a/packages/solid-type-index/package.json b/packages/solid-type-index/package.json index cce0166..735d0a6 100644 --- a/packages/solid-type-index/package.json +++ b/packages/solid-type-index/package.json @@ -2,18 +2,26 @@ "name": "@ldo/solid-type-index", "version": "1.0.0-alpha.9", "description": "Solid Type Index support for LDO", - "main": "dist/index.js", + "type": "module", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/types/index.d.ts", + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "./package.json": "./package.json" + }, "scripts": { - "build": "tsc --project tsconfig.build.json", - "watch": "tsc --watch", - "test": "npm run test:integration", - "test:watch": "jest --watch", + "build": "rimraf dist && npm run build:cjs && npm run build:esm", + "build:cjs": "tsc --project tsconfig.cjs.json", + "build:esm": "tsc --project tsconfig.esm.json", + "test": "vitest run --coverage", "prepublishOnly": "npm run test && npm run build", "build:ldo": "ldo build --input src/.shapes --output src/.ldo", - "lint": "eslint src/** --fix --no-error-on-unmatched-pattern", - "test:integration": "start-server-and-test start-test-server http://localhost:3003 start-integration-test", - "start-test-server": "ts-node ./test/test-server/runServer.ts", - "start-integration-test": "jest --coverage" + "lint": "eslint src/** --fix --no-error-on-unmatched-pattern" }, "repository": { "type": "git", @@ -27,6 +35,7 @@ "homepage": "https://github.com/o-development/ldo/tree/main/packages/solid-react#readme", "devDependencies": { "@ldo/rdf-utils": "^1.0.0-alpha.9", + "@ldo/test-solid-server": "^1.0.0-alpha.9", "@rdfjs/types": "^1.0.1", "@testing-library/react": "^14.1.2", "jest-environment-jsdom": "^29.7.0", diff --git a/packages/solid-type-index/src/setTypeIndex.ts b/packages/solid-type-index/src/setTypeIndex.ts index 778e929..eecdbdf 100644 --- a/packages/solid-type-index/src/setTypeIndex.ts +++ b/packages/solid-type-index/src/setTypeIndex.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { v4 } from "uuid"; -$1$2.js$3 import { FOR_CLASS, RDF_TYPE, TYPE_REGISTRATION } from "./constants.js"; import { guaranteeOptions, type Options } from "./util/Options.js"; import { namedNode, quad } from "@rdfjs/data-model"; @@ -16,6 +15,10 @@ import type { SolidLeafUri, } from "@ldo/connected-solid"; import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; +import { + TypeIndexDocumentShapeType, + TypeRegistrationShapeType, +} from "./.ldo/typeIndex.shapeTypes.js"; /** * ============================================================================= diff --git a/packages/solid-type-index/test/General.test.tsx b/packages/solid-type-index/test/General.test.tsx index 5798160..3de4828 100644 --- a/packages/solid-type-index/test/General.test.tsx +++ b/packages/solid-type-index/test/General.test.tsx @@ -1,4 +1,5 @@ import { + fileData, MY_BOOKMARKS_1_URI, MY_BOOKMARKS_2_URI, PRIVATE_TYPE_INDEX_URI, @@ -6,9 +7,8 @@ import { ROOT_CONTAINER, setupEmptyTypeIndex, setupFullTypeIndex, - setUpServer, WEB_ID, -} from "./setUpServer.js"; +} from "./fileData.js"; import { getInstanceUris, getTypeRegistrations } from "../src/getTypeIndex.js"; import { addRegistration, @@ -19,19 +19,43 @@ import { TypeIndexProfileShapeType } from "../src/.ldo/profile.shapeTypes.js"; import { namedNode } from "@rdfjs/dataset"; import { INSTANCE } from "../src/constants.js"; import { createSolidLdoDataset } from "@ldo/connected-solid"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { setupServer } from "@ldo/test-solid-server"; +import { it, expect, describe, afterEach } from "vitest"; -// Use an increased timeout, since the CSS server takes too much setup time. -jest.setTimeout(40_000); +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +const __dirname = dirname(fileURLToPath(import.meta.url)); const ADDRESS_BOOK = "http://www.w3.org/2006/vcard/ns#AddressBook"; const BOOKMARK = "http://www.w3.org/2002/01/bookmark#Bookmark"; const EXAMPLE_THING = "https://example.com/ExampleThing"; describe("General Tests", () => { - const s = setUpServer(); + const s = setupServer( + 3003, + fileData, + join( + __dirname, + "configs", + "components-config", + "unauthenticatedServer.json", + ), + ); + + afterEach(async () => { + await Promise.all([ + await s.authFetch(WEB_ID, { method: "DELETE" }), + await s.authFetch(PUBLIC_TYPE_INDEX_URI, { method: "DELETE" }), + await s.authFetch(PRIVATE_TYPE_INDEX_URI, { method: "DELETE" }), + await s.authFetch(MY_BOOKMARKS_1_URI, { method: "DELETE" }), + await s.authFetch(MY_BOOKMARKS_2_URI, { method: "DELETE" }), + ]); + }); it("gets the current typeindex", async () => { - await setupFullTypeIndex(s); + await setupFullTypeIndex(s.authFetch); const solidLdoDataset = createSolidLdoDataset(); const typeRegistrations = await getTypeRegistrations(WEB_ID, { @@ -67,7 +91,7 @@ describe("General Tests", () => { }); it("initializes the type index", async () => { - await setupEmptyTypeIndex(s); + await setupEmptyTypeIndex(s.authFetch); const solidLdoDataset = createSolidLdoDataset(); @@ -84,7 +108,7 @@ describe("General Tests", () => { }); it("Adds to the typeIndex", async () => { - await setupFullTypeIndex(s); + await setupFullTypeIndex(s.authFetch); const solidLdoDataset = createSolidLdoDataset(); @@ -125,7 +149,7 @@ describe("General Tests", () => { }); it("Removes from the typeIndex", async () => { - await setupFullTypeIndex(s); + await setupFullTypeIndex(s.authFetch); const solidLdoDataset = createSolidLdoDataset(); diff --git a/packages/solid-type-index/test/test-server/configs/components-config/unauthenticatedServer.json b/packages/solid-type-index/test/configs/components-config/unauthenticatedServer.json similarity index 96% rename from packages/solid-type-index/test/test-server/configs/components-config/unauthenticatedServer.json rename to packages/solid-type-index/test/configs/components-config/unauthenticatedServer.json index ff01914..8816739 100644 --- a/packages/solid-type-index/test/test-server/configs/components-config/unauthenticatedServer.json +++ b/packages/solid-type-index/test/configs/components-config/unauthenticatedServer.json @@ -45,8 +45,8 @@ }, "overrideParameters": { "@type": "StaticFolderGenerator", - "templateFolder": "./test/test-server/configs/template" + "templateFolder": "./test/configs/template" } } ] -} +} \ No newline at end of file diff --git a/packages/solid-type-index/test/test-server/configs/solid-css-seed.json b/packages/solid-type-index/test/configs/solid-css-seed.json similarity index 100% rename from packages/solid-type-index/test/test-server/configs/solid-css-seed.json rename to packages/solid-type-index/test/configs/solid-css-seed.json diff --git a/packages/solid-type-index/test/test-server/configs/template/wac/.acl.hbs b/packages/solid-type-index/test/configs/template/wac/.acl.hbs similarity index 100% rename from packages/solid-type-index/test/test-server/configs/template/wac/.acl.hbs rename to packages/solid-type-index/test/configs/template/wac/.acl.hbs diff --git a/packages/solid-type-index/test/test-server/configs/template/wac/profile/card.acl.hbs b/packages/solid-type-index/test/configs/template/wac/profile/card.acl.hbs similarity index 100% rename from packages/solid-type-index/test/test-server/configs/template/wac/profile/card.acl.hbs rename to packages/solid-type-index/test/configs/template/wac/profile/card.acl.hbs diff --git a/packages/solid-type-index/test/setUpServer.ts b/packages/solid-type-index/test/fileData.ts similarity index 67% rename from packages/solid-type-index/test/setUpServer.ts rename to packages/solid-type-index/test/fileData.ts index 04fc479..c376aba 100644 --- a/packages/solid-type-index/test/setUpServer.ts +++ b/packages/solid-type-index/test/fileData.ts @@ -1,4 +1,5 @@ -import fetch from "cross-fetch"; +import type fetch from "cross-fetch"; +import type { ResourceInfo } from "@ldo/test-solid-server"; export const SERVER_DOMAIN = process.env.SERVER || "http://localhost:3003/"; export const ROOT_ROUTE = process.env.ROOT_CONTAINER || "example/"; @@ -45,18 +46,16 @@ export const PRIVATE_TYPE_INDEX_TTL = `@prefix solid: .`; -export interface SetUpServerReturn { - authFetch: typeof fetch; - fetchMock: jest.Mock< - Promise, - [input: RequestInfo | URL, init?: RequestInit | undefined] - >; -} +export const fileData: ResourceInfo = { + slug: "myBookmarks/", + isContainer: true, + contains: [], +}; -export async function setupFullTypeIndex(s: SetUpServerReturn) { +export async function setupFullTypeIndex(authFetch: typeof fetch) { // Create a new document called sample.ttl - await s.authFetch(WEB_ID, { method: "DELETE" }); - await s.authFetch(ROOT_CONTAINER, { + await authFetch(WEB_ID, { method: "DELETE" }); + await authFetch(ROOT_CONTAINER, { method: "POST", headers: { link: '; rel="type"', @@ -64,17 +63,17 @@ export async function setupFullTypeIndex(s: SetUpServerReturn) { }, }); await Promise.all([ - s.authFetch(PROFILE_CONTAINER, { + authFetch(PROFILE_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", slug: "card.ttl" }, body: PROFILE_TTL, }), - s.authFetch(PROFILE_CONTAINER, { + authFetch(PROFILE_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", slug: "publicTypeIndex.ttl" }, body: PUBLIC_TYPE_INDEX_TTL, }), - s.authFetch(PROFILE_CONTAINER, { + authFetch(PROFILE_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", @@ -82,12 +81,12 @@ export async function setupFullTypeIndex(s: SetUpServerReturn) { }, body: PRIVATE_TYPE_INDEX_TTL, }), - s.authFetch(MY_BOOKMARKS_CONTAINER, { + authFetch(MY_BOOKMARKS_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", slug: "bookmark1.ttl" }, body: "", }), - s.authFetch(MY_BOOKMARKS_CONTAINER, { + authFetch(MY_BOOKMARKS_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", slug: "bookmark2.ttl" }, body: "", @@ -95,10 +94,10 @@ export async function setupFullTypeIndex(s: SetUpServerReturn) { ]); } -export async function setupEmptyTypeIndex(s: SetUpServerReturn) { +export async function setupEmptyTypeIndex(authFetch: typeof fetch) { // Create a new document called sample.ttl - await s.authFetch(WEB_ID, { method: "DELETE" }); - await s.authFetch(ROOT_CONTAINER, { + await authFetch(WEB_ID, { method: "DELETE" }); + await authFetch(ROOT_CONTAINER, { method: "POST", headers: { link: '; rel="type"', @@ -106,48 +105,20 @@ export async function setupEmptyTypeIndex(s: SetUpServerReturn) { }, }); await Promise.all([ - s.authFetch(PROFILE_CONTAINER, { + authFetch(PROFILE_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", slug: "card.ttl" }, body: "", }), - s.authFetch(MY_BOOKMARKS_CONTAINER, { + authFetch(MY_BOOKMARKS_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", slug: "bookmark1.ttl" }, body: "", }), - s.authFetch(MY_BOOKMARKS_CONTAINER, { + authFetch(MY_BOOKMARKS_CONTAINER, { method: "POST", headers: { "content-type": "text/turtle", slug: "bookmark2.ttl" }, body: "", }), ]); } - -export function setUpServer(): SetUpServerReturn { - // Ignore to build s - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const s: SetUpServerReturn = {}; - - beforeAll(async () => { - // s.authFetch = await getAuthenticatedFetch(); - s.authFetch = fetch; - }); - - beforeEach(async () => { - s.fetchMock = jest.fn(s.authFetch); - }); - - afterEach(async () => { - await Promise.all([ - await s.authFetch(WEB_ID, { method: "DELETE" }), - await s.authFetch(PUBLIC_TYPE_INDEX_URI, { method: "DELETE" }), - await s.authFetch(PRIVATE_TYPE_INDEX_URI, { method: "DELETE" }), - await s.authFetch(MY_BOOKMARKS_1_URI, { method: "DELETE" }), - await s.authFetch(MY_BOOKMARKS_2_URI, { method: "DELETE" }), - ]); - }); - - return s; -} diff --git a/packages/solid-type-index/test/test-server/runServer.ts b/packages/solid-type-index/test/test-server/runServer.ts deleted file mode 100644 index bfc7753..0000000 --- a/packages/solid-type-index/test/test-server/runServer.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { createApp } from "./solidServer.helper.js"; - -async function run() { - const app = await createApp(); - await app.start(); -} -run(); diff --git a/packages/solid-type-index/test/test-server/solidServer.helper.ts b/packages/solid-type-index/test/test-server/solidServer.helper.ts deleted file mode 100644 index 9dd4703..0000000 --- a/packages/solid-type-index/test/test-server/solidServer.helper.ts +++ /dev/null @@ -1,39 +0,0 @@ -// Taken from https://github.com/comunica/comunica/blob/b237be4265c353a62a876187d9e21e3bc05123a3/engines/query-sparql/test/QuerySparql-solid-test.ts#L9 - -import * as path from "path"; -import type { App } from "@solid/community-server"; -import { AppRunner, resolveModulePath } from "@solid/community-server"; - -export async function createApp(): Promise { - if (process.env.SERVER) { - return { - start: () => {}, - stop: () => {}, - } as App; - } - const appRunner = new AppRunner(); - - return appRunner.create({ - loaderProperties: { - mainModulePath: resolveModulePath(""), - typeChecking: false, - }, - config: path.join( - __dirname, - "configs", - "components-config", - "unauthenticatedServer.json", - ), - variableBindings: {}, - shorthand: { - port: 3_003, - loggingLevel: "off", - seedConfig: path.join(__dirname, "configs", "solid-css-seed.json"), - }, - }); -} - -export interface ISecretData { - id: string; - secret: string; -} diff --git a/packages/solid-type-index/tsconfig.build.json b/packages/solid-type-index/tsconfig.build.json deleted file mode 100644 index e375629..0000000 --- a/packages/solid-type-index/tsconfig.build.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "outDir": "./dist", - "lib": ["dom"] - }, - "include": ["./src"] -} \ No newline at end of file diff --git a/packages/solid-type-index/tsconfig.cjs.json b/packages/solid-type-index/tsconfig.cjs.json new file mode 100644 index 0000000..affce40 --- /dev/null +++ b/packages/solid-type-index/tsconfig.cjs.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.cjs.json", + "compilerOptions": { + "outDir": "./dist/cjs", + "rootDir": "./src" + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/packages/solid-type-index/tsconfig.esm.json b/packages/solid-type-index/tsconfig.esm.json new file mode 100644 index 0000000..09f99c2 --- /dev/null +++ b/packages/solid-type-index/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.esm.json", + "compilerOptions": { + "outDir": "./dist/esm", + "rootDir": "./src", + "declarationDir": "./dist/types" + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/packages/solid-type-index/vitest.config.js b/packages/solid-type-index/vitest.config.js new file mode 100644 index 0000000..9713f14 --- /dev/null +++ b/packages/solid-type-index/vitest.config.js @@ -0,0 +1,9 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + coverage: { + provider: "istanbul", + }, + }, +});