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

test: Add detox with a simple e2e test #396

Merged
merged 20 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ name: pr

on: [pull_request]

env:
SIS_HAWK_KEY: ${{ secrets.SIS_STAGING_HAWK_KEY }}
SIS_SENTRY_ORG: ${{ secrets.SIS_STAGING_SENTRY_ORG }}
SIS_SENTRY_PROJECT: ${{ secrets.SIS_STAGING_SENTRY_PROJECT }}
SIS_SENTRY_AUTH_TOKEN: ${{ secrets.SIS_STAGING_SENTRY_AUTH_TOKEN }}

jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -11,11 +17,34 @@ jobs:
run: |
yarn install
yarn lint
test:
runs-on: ubuntu-latest
test-e2e:
runs-on: macOS-latest
steps:
- uses: actions/checkout@v1
- name: Run yarn test
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-cache: true
- name: Install applesimutils
run: |
yarn install
yarn test
brew tap wix/brew
brew install applesimutils
- run: yarn install
- name: Generate staging app.json
run: ./scripts/generateAppJson.js
- name: Download ExpoClient binary
run: ./e2e/dl_expo_bins.sh
- name: Run E2E Tests
run: |
# Start packager in background
yarn start >/dev/null &
PID=$(ps $! | tail -1 | awk '{print $1}')
# Run e2e test
yarn test:e2e
# Kill packager
kill $PID
- uses: actions/upload-artifact@master
if: always()
with:
name: test-e2e-artifacts
path: ./artifacts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# expo
.expo/
.tmp/
bin/

# dependencies
/node_modules
Expand Down
8 changes: 6 additions & 2 deletions App/Screens/ErrorScreen/ErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { t } from '../../localization';
import { ErrorContext } from '../../stores';
import { track, trackScreen } from '../../util/amplitude';
import { sentryError } from '../../util/sentry';
import { testIds } from '../../util/testId';
import * as theme from '../../util/theme';
import { ErrorStackParams } from '../routeParams';

Expand Down Expand Up @@ -72,7 +73,7 @@ export function ErrorScreen(props: ErrorScreenProps): React.ReactElement {
}, [error]);

