Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TESTS] Test in docker #2290

Merged
merged 11 commits into from
Jul 15, 2020
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ buck-out/
coverage

.vscode/
e2e/docker/rc_test_env/docker-compose.yml
e2e/docker/data/db
6 changes: 6 additions & 0 deletions e2e/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"timeout": 300000,
"recursive": true,
"bail": true,
"file":"e2e/tests/init.js"
}
34 changes: 24 additions & 10 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,35 @@

### 1. Prepare test environment

#### 1.1. Set up local Rocket Chat server
#### 1.1. A Rocket.Chat server

Either

* Install Rocket Chat meteor app by following this [guide](https://rocket.chat/docs/developer-guides/quick-start).

Or

* Use the local Docker environment available in this folder. You can start the environment using `./e2e/docker/controlRCDemoEnv.sh startandwait`, or you can use the packaged start & run script (see step 3). Either way, you'll need [Docker](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/).

#### 1.2. Set up detox

* Install dependencies by following this [guide](https://github.com/wix/Detox/blob/master/docs/Introduction.GettingStarted.md#step-1-install-dependencies) (only Step 1).

### 2. Prepare test data

* Run Rocket Chat meteor app: `meteor npm start` (make sure you to run this command from project that you created on Step 1.1.).
* Open `localhost:3000` in browser.
* Sign up as admin.
* Create public room `detox-public`.
* Create user with role: `user`, username: `detoxrn`, email: `YOUR@EMAIL.COM`, password: `123`.
* Create user with role: `user`, username: `YOUR.NAME`, email: `YOUR.SECOND@EMAIL.COM`, password: `123`.
* In file `e2e/data.js` change values `existingEmail` with `YOUR.SECOND@EMAIL.COM`, `existingName` with `YOUR.NAME`.
* Login as user `detoxrn` -> open My Account -> Security tab -> click "Enable two-factor authentication" -> copy TTOLP code -> paste TTOLP code into `./e2e/data.js` file into field: `alternateUserTOTPSecret`.
* If you're running your own Rocket.Chat server, ensure it's started (e.g. `meteor npm start` in the server project directory).
* Edit `e2e/data.js`:
* Set the `server` to the address of the server under test
* Set the `adminUser` and `adminPassword` to an admin user on that environment (or a user with at least `create-user` and `create-c`).
* Working example configs exist in `./e2e/data/`. Setting `FORCE_DEFAULT_DOCKER_DATA` to `1` in the `runTestsInDocker.sh` script will use the example config automatically

### 3. Running tests

#### 3.1. iOS

* Build app with detox: `detox build -c ios.sim.release`
* Open Simulator which is used in tests (check in package.json under detox section) from Xcode and make sure that software keyboard is being displayed. To toggle keyboard press `cmd+K`.
* Run tests: `detox test -c ios.sim.release`
* Run tests: `detox test -c ios.sim.release`, or, if choosing Docker you can run the packaged environment & runner (`./e2e/docker/runTestsInDocker.sh`) which will start the Docker infrastructure, run the tests and tear it down again once done.

#### 3.2. Android

Expand All @@ -50,6 +53,10 @@ Tests have been grouped into subfolders. You can choose to run just one group of

`detox test ./e2e/tests/onboarding -c ios.sim.release`

To do the same with the Docker runner:

`./e2e/docker/runTestsInDocker.sh onboarding`

### 4. FAQ

#### 4.1. Detox build fails
Expand All @@ -68,3 +75,10 @@ Tests have been grouped into subfolders. You can choose to run just one group of
* Make sure software keyboard is displayed in simulator when focusing some input. To enable keyboard press `cmd+K`.
* Make sure you have prepared all [test data](##-2.-Prepare-test-data).
* Sometimes detox e2e tests fail for no reason so all you can do is simply re-run again.

### 5. Todo

* TOTP test
* Push notifications
* Deep linking
* Intermittent connectivity
45 changes: 36 additions & 9 deletions e2e/data.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
const random = require('./helpers/random');
const value = random(20);
const data = {
server: 'https://ilarion.rocket.chat',
server: 'https://mobile.rocket.chat',
adminUser: 'e2e_admin',
adminPassword: 'p7mFh4yLwCRXSnMvG',
alternateServer: 'https://stable.rocket.chat',
user: `user${ value }`,
password: `password${ value }`,
alternateUser: 'detoxrn',
alternateUserPassword: '123',
alternateUserTOTPSecret: 'NFXHKKC6FJXESL25HBYTYNSFKR4WCTSXFRKUUVKEOBBC6I3JKI7A',
existingEmail: 'diego.mello@rocket.chat',
existingName: 'diego.mello',
email: `diego.mello+e2e${ value }@rocket.chat`,
users: {
regular: {
username: `userone${ value }`,
password: '123',
email: `diego.mello+regular${ value }@rocket.chat`
},
alternate: {
username: `usertwo${ value }`,
password: '123',
email: `diego.mello+alternate${ value }@rocket.chat`,
totpSecret: 'NA4GOMZGHBQSK6KEFRVT62DMGJJGSYZJFZIHO3ZOGVXWCYZ6MMZQ'
},
profileChanges: {
username: `userthree${ value }`,
password: '123',
email: `diego.mello+profileChanges${ value }@rocket.chat`
},
existing: {
username: `existinguser${ value }`,
password: '123',
email: `diego.mello+existing${ value }@rocket.chat`
}
},
channels: {
public: {
name: 'detox-public'
}
},
registeringUser: {
username: `newuser${ value }`,
password: `password${ value }`,
email: `diego.mello+registering${ value }@rocket.chat`
},
random: value
}
module.exports = data;
43 changes: 43 additions & 0 deletions e2e/data/data.cloud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const random = require('./helpers/random');
const value = random(20);
const data = {
server: 'https://mobile.rocket.chat',
adminUser: 'e2e_admin',
adminPassword: 'p7mFh4yLwCRXSnMvG',
alternateServer: 'https://stable.rocket.chat',
users: {
regular: {
username: `userone${ value }`,
password: '123',
email: `diego.mello+regular${ value }@rocket.chat`
},
alternate: {
username: `usertwo${ value }`,
password: '123',
email: `diego.mello+alternate${ value }@rocket.chat`,
totpSecret: 'NA4GOMZGHBQSK6KEFRVT62DMGJJGSYZJFZIHO3ZOGVXWCYZ6MMZQ'
},
profileChanges: {
username: `userthree${ value }`,
password: '123',
email: `diego.mello+profileChanges${ value }@rocket.chat`
},
existing: {
username: `existinguser${ value }`,
password: '123',
email: `diego.mello+existing${ value }@rocket.chat`
}
},
channels: {
public: {
name: 'detox-public'
}
},
registeringUser: {
username: `newuser${ value }`,
password: `password${ value }`,
email: `diego.mello+registering${ value }@rocket.chat`
},
random: value
}
module.exports = data;
43 changes: 43 additions & 0 deletions e2e/data/data.docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const random = require('./helpers/random');
const value = random(20);
const data = {
server: 'http://127.0.0.1:3000',
adminUser: 'admin',
adminPassword: 'password',
alternateServer: 'https://stable.rocket.chat',
users: {
regular: {
username: `userone${ value }`,
password: '123',
email: `diego.mello+regular${ value }@rocket.chat`
},
alternate: {
username: `usertwo${ value }`,
password: '123',
email: `diego.mello+alternate${ value }@rocket.chat`,
totpSecret: 'NA4GOMZGHBQSK6KEFRVT62DMGJJGSYZJFZIHO3ZOGVXWCYZ6MMZQ'
},
profileChanges: {
username: `userthree${ value }`,
password: '123',
email: `diego.mello+profileChanges${ value }@rocket.chat`
},
existing: {
username: `existinguser${ value }`,
password: '123',
email: `diego.mello+existing${ value }@rocket.chat`
}
},
channels: {
public: {
name: 'detox-public'
}
},
registeringUser: {
username: `newuser${ value }`,
password: `password${ value }`,
email: `diego.mello+registering${ value }@rocket.chat`
},
random: value
}
module.exports = data;
70 changes: 70 additions & 0 deletions e2e/docker/controlRCDemoEnv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

PAUSE_ON_FAIL_FOR_DEBUG=0

COMMAND="start"
if [ "$1" != "" ]; then
if [[ "$1" =~ ^(start|startandwait|stop)$ ]]; then
COMMAND=$1
else
echo "Invalid command. Must be one of: start,stop"
exit 1
fi
fi

WAIT=0
if [ "$COMMAND" == "startandwait" ]; then
COMMAND="start"
WAIT=1
fi

COMPOSEPATH="$SCRIPTPATH/rc_test_env"
export DATAROOT="$SCRIPTPATH"

if [ "$COMMAND" == "start" ]; then
echo "Fetching infrastructure config from GitHub"
COMPOSEURL=https://raw.githubusercontent.com/RocketChat/Rocket.Chat/develop/docker-compose.yml
COMPOSEFILE="$COMPOSEPATH/docker-compose.yml"
curl -s "$COMPOSEURL" -o "$COMPOSEFILE"

echo "Starting infrastructure"
(
if [ -d "$SCRIPTPATH/data/db" ]; then rm -rf "$SCRIPTPATH/data/db"; fi
cd "$COMPOSEPATH"
docker-compose up -d
)

if [ $WAIT == 1 ]; then
echo "Waiting for RocketChat to be ready"

ATTEMPT_NUMBER=0
MAX_ATTEMPTS=60
while [ $ATTEMPT_NUMBER -lt $MAX_ATTEMPTS ]; do # https://stackoverflow.com/a/21189312/399007
ATTEMPT_NUMBER=$((ATTEMPT_NUMBER + 1 ))
echo "Waiting for server to be up ($ATTEMPT_NUMBER of $MAX_ATTEMPTS)"
LOGS=$(docker logs rc_test_env_rocketchat_1 2> /dev/null)
if grep -q 'SERVER RUNNING' <<< $LOGS ; then
echo "RocketChat is ready!"
break
else
if [ $ATTEMPT_NUMBER == $MAX_ATTEMPTS ]; then
echo "RocketChat failed to start"
if [ $PAUSE_ON_FAIL_FOR_DEBUG == 1 ]; then
read -n 1 -s -r -p "Press any key to tear down infrastructure." && echo
fi
docker-compose down --volumes
exit 1
fi
fi
sleep 4
done
fi
fi

if [ "$COMMAND" == "stop" ]; then
(
cd "$COMPOSEPATH"
docker-compose down --volumes
)
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rs.initiate({
_id: 'rs0',
members: [ { _id: 0, host: 'localhost:27017' } ]})

var masterness = db.isMaster().ismaster
print("MongoDB Master initial state: " + masterness)
while(db.isMaster().ismaster==false) {
print("Waiting for MongoDB election")
sleep(1000)
}
print("Election complete! Ready for data imports.")
1 change: 1 addition & 0 deletions e2e/docker/docker-entrypoint-initdb.d/migrations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db.getCollection("migrations").insert({"_id":"control","locked":false,"version":NumberInt(188),"buildAt":"2020-05-11T19:06:54.422Z","lockedAt":new Date(1591734393789)});

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db.getCollection("rocketchat_custom_user_status").insert({"_id":"y7RDq6exjSuqdxvgT","name":"Pensive","statusType":"busy","_updatedAt":new Date(1589466480022)});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading