Skip to content

fix(tests): ensure @screenly/edge-apps mock is applied before fetcher import - #4

Draft
nicomiguelino wants to merge 1 commit into
developmentfrom
fix/mock-module-ordering-in-fetcher-test
Draft

fix(tests): ensure @screenly/edge-apps mock is applied before fetcher import#4
nicomiguelino wants to merge 1 commit into
developmentfrom
fix/mock-module-ordering-in-fetcher-test

Conversation

@nicomiguelino

Copy link
Copy Markdown
Contributor

Summary

CI on PR #3 (the @screenly/edge-apps 1.2.0 to 1.2.1 dependency bump) is failing with:

SyntaxError: Export named 'Hardware' not found in module '.../node_modules/@screenly/edge-apps/dist/index.js'.

reported by bun test as an "Unhandled error between tests" in src/fetcher.test.ts. This is unrelated to the version bump itself, 1.2.1 genuinely exports Hardware (via export * from './types/index.js'). It is a pre-existing test load-order bug that this PR fixes independently of PR #3.

Root cause

src/fetcher.test.ts statically imported ./fetcher before calling mock.module('@screenly/edge-apps', ...). Since ./fetcher itself imports Hardware from @screenly/edge-apps at its own top level, that import gets linked against whatever is registered under that module specifier at load time, not necessarily the mock defined later in the same file.

parser.test.ts and utils.test.ts each register their own mock.module('@screenly/edge-apps', ...) for that specifier, and neither of those mocks include a Hardware export. Bun's module mock registry is shared across the whole test run, so if one of those files' mock is still the active registration when fetcher.test.ts starts loading, ./fetcher's static import of Hardware links against that Hardware-less mock and throws the SyntaxError, exactly what CI hit.

Fix

  • Drop the static import { CAPFetcher } from './fetcher' at the top of fetcher.test.ts
  • Keep the mock.module('@screenly/edge-apps', ...) registration where it is (with the local Hardware mock included)
  • Dynamically await import('./fetcher') only after the mock is registered, guaranteeing ./fetcher always links against this file's own mock

Mock shape and test behavior are unchanged, this is purely a load-order fix.

Test plan

… import

fetcher.test.ts statically imported ./fetcher before calling
mock.module('@screenly/edge-apps', ...). Since ./fetcher itself imports
Hardware from @screenly/edge-apps at its top, that import gets linked
against whichever module is registered under that specifier at the time,
which is not guaranteed to be the mock defined later in this same file.

If another test file's earlier mock.module('@screenly/edge-apps', ...)
call (one that omits Hardware, e.g. parser.test.ts or utils.test.ts) is
still active in the shared module registry when fetcher.test.ts starts
loading, ./fetcher links against that stale, Hardware-less mock and
throws SyntaxError: Export named 'Hardware' not found, surfaced by bun
test as an unhandled error between tests. This is what CI hit.

- Drop the static import of CAPFetcher from ./fetcher
- Register the mock.module() call first
- Dynamically import ./fetcher only after the mock is in place

Mock shape and test behavior are unchanged, this only fixes load order.
@nicomiguelino nicomiguelino self-assigned this Jul 23, 2026
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.

1 participant