return (
<View style={styles.container}>
<View style={styles.container} testID={testIds.Error.screen}>
<Image source={errorPicture} />
<View>
<Text style={styles.errorText}>
Expand All @@ -92,7 +93,10 @@ export function ErrorScreen(props: ErrorScreenProps): React.ReactElement {
</Button>
<Text style={theme.text}>{t('error_screen_error_description')}</Text>
<ScrollView style={styles.errorScrollView}>
<TouchableOpacity onPress={(): void => setShowDetails(!showDetails)}>
<TouchableOpacity
onPress={(): void => setShowDetails(!showDetails)}
testID={testIds.Error.showDetails}
>
{showDetails ? (
<Text style={styles.errorMessage}>
{t('error_screen_error_message', {
Expand Down
25 changes: 25 additions & 0 deletions App/util/testId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

/**
* Ids used for detox
*/
export const testIds = {
Error: {
screen: 'Error.screen',
showDetails: 'Error.showDetails',
},
};
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This app is bootstrapped with [Expo](https://expo.io), you can download the Expo
| Release Channel | Version | Description | Url |
| --------------------------------------------------------------------------------------------- | ------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| [Production](https://exp.host/@amaurymartiny/shoot-i-smoke?release-channel=production-v1.5.7) | v1.5.7 | Same version as Sh\*\*t! I Smoke on the App Store and Play Store. | `https://exp.host/@amaurymartiny/shoot-i-smoke?release-channel=production-v1.5.7` |
| [Staging](https://exp.host/@amaurymartiny/shoot-i-smoke) | v1.6.0 | Latest version currently in development: newest features, may contain bugs. | `https://exp.host/@amaurymartiny/shoot-i-smoke` |
| [Staging](https://exp.host/@amaurymartiny/shoot-i-smoke) | v1.6.2 | Latest version currently in development: newest features, may contain bugs. | `https://exp.host/@amaurymartiny/shoot-i-smoke` |

## :hammer: Build it yourself

Expand All @@ -67,7 +67,7 @@ yarn install
cp app.example.json app.json

# Run the app with Expo
yarn start --config app.json
yarn start
```

The [Expo](https://expo.io) packager will show, and you can either:
Expand Down
17 changes: 17 additions & 0 deletions e2e/ambiend.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

declare module 'detox-expo-helpers';
5 changes: 5 additions & 0 deletions e2e/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"preset": "ts-jest",
"setupFilesAfterEnv": ["./init.ts"],
"testEnvironment": "node"
}
23 changes: 23 additions & 0 deletions e2e/dl_expo_bins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# Source: https://github.com/yaron1m/expo-detox-typescript-example/blob/master/scripts/dl_expo_bins
set -eo pipefail

# query expo.io to find most recent ipaUrl
IPA_URL=$(curl -sS https://expo.io/--/api/v2/versions | python2 -c 'import sys, json; print json.load(sys.stdin)["iosUrl"]')
# Skipping android apk dl for now
# APK_URL=$(curl -sS https://expo.io/--/api/v2/versions | python -c 'import sys, json; print json.load(sys.stdin)["androidUrl"]')

# download tar.gz
TMP_PATH_IPA=/tmp/exponent-app.tar.gz
curl -o $TMP_PATH_IPA "$IPA_URL"

# recursively make app dir
APP_PATH=bin/Exponent.app
mkdir -p $APP_PATH

# create apk (isn't stored tar'd)
# APK_PATH=bin/Exponent.apk
# curl -o $APK_PATH "$APK_URL"

# unzip tar.gz into APP_PATH
tar -C $APP_PATH -xzf $TMP_PATH_IPA
38 changes: 38 additions & 0 deletions e2e/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

import { cleanup, init } from 'detox';
import adapter from 'detox/runners/jest/adapter';

const config = require('../package.json').detox;

jest.setTimeout(30 * 60 * 1000); // 30 minutes timeout
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
jasmine.getEnv().addReporter(adapter);

beforeAll(async () => {
await init(config);
});

beforeEach(async () => {
await adapter.beforeEach();
});

afterAll(async () => {
await adapter.afterAll();
await cleanup();
});
45 changes: 45 additions & 0 deletions e2e/locationDenied.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2020 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <https://www.gnu.org/licenses/>.

import { by, element, expect } from 'detox';
import { reloadApp } from 'detox-expo-helpers';

import { testIds } from '../App/util/testId';

describe('Location denied', () => {
// Load the app first, so that subsequent tests are faster (and don't timeout)
beforeAll(async () => {
await reloadApp();
});

it('should go to Error page if location not allowed', async () => {
await reloadApp({
permissions: { location: 'never' },
});
await expect(element(by.id(testIds.Error.screen))).toBeVisible();
});

it('should show the error details', async () => {
await reloadApp({
permissions: { location: 'never' },
});

await element(by.id(testIds.Error.showDetails)).tap();
await expect(element(by.id(testIds.Error.showDetails))).toHaveLabel(
'Error: Permission to access location was denied'
);
});
});
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ module.exports = {
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js' // https://github.com/facebook/react-native/issues/21075#issuecomment-441332894
}
},
};
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@
"private": true,
"scripts": {
"lint": "tsc --noEmit --skipLibCheck && eslint --ext .ts,.tsx App",
"start": "expo start --config app.staging.json",
"test": "echo Skipped, see https://github.com/amaurymartiny/shoot-i-smoke/issues/19."
"start": "expo start",
"test:e2e": "detox test --configuration ios.sim --record-videos all"
},
"detox": {
"configurations": {
"ios.sim": {
"binaryPath": "bin/Exponent.app",
"type": "ios.simulator",
"name": "iPhone 11 Pro Max"
}
},
"test-runner": "jest"
},
"dependencies": {
"@apollo/client": "^3.0.0-beta.41",
Expand All @@ -27,16 +37,20 @@
"@shootismoke/convert": "^0.2.8",
"@shootismoke/dataproviders": "^0.2.23",
"@shootismoke/graphql": "^0.2.22",
"@types/detox": "^14.5.2",
"@types/haversine": "^1.1.4",
"@types/i18n-js": "^3.0.1",
"@types/p-any": "^1.1.3",
"@types/react-native": "^0.62.1",
"apollo-cache-persist": "^0.1.1",
"date-fns": "^2.11.1",
"detox": "^16.1.1",
"detox-expo-helpers": "^0.6.0",
"expo": "^37.0.0",
"expo-analytics-amplitude": "~8.1.0",
"expo-av": "~8.1.0",
"expo-constants": "~9.0.0",
"expo-detox-hook": "^1.0.10",
"expo-font": "~8.1.0",
"expo-localization": "~8.1.0",
"expo-location": "~8.1.0",
Expand Down
Loading