Skip to content

Commit abcf56d

Browse files
author
Alain Bourgeois
committed
Map solid-logic to local source in Jest
Mock @uvdsl/solid-oidc-client-browser for JSDOM tests Keep TypeScript config stable for linked workspace development Preserve pane behavior while upstream auth/session contracts change
1 parent cf62f64 commit abcf56d

4 files changed

Lines changed: 73 additions & 4 deletions

File tree

jest.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export default {
1919
'\\.svg\\?raw$': '<rootDir>/test/__mocks__/fileMock.js',
2020
'\\.(svg)$': '<rootDir>/test/__mocks__/fileMock.js',
2121
'\\.(png|jpe?g|gif|webp|avif)$': '<rootDir>/test/__mocks__/fileMock.js',
22-
'\\.css$': '<rootDir>/test/__mocks__/styleMock.js'
22+
'\\.css$': '<rootDir>/test/__mocks__/styleMock.js',
23+
'solid-logic': '<rootDir>/../solid-logic/src/index.ts',
24+
'solid-oidc-client-browser': '<rootDir>/test/mocks/solid-oidc-client-browser.ts'
2325
},
2426
setupFilesAfterEnv: ['./test/helpers/setup.ts'],
2527
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],

src/mainPage/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const applyMenuCollapsedState = (navMenu: HTMLElement | null): void => {
5959
updateCollapseButtonPosition(navMenu, collapseBtn)
6060
}
6161

62-
const isLoggedIn = (): boolean => Boolean(authSession?.info?.isLoggedIn)
62+
const isLoggedIn = (): boolean => Boolean(authSession?.isActive)
6363

6464
const ensureMenuSkeleton = () => {
6565
menuCollapsed = loadMenuCollapsedState()
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
type Listener = (...args: any[]) => void
2+
3+
class EventEmitterLike {
4+
private listeners: Record<string, Listener[]> = {}
5+
6+
on(event: string, listener: Listener): void {
7+
const list = this.listeners[event] || []
8+
list.push(listener)
9+
this.listeners[event] = list
10+
}
11+
12+
emit(event: string, ...args: any[]): void {
13+
const list = this.listeners[event] || []
14+
list.forEach(listener => listener(...args))
15+
}
16+
}
17+
18+
export class Session {
19+
info: { webId?: string, isLoggedIn: boolean } = { isLoggedIn: false }
20+
webId?: string
21+
isActive = false
22+
events = new EventEmitterLike()
23+
24+
addEventListener(event: string, listener: Listener): void {
25+
this.events.on(event, listener)
26+
}
27+
28+
async handleIncomingRedirect(): Promise<void> {
29+
return
30+
}
31+
32+
async handleRedirectFromLogin(): Promise<void> {
33+
return
34+
}
35+
36+
async restore(): Promise<void> {
37+
return
38+
}
39+
40+
async login(): Promise<void> {
41+
return
42+
}
43+
44+
async logout(): Promise<void> {
45+
this.info = { isLoggedIn: false }
46+
this.webId = undefined
47+
this.isActive = false
48+
}
49+
50+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
51+
return globalThis.fetch(input, init)
52+
}
53+
54+
authFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
55+
return globalThis.fetch(input, init)
56+
}
57+
}

tsconfig.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@
5757
] /* List of folders to include type definitions from. */,
5858
// "types": [], /* Type declaration files to be included in compilation. */
5959
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
60-
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
61-
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
60+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
61+
"preserveSymlinks": true, /* Keep symlinks unresolved to avoid duplicate rdflib type identities in local linked dev. */
62+
/* baseUrl + paths below are for local integrated dev only.
63+
They force a single rdflib type identity when solid-panes is linked to local solid-logic/solid-ui.
64+
Both options are deprecated in TS6+ but remain functional until TS7.
65+
See solid-ui README: Local Integrated Development for context. */
66+
"ignoreDeprecations": "6.0",
67+
"baseUrl": ".",
68+
"paths": {
69+
"rdflib": ["node_modules/rdflib"],
70+
"rdflib/*": ["node_modules/rdflib/*"]
71+
}
6272

6373
/* Source Map Options */
6474
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */

0 commit comments

Comments
 (0)