refactor: switch from jsdom to happy-dom

This commit is contained in:
2025-02-16 23:59:00 +08:00
parent ba13828093
commit 41f2b04c45
8 changed files with 124 additions and 89 deletions

View File

@@ -1,29 +1,13 @@
import type { Provider } from '@outposts/injection-js';
import { JSDOM } from 'jsdom';
import { AbstractRouter, type Navigation, type UrlTree } from 'oidc-client-rx';
import {
AbstractRouter,
type UrlTree,
VanillaLocationRouter,
} from 'oidc-client-rx';
export class MockRouter extends AbstractRouter {
dom = new JSDOM('', {
url: 'http://localhost',
});
navigation: Navigation = {
extractedUrl: this.parseUrl(this.dom.window.location.href),
};
navigateByUrl(url: string): void {
this.dom.reconfigure({
url: new URL(url, this.dom.window.location.href).href,
});
this.navigation = {
extractedUrl: this.parseUrl(this.dom.window.location.href),
};
}
getCurrentNavigation(): Navigation {
return this.navigation;
}
export class MockRouter extends VanillaLocationRouter {
parseUrl(url: string): UrlTree {
const u = new URL(url, this.dom.window.location.href);
const u = new URL(url, this.document.baseURI);
return `${u.pathname}${u.search}${u.hash}`;
}
}