Skip to content

tests: add some tests for the webapp#368

Open
henryiii wants to merge 1 commit intomainfrom
henryiii/chore/webapptests
Open

tests: add some tests for the webapp#368
henryiii wants to merge 1 commit intomainfrom
henryiii/chore/webapptests

Conversation

@henryiii
Copy link
Copy Markdown
Collaborator

@henryiii henryiii commented Apr 6, 2026

Adding some tests, vscode + copilot.

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial Bun-based unit/component tests for the TypeScript webapp and wires them into the repository’s CI workflow, with a small refactor to make URL-related helpers independently testable.

Changes:

  • Introduces Bun test suites for URL utilities, GitHub API ref fetching, and IfUrlLink rendering.
  • Extracts URL parsing/sanitization helpers into a dedicated module and updates the app to use it.
  • Adds test-oriented TypeScript config and updates CI/scripts to run bun test.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tsconfig.test.json New TS config intended for type-checking test files with Bun types.
tsconfig.json Excludes *.test.ts/tsx from the main TS compilation.
src/repo-review-app/utils/url.ts New shared helpers for packageDir sanitization + refType parsing.
src/repo-review-app/utils/url.test.ts Unit tests for the new URL helpers.
src/repo-review-app/utils/github.ts Adds explicit JSON typing for GitHub refs responses.
src/repo-review-app/utils/github.test.ts Unit tests for fetchRepoRefs using a mocked fetch.
src/repo-review-app/repo-review-app.tsx Uses extracted URL helpers instead of inline functions.
src/repo-review-app/components/IfUrlLink.test.tsx Component-level rendering tests via renderToStaticMarkup.
package.json Adds test and type:test scripts; adds @types/bun.
bun.lock Lockfile updates for Bun/Node typing dependencies.
.github/workflows/ci.yml Runs Bun tests in CI.
Comments suppressed due to low confidence (1)

src/repo-review-app/utils/github.ts:25

  • branches/tags are already parsed as Array<{ name: string }> but the subsequent map still uses (branch: any) / (tag: any). This defeats the purpose of the cast and can hide JSON-shape regressions. Use the inferred element type (or define a RefJson type) and drop the any annotations in the map callbacks.
    const branches = (await branchesResponse.json()) as Array<{
      name: string;
    }>;
    const tags = (await tagsResponse.json()) as Array<{ name: string }>;

    return {
      branches: branches.map((branch: any) => ({
        name: branch.name,
        type: "branch",
      })),
      tags: tags.map((tag: any) => ({ name: tag.name, type: "tag" })),
    };

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to +30

beforeEach(() => {
savedFetch = globalThis.fetch;
spyOn(console, "error").mockImplementation(() => {});
});

afterEach(() => {
globalThis.fetch = savedFetch;
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.error is spied on in beforeEach but never restored in afterEach. This can leak the mocked implementation into other test files (and can also accumulate spies across tests). Capture the spy returned by spyOn(...) and restore it in afterEach (or call the appropriate restore method supported by bun:test).

Suggested change
beforeEach(() => {
savedFetch = globalThis.fetch;
spyOn(console, "error").mockImplementation(() => {});
});
afterEach(() => {
globalThis.fetch = savedFetch;
let consoleErrorSpy: ReturnType<typeof spyOn>;
beforeEach(() => {
savedFetch = globalThis.fetch;
consoleErrorSpy = spyOn(console, "error");
consoleErrorSpy.mockImplementation(() => {});
});
afterEach(() => {
globalThis.fetch = savedFetch;
consoleErrorSpy.mockRestore();

Copilot uses AI. Check for mistakes.
@@ -42,6 +42,8 @@ jobs:
run: bun run lint
- name: Run type checker
run: bun run type
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI runs bun run type, but tsconfig.json now excludes *.test.ts/tsx and the new type:test script isn’t executed. This means TypeScript errors in tests won’t be caught by CI. Add a CI step to run bun run type:test (or adjust the existing typecheck to cover both app code and tests).

Suggested change
run: bun run type
run: bun run type
- name: Run test type checker
run: bun run type:test

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants