fix(tests): ensure @screenly/edge-apps mock is applied before fetcher import - #4
Draft
nicomiguelino wants to merge 1 commit into
Draft
fix(tests): ensure @screenly/edge-apps mock is applied before fetcher import#4nicomiguelino wants to merge 1 commit into
nicomiguelino wants to merge 1 commit into
Conversation
… 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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
CI on PR #3 (the @screenly/edge-apps 1.2.0 to 1.2.1 dependency bump) is failing with:
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 exportsHardware(viaexport * 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.tsstatically imported./fetcherbefore callingmock.module('@screenly/edge-apps', ...). Since./fetcheritself importsHardwarefrom@screenly/edge-appsat 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.tsandutils.test.tseach register their ownmock.module('@screenly/edge-apps', ...)for that specifier, and neither of those mocks include aHardwareexport. Bun's module mock registry is shared across the whole test run, so if one of those files' mock is still the active registration whenfetcher.test.tsstarts loading,./fetcher's static import ofHardwarelinks against that Hardware-less mock and throws the SyntaxError, exactly what CI hit.Fix
import { CAPFetcher } from './fetcher'at the top offetcher.test.tsmock.module('@screenly/edge-apps', ...)registration where it is (with the local Hardware mock included)await import('./fetcher')only after the mock is registered, guaranteeing./fetcheralways links against this file's own mockMock shape and test behavior are unchanged, this is purely a load-order fix.
Test plan
gh run view --log-failedon PR chore(deps): bump @screenly/edge-apps to 1.2.1 #3's run@screenly/edge-apps@1.2.1does exportHardwarebun run test(full suite, 3 files) repeatedly: 170 pass, 0 failbun run format:check,bun run type-check,bun run lint, andbun run build: all clean.github/