Skip to content

fix(jest-compat): run the setup without an engine - #926

Open
swey wants to merge 3 commits into
danfry1:mainfrom
swey:jest-compat-without-engine
Open

swey wants to merge 3 commits into
danfry1:mainfrom
swey:jest-compat-without-engine

Conversation

@swey

@swey swey commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Since 0.15, a project that uses the jest-compat layer without an engine (jestMockTransform() and the setup, no reactNative(), the way a react-native-web suite uses it for the Jest API) fails every test file at startup:

SyntaxError: Unexpected token 'typeof'

The setup now requires react-native through Node to put the native methods on View.prototype. Without an engine nothing compiles React Native's Flow source, so Node chokes on it. 0.14 ran such a project.

The fix skips that step when no engine is configured, which the project context tells; under either engine nothing changes. A new test:native step runs the layer without an engine and fails on main with the error above.

swey added 3 commits November 22, 2026 12:27
Since View.prototype took the native methods, the jest-compat setup ends by
requiring react-native and its NativeComponentRegistry through Node. Under the
native engine the require hooks compile them, and under the mock engine the
stand-in answers. With jestMockTransform() and the setup but no reactNative(),
a project that uses the layer for the Jest API alone, nothing compiles them:
Node parsed React Native's Flow source and every test file failed at startup
with "SyntaxError: Unexpected token 'typeof'". 0.14 ran such a project.

The setup now fills View.prototype only when projectContext() is set. Both
engines' reactNative() write the project context, and nothing else does, so it
tells reliably whether an engine is configured. Chosen over catching a failed
load, which would also hide a real load error under an engine and still parse
React Native's source on every file to find out. Under either engine nothing
changes.

tests-native/vitest.jest-compat-no-engine.config.mts runs the layer with no
engine, in its own test:native step.
tests/fixture-mocks-scope.test.ts reads every tests-native config for
jestMockTransform calls without a mock scope; the comment's mention of the
call counted as one.

This branch has not been deployed

No deployments
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