Skip to content

Added react native tests#1473

Open
ArnabChatterjee20k wants to merge 7 commits intomasterfrom
realtime-fixes
Open

Added react native tests#1473
ArnabChatterjee20k wants to merge 7 commits intomasterfrom
realtime-fixes

Conversation

@ArnabChatterjee20k
Copy link
Copy Markdown
Member

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR adds a browser-based Playwright test harness for the React Native SDK, including a Rollup bundling pipeline that shims react-native with react-native-web and expo-file-system with a stub, alongside small template fixes (ping() helper, request model generation, multipart/form-data async guard, and a Platform.OS === 'web' WebSocket branch).

  • The realtime endpoint in browser.js is set to wss://cloud.appwrite.io/v1, but within the mockapi Docker network only the mockapi hostname resolves to the mock server. This will cause both responseRealtime and responseRealtimeWithQueries to remain 'Realtime failed!', failing the REALTIME_RESPONSES[0] and REALTIME_RESPONSES[1] PHP assertions in CI.

Confidence Score: 3/5

Not safe to merge — the realtime endpoint misconfiguration will cause CI test failures.

One P1 finding: the hardcoded wss://cloud.appwrite.io/v1 realtime endpoint in the browser test will not reach the mock server, breaking the realtime assertion checks. All other changes look structurally sound.

tests/languages/react-native/browser.js — the setEndpointRealtime call on line 205.

Important Files Changed

Filename Overview
tests/languages/react-native/browser.js Main browser test bundle — hardcodes the production realtime endpoint instead of the mock server, which will cause all WebSocket assertion checks to produce incorrect output and fail CI.
tests/ReactNativeTest.php New PHP test class — build steps and expected output look correct, though the realtime assertions will fail due to the wrong WS endpoint in browser.js.
templates/react-native/src/client.ts.twig Adds a ping() helper method consistent with the web SDK template; return type annotation Promise<string> is a pre-existing pattern across the codebase.
templates/react-native/src/services/template.ts.twig Changes async guard from method.type == 'upload' to 'multipart/form-data' in method.consumes on all three overloads; semantics differ (flagged in a prior review thread).
templates/web/src/services/realtime.ts.twig Adds a Platform.OS === 'web' guard so that the WebSocket constructor is called without the headers option when running in a browser environment, which is correct.
tests/languages/react-native/tests.js Playwright runner — correctly uses waitForFunction to poll window.__APPWRITE_TEST_DONE__; mirrors the web SDK test pattern.
tests/languages/react-native/rollup.test.config.mjs Rollup config for bundling the test browser entry point; aliases react-nativereact-native-web and shims expo-file-system correctly.
templates/react-native/src/models.ts.twig Adds request model type generation, mirroring the existing response model pattern.
tests/languages/react-native/shims/expo-file-system.js Throws on any file-system call, cleanly preventing accidental upload tests from silently passing in the browser shim environment.

Reviews (6): Last reviewed commit: "fix: skip non-spec WebSocket third arg o..." | Re-trigger Greptile

Comment thread tests/languages/react-native/tests.js Outdated
Comment thread tests/ReactNativeTest.php Outdated
Comment on lines +24 to +26
});
page.on('pageerror', err => {
console.log('PAGE ERROR: ' + err.message);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Page errors don't affect exit code

pageerror events are logged via console.log, which means they'll appear in captured output but won't cause the process to exit with a non-zero code. The current approach relies entirely on PHP's expected-output comparison to catch page-level JS errors. This is consistent with the web SDK test pattern, but worth noting that if an unhandled page error produces no console output (e.g., a thrown but uncaught promise in a non-async context), it could silently swallow failures.

Comment thread templates/react-native/src/services/template.ts.twig
@abnegate
Copy link
Copy Markdown
Member

@copilot Fix the failing react native test

abnegate and others added 4 commits April 29, 2026 20:22
@rollup/plugin-typescript requires the TypeScript compiler's outDir to
sit inside the directory of the Rollup output file. Without an explicit
outDir the plugin inferred a path outside dist/ and refused to render
the bundle, leaving the playwright runner with nothing to load.

Also: drop the redundant serve-handler from the no-save install (it is
already a dev dependency), and replace the hard 20s timeout with
page.waitForFunction so a fast-failing test exits sooner.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The PING_RESPONSE assertion in ReactNativeTest hit a TypeError because
the generated Client had no ping(); the test runner aborted before any
SDK call landed, which cascaded into the whole expected-output diff.

Mirrors the web template's existing helper (templates/web/src/client.ts.twig:864).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The React Native realtime template called the WebSocket constructor
with three arguments (url, protocols, headers) — a React Native runtime
extension that the React Native test bundle (which aliases react-native
to react-native-web) cannot service via the browser's native WebSocket.
Newer Chromium dispatched an immediate error event, the subscribe()
promise rejected, and the test runner aborted before any of the foo/bar
calls landed.

When Platform.OS reports 'web' the SDK is running in a browser host,
so the browser already attaches its own Origin header and no third
argument is needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
console.log(Query.between('name', 'Anna', 'Brad'));
console.log(Query.startsWith('name', 'Ann'));
console.log(Query.endsWith('name', 'nne'));
console.log(Query.select(['name', 'age']));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Wrong realtime endpoint points to production instead of the mock server

setEndpointRealtime('wss://cloud.appwrite.io/v1') sends WebSocket traffic to the real Appwrite cloud, not the mock API container. Within the mockapi Docker network, cloud.appwrite.io does not resolve to mockapi, so the WS connection will either reach the real cloud (which won't emit WS:/v1/realtime:passed) or fail DNS resolution. Either way, responseRealtime and responseRealtimeWithQueries stay as 'Realtime failed!', causing the PHP assertions for REALTIME_RESPONSES[0] and REALTIME_RESPONSES[1] to fail.

The mock server is reachable as ws://mockapi/v1. A simple fix is to drop the explicit call (since setEndpoint auto-derives endpointRealtime from the HTTP endpoint), or set it explicitly to the mock address:

Suggested change
console.log(Query.select(['name', 'age']));
client.setEndpointRealtime('ws://mockapi/v1');

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