-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: streamline beta switch initialization and add tests #1682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Oksamies
merged 1 commit into
xmas-features
from
12-23-refactor_streamline_beta_switch_initialization_and_add_tests
Dec 23, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| type TestWindow = { | ||
| location: { | ||
| hostname: string; | ||
| pathname: string; | ||
| assign: (url: string) => void; | ||
| }; | ||
| }; | ||
|
|
||
| type TestElement = { | ||
| tag: string; | ||
| attributes: Map<string, string>; | ||
| setAttribute: (key: string, value: string) => void; | ||
| onclick?: (() => void) | null; | ||
| innerHTML: string; | ||
| cloneNode: (deep?: boolean) => TestElement; | ||
| }; | ||
|
|
||
| type TestDocument = { | ||
| readyState: "complete" | "interactive" | "loading"; | ||
| createElement: (tag: string) => TestElement; | ||
| addEventListener: (type: string, listener: () => void) => void; | ||
| removeEventListener: (type: string, listener: () => void) => void; | ||
| querySelector: ( | ||
| selector: string | ||
| ) => { appendChild: (child: TestElement) => void } | null; | ||
| }; | ||
|
|
||
| describe("@thunderstore/beta-switch", () => { | ||
| it("can be imported without window/document (SSR-safe)", async () => { | ||
| // Ensure SSR-like environment | ||
| const g = globalThis as unknown as { window?: unknown; document?: unknown }; | ||
| delete g.window; | ||
| delete g.document; | ||
|
|
||
| await expect(import("../index")).resolves.toBeTruthy(); | ||
| }); | ||
|
|
||
| it("inserts switch button into #nimbusBeta when container exists", async () => { | ||
| const appended: TestElement[] = []; | ||
|
|
||
| const desktopContainer = { | ||
| appendChild: (child: TestElement) => appended.push(child), | ||
| }; | ||
|
|
||
| const createElement = (tag: string) => { | ||
| const element: TestElement = { | ||
| tag, | ||
| attributes: new Map<string, string>(), | ||
| setAttribute: (k: string, v: string) => element.attributes.set(k, v), | ||
| onclick: undefined, | ||
| innerHTML: "", | ||
| cloneNode: () => ({ | ||
| ...element, | ||
| attributes: new Map(element.attributes), | ||
| }), | ||
| }; | ||
| return element; | ||
| }; | ||
|
|
||
| const addEventListener = vi.fn(); | ||
| const removeEventListener = vi.fn(); | ||
|
|
||
| const g = globalThis as unknown as { window?: unknown; document?: unknown }; | ||
|
|
||
| const w: TestWindow = { | ||
| location: { | ||
| hostname: "thunderstore.temp", | ||
| pathname: "/", | ||
| assign: vi.fn(), | ||
| }, | ||
| }; | ||
|
|
||
| const d: TestDocument = { | ||
| readyState: "complete", | ||
| createElement, | ||
| addEventListener: | ||
| addEventListener as unknown as TestDocument["addEventListener"], | ||
| removeEventListener: | ||
| removeEventListener as unknown as TestDocument["removeEventListener"], | ||
| querySelector: (selector: string) => | ||
| selector === "#nimbusBeta" ? desktopContainer : null, | ||
| }; | ||
|
|
||
| g.window = w; | ||
| g.document = d; | ||
|
|
||
| const mod: typeof import("../index") = await import("../index"); | ||
| mod.initBetaSwitch(); | ||
|
|
||
| expect(appended.length).toBe(1); | ||
| expect(appended[0].tag).toBe("button"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test uses outdated hostname. The implementation changed from
thunderstore.temptothunderstore.localhost(beta-switch.js line 130, index.ts line 185), but the test still uses the old value. While the test may still pass due to fallback logic, it's not properly testing the dev environment detection.Spotted by Graphite Agent

Is this helpful? React 👍 or 👎 to let us know.