solid-react tests work

main
Jackson Morgan 5 months ago
parent a230244af6
commit 1dc42ef0a7
  1. 14
      package-lock.json
  2. 12
      packages/connected-solid/src/notifications/Websocket2023NotificationSubscription.ts
  3. 46
      packages/connected/src/ConnectedLdoDataset.ts
  4. 7
      packages/connected/src/ConnectedLdoTransactionDataset.ts
  5. 4
      packages/connected/src/IConnectedLdoDataset.ts
  6. 3
      packages/solid-react/babel.config.js
  7. 10
      packages/solid-react/jest.config.js
  8. 7
      packages/solid-react/jest.setup.ts
  9. 7
      packages/solid-react/package.json
  10. 19
      packages/solid-react/test/Solid-Integration.test.tsx

14
package-lock.json generated

@ -25710,6 +25710,13 @@
"node": ">=0.10.0"
}
},
"node_modules/whatwg-fetch": {
"version": "3.6.20",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz",
"integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==",
"dev": true,
"license": "MIT"
},
"node_modules/whatwg-mimetype": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz",
@ -26760,13 +26767,18 @@
"cross-fetch": "^3.1.6"
},
"devDependencies": {
"@babel/core": "^7.26.10",
"@babel/preset-env": "^7.26.9",
"@inrupt/jest-jsdom-polyfills": "^3.2.6",
"@ldo/rdf-utils": "^1.0.0-alpha.1",
"@rdfjs/types": "^1.0.1",
"@testing-library/react": "^14.1.2",
"babel-jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"start-server-and-test": "^2.0.3",
"ts-node": "^10.9.2"
"ts-jest": "^29.3.0",
"ts-node": "^10.9.2",
"whatwg-fetch": "^3.6.20"
}
},
"packages/solid-type-index": {

@ -93,7 +93,9 @@ export class Websocket2023NotificationSubscription extends SolidNotificationSubs
this.onNotification(JSON.parse(messageData) as SolidNotificationMessage);
};
this.socket.onclose = this.onClose.bind(this);
this.socket.onclose = () => {
this.onClose();
};
this.socket.onerror = (err) => {
this.onNotificationError(
@ -129,10 +131,12 @@ export class Websocket2023NotificationSubscription extends SolidNotificationSubs
}
protected async close(): Promise<void> {
this.socket?.terminate();
this.socket?.close();
}
}
function createWebsocketDefault(address: string) {
return new WebSocket(address);
function createWebsocketDefault(address: string): WebSocket {
const WebSocketImpl =
typeof window !== "undefined" ? window.WebSocket : WebSocket;
return new WebSocketImpl(address) as WebSocket;
}

@ -47,6 +47,26 @@ export class ConnectedLdoDataset<
);
}
private getValidPlugin(
uri: string,
pluginName?: string,
): Plugins[number] | undefined {
// Check for which plugins this uri is valid
const validPlugins = this.plugins
.filter((plugin) => plugin.isUriValid(uri))
.filter((plugin) => (pluginName ? pluginName === plugin.name : true));
if (validPlugins.length === 0) {
return undefined;
} else if (validPlugins.length > 1) {
// TODO: LDO is currently not architected to have an ID valid in multiple
// protocols. This will need to be refactored if this is ever the case.
throw new Error(
"LDO Connect does not currently support two plugins with overlappng uris",
);
}
return validPlugins[0];
}
/**
* Retireves a representation of a Resource at the given URI. This resource
* represents the current state of the resource: whether it is currently
@ -69,20 +89,8 @@ export class ConnectedLdoDataset<
Plugin extends Extract<Plugins[number], { name: Name }>,
UriType extends string,
>(uri: UriType, pluginName?: Name): GetResourceReturnType<Plugin, UriType> {
// Check for which plugins this uri is valid
const validPlugins = this.plugins
.filter((plugin) => plugin.isUriValid(uri))
.filter((plugin) => (pluginName ? pluginName === plugin.name : true));
if (validPlugins.length === 0) {
return new InvalidIdentifierResource(uri) as any;
} else if (validPlugins.length > 1) {
// TODO: LDO is currently not architected to have an ID valid in multiple
// protocols. This will need to be refactored if this is ever the case.
throw new Error(
"LDO Connect does not currently support two plugins with overlappng uris",
);
}
const plugin = validPlugins[0];
const plugin = this.getValidPlugin(uri, pluginName);
if (!plugin) return new InvalidIdentifierResource(uri) as any;
const normalizedUri = plugin.normalizeUri?.(uri) ?? uri;
let resource = this.resourceMap.get(normalizedUri);
@ -111,6 +119,16 @@ export class ConnectedLdoDataset<
return newResourceResult as any;
}
forgetResource(uri: string): boolean {
const plugin = this.getValidPlugin(uri);
const normalizedUri = plugin?.normalizeUri?.(uri) ?? uri;
return this.resourceMap.delete(normalizedUri);
}
forgetAllResources(): void {
this.resourceMap.clear();
}
/**
* Shorthand for solidLdoDataset
* .usingType(shapeType)

@ -105,6 +105,13 @@ export class ConnectedLdoTransactionDataset<Plugins extends ConnectedPlugin[]>
this.context.dataset.setContext(name, context);
}
forgetResource(uri: string): boolean {
return this.context.dataset.forgetResource(uri);
}
forgetAllResources(): void {
this.context.dataset.forgetAllResources();
}
/**
* Retireves a representation (either a LeafResource or a ContainerResource)
* of a Solid Resource at the given URI. This resource represents the

@ -52,6 +52,10 @@ export interface IConnectedLdoDataset<Plugins extends ConnectedPlugin[]>
name: Name,
): Promise<ReturnType<Plugin["createResource"]>>;
forgetResource(uri: string): boolean;
forgetAllResources(): void;
setContext<
Name extends Plugins[number]["name"],
Plugin extends Extract<Plugins[number], { name: Name }>,

@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};

@ -3,5 +3,15 @@ module.exports = {
...sharedConfig,
rootDir: "./",
testEnvironment: "jsdom",
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
"^.+\\.(js|jsx)$": "babel-jest",
},
transformIgnorePatterns: ["/node_modules/(?!(jose)/)"],
globals: {
"ts-jest": {
isolatedModules: true,
},
},
setupFiles: ["<rootDir>/jest.setup.ts"],
};

@ -1 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import "@inrupt/jest-jsdom-polyfills";
jest.mock("undici", () => {
return {
fetch: global.fetch,
};
});

@ -26,13 +26,18 @@
},
"homepage": "https://github.com/o-development/ldobjects/tree/main/packages/solid-react#readme",
"devDependencies": {
"@babel/core": "^7.26.10",
"@babel/preset-env": "^7.26.9",
"@inrupt/jest-jsdom-polyfills": "^3.2.6",
"@ldo/rdf-utils": "^1.0.0-alpha.1",
"@rdfjs/types": "^1.0.1",
"@testing-library/react": "^14.1.2",
"babel-jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"start-server-and-test": "^2.0.3",
"ts-node": "^10.9.2"
"ts-jest": "^29.3.0",
"ts-node": "^10.9.2",
"whatwg-fetch": "^3.6.20"
},
"dependencies": {
"@inrupt/solid-client-authn-browser": "^2.0.0",

@ -9,6 +9,7 @@ import {
} from "./setUpServer";
import { UnauthenticatedSolidLdoProvider } from "../src/UnauthenticatedSolidLdoProvider";
import {
dataset,
useLdo,
useMatchObject,
useMatchSubject,
@ -23,21 +24,14 @@ import type { PostSh } from "./.ldo/post.typings";
// Use an increased timeout, since the CSS server takes too much setup time.
jest.setTimeout(40_000);
const oldFetch = global.fetch;
global.fetch = async (
input: string | Request | URL,
init?: RequestInit | undefined,
): Promise<Response> => {
console.log("-------");
console.log(input, init);
const response = await oldFetch(input, init);
console.log(response.status);
return response;
};
describe("Integration Tests", () => {
setUpServer();
afterEach(() => {
dataset.forgetAllResources();
dataset.deleteMatches(undefined, undefined, undefined, undefined);
});
/**
* ===========================================================================
* useResource
@ -56,7 +50,6 @@ describe("Integration Tests", () => {
</UnauthenticatedSolidLdoProvider>,
);
await screen.findByText("Loading");
debug();
const resourceStatus = await screen.findByRole("status");
expect(resourceStatus.innerHTML).toBe("dataReadSuccess");
});

Loading…
Cancel
Save