Skip to content

Commit

Permalink
fix: Make WebSocketTests work in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Cipolleschi committed Apr 27, 2022
1 parent ecf3293 commit d8fa937
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ jobs:
# -------------------------
# JOBS: iOS Unit Tests
# -------------------------
test_ios_unit:
ios_unit_and_integration_tests:
executor: reactnativeios
parameters:
use_frameworks:
Expand Down Expand Up @@ -1252,16 +1252,16 @@ workflows:
- build_npm_package
- test_ios_rntester
- build_ios
- test_ios_unit:
- ios_unit_and_integration_tests:
run_unit_tests: true
requires:
- build_ios
# DISABLED: USE_FRAMEWORKS=1 not supported by Flipper
# - build_ios:
# name: build_ios_frameworks
# use_frameworks: true
# - test_ios_unit:
# name: test_ios_unit_frameworks
# - ios_unit_and_integration_tests:
# name: ios_unit_and_integration_tests_frameworks
# use_frameworks: true
# run_unit_tests: true
# requires:
Expand Down
9 changes: 9 additions & 0 deletions IntegrationTests/WebSocketTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class WebSocketTest extends React.Component<{...}, State> {

_connect = () => {
const socket = new WebSocket(this.state.url);
console.log(`>>> Socket server url should be: ${this.state.url}`)
WS_EVENTS.forEach(ev => socket.addEventListener(ev, this._onSocketEvent));
this.setState({
socket,
Expand Down Expand Up @@ -115,31 +116,39 @@ class WebSocketTest extends React.Component<{...}, State> {
}

testConnect: () => void = () => {
console.log('>>> Testing connect...');
this._connect();
this._waitFor(this._socketIsConnected, 5, connectSucceeded => {
if (!connectSucceeded) {
TestModule.markTestPassed(false);
console.log('>>> Connect test failed.');
return;
}
console.log('>>> Connect test ended successfully.');
this.testSendAndReceive();
});
};

testSendAndReceive: () => void = () => {
console.log('>>> Testing sendAndReceive...');
this._sendTestMessage();
this._waitFor(this._receivedTestExpectedResponse, 5, messageReceived => {
if (!messageReceived) {
TestModule.markTestPassed(false);
console.log('>>> Test sendAndReceive failed.');
return;
}
console.log('>>> Test sendAndReceive ended successfully.');
this.testDisconnect();
});
};

testDisconnect: () => void = () => {
console.log('>>> Testing disconnect...');
this._disconnect();
this._waitFor(this._socketIsDisconnected, 5, disconnectSucceeded => {
TestModule.markTestPassed(disconnectSucceeded);
console.log('>>> Test disconnect ended successfully.');
});
};

Expand Down
13 changes: 10 additions & 3 deletions scripts/objc-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,25 @@ preloadBundles() {
curl -s 'http://localhost:8081/IntegrationTests/RCTRootViewIntegrationTestApp.bundle?platform=ios&dev=true' -o /dev/null
}

failForNoWebSocketServer() {
echo "[Error] Can't start websocket server"
exit 2
cleanup EXIT
}

main() {
cd "$ROOT" || exit

# If first argument is "test", actually start the packager and run tests.
# Otherwise, just build RNTester and exit
if [ "$1" = "test" ]; then

# Start the packager
yarn start --max-workers=1 || echo "Can't start packager automatically" &
# Start the WebSocket test server
open "./IntegrationTests/launchWebSocketServer.command" || echo "Can't start web socket server automatically"
echo "Launch WebSocket Server"
open "./IntegrationTests/launchWebSocketServer.command" || failForNoWebSocketServer

# Start the packager
yarn start --max-workers=1 || echo "Can't start packager automatically" &
waitForPackager
preloadBundles

Expand Down

0 comments on commit d8fa937

Please sign in to comment.