make tests run

This commit is contained in:
ammarahm-ed
2022-08-08 23:35:48 +05:00
parent 03593af10d
commit de3e135c21
8 changed files with 111 additions and 98 deletions

View File

@@ -1,39 +1,36 @@
{
"testRunner": "jest",
"runnerConfig": "e2e/config.json",
"configurations": {
"ios": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/Notesnook.app",
"build": "xcodebuild -workspace ios/Notesnook.xcworkspace -scheme Notesnook -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"device": {
"type": "iPhone 11 Pro"
}
},
"android.emu.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"devices": {
"emulator": {
"type": "android.emulator",
"name": "emu"
},
"android.dev.debug": {
"binaryPath": "android/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk",
"device": {
"avdName": "Pixel_5_API_31"
}
}
},
"apps": {
"android.debug": {
"type": "android.apk",
"binaryPath": "android/app/build/outputs/apk/debug/app-x86_64-debug.apk",
"testBinaryPath": "android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",
"type": "android.attached",
"device": {
"adbName": "LMG710ULM3d3678f0",
"adbNameAlt": "LMG710ULM3d3678f0"
}
"build": "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd .."
},
"android.dev.release": {
"binaryPath": "android/app/build/outputs/apk/release/app-arm64-v8a-release.apk",
"android.release": {
"type": "android.apk",
"binaryPath": "android/app/build/outputs/apk/release/app-x86_64-release.apk",
"testBinaryPath": "android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
"build": "cd android ; ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release ; cd ..",
"type": "android.attached",
"device": {
"adbName": "LMG710ULM3d3678f0"
}
"build": "cd android ; ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release ; cd .."
}
},
"configurations": {
"android.emu.debug": {
"app": "android.debug",
"device": "emulator"
},
"android.emu.release": {
"app": "android.release",
"device": "emulator"
}
}
}

View File

@@ -14,17 +14,21 @@ import androidx.test.rule.ActivityTestRule;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class DetoxTest {
@Rule
// Replace 'MainActivity' with the value of android:name entry in
// Replace 'MainActivity' with the value of android:name entry in
// <activity> in AndroidManifest.xml
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class, false, false);
@Test
public void runDetoxTests() {
// This is optional - in case you've decided to integrate TestButler
// See https://github.com/wix/Detox/blob/master/docs/Introduction.Android.md#8-test-butler-support-optional
//TestButlerProbe.assertReadyIfInstalled();
DetoxConfig detoxConfig = new DetoxConfig();
detoxConfig.idlePolicyConfig.masterTimeoutSec = 90;
detoxConfig.idlePolicyConfig.idleResourceTimeoutSec = 60;
detoxConfig.rnContextLoadTimeoutSec = (com.streetwriters.notesnook.BuildConfig.DEBUG ? 180 : 60);
detoxConfig.rnContextLoadTimeoutSec = (BuildConfig.DEBUG ? 180 : 60);
Detox.runTests(mActivityRule, detoxConfig);
}

View File

@@ -1,6 +1,4 @@
rootProject.name = 'Notesnook'
include ':detox'
project(':detox').projectDir = new File(rootProject.projectDir, '../node_modules/detox/android/detox')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
includeBuild('../node_modules/react-native-gradle-plugin')

View File

@@ -3,7 +3,7 @@
"testRunner": "jest-circus/runner",
"setupFilesAfterEnv": ["./setup.ts"],
"testTimeout": 120000,
"testRegex": "\\.e2e\\.js$",
"testRegex": "index\\.e2e\\.js$",
"reporters": ["detox/runners/jest/streamlineReporter"],
"verbose": true
}

View File

@@ -1,19 +1,19 @@
export const notesnook = {
editor:{
back:"editor.back",
id:"editor.id"
const notesnook = {
editor: {
back: 'editor.back',
id: 'editor.id'
},
buttons:{
add:"buttons.add"
buttons: {
add: 'buttons.add'
},
toast: {
button:"toast.button"
button: 'toast.button'
},
listitem:{
menu:"listitem.menu"
listitem: {
menu: 'listitem.menu'
},
list:{
id:"list.id"
list: {
id: 'list.id'
},
ids: {
default: {
@@ -21,43 +21,43 @@ export const notesnook = {
menu: 'menu',
dialog: {
yes: 'yes',
no: 'no',
no: 'no'
},
editor: 'editor',
header: {
buttons: {
left: 'left',
right: 'right',
back: 'back',
},
back: 'back'
}
},
actionsheetBackdrop: 'backdrop',
loginToSync: 'login_to_sync',
addBtn: 'btn-add-item',
addBtn: 'btn-add-item'
},
dialogs: {
notebook: {
inputs: {
title: 'title',
description: 'description',
topic: 'topic',
topic: 'topic'
},
buttons: {
add: 'add',
},
add: 'add'
}
},
export: {
pdf: 'pdf',
text: 'text',
md: 'md',
html: 'html',
html: 'html'
},
vault: {
changePwd: 'change_pwd',
pwd: 'pwd',
confirmPwd: 'pwd',
pwdAlt: 'pwd_alt',
fingerprint: 'fingerprint',
fingerprint: 'fingerprint'
},
sortBy: {
order: 'orderby',
@@ -65,13 +65,13 @@ export const notesnook = {
alphabetical: 'btn-alphabetical',
year: 'btn-year',
week: 'btn-week',
month: 'btn-month',
month: 'btn-month'
},
addTo: {
addNotebook: 'input-addNotebook',
addTopic: 'input-addTopic',
btnNotebook: 'btn-addNotebook',
btnTopic: 'btn-addTopic',
btnTopic: 'btn-addTopic'
},
actionsheet: {
delete: 'icon-Delete',
@@ -85,30 +85,34 @@ export const notesnook = {
copy: 'icon-Copy',
sync: 'btn-sync-now',
night: 'nightswitch',
color: (color) => 'icon-color-' + color,
},
color: color => 'icon-color-' + color
}
},
menu: {
nightmode: 'night',
nightmode: 'night'
},
note: {
menu: 'note_menu',
get:(index) => 'note-item-' + index
get: index => 'note-item-' + index
},
notebook: {
menu: 'notebook_menu',
get:(index) => 'notebook-item-' + index
get: index => 'notebook-item-' + index
},
topic: {
menu: 'topic_menu',
get:(index) => 'topic-item-' + index
get: index => 'topic-item-' + index
},
tag: {
tag: {
menu: 'tag_menu',
get:(index) => 'tag-item-' + index
get: index => 'tag-item-' + index
},
list: {
getByType: (type) => 'list-' + type,
},
},
getByType: type => 'list-' + type
}
}
};
module.exports = {
notesnook
};

View File

@@ -1,7 +1,10 @@
const { notesnook } = require('../test.ids');
const fs = require('fs');
const { expect: jestExpect } = require('@jest/globals');
const { toMatchImageSnapshot } = require('jest-image-snapshot');
jestExpect.extend({ toMatchImageSnapshot });
export const sleep = duration =>
const sleep = duration =>
new Promise(resolve =>
setTimeout(() => {
console.log('Sleeping for ' + duration / 1000 + ' secs');
@@ -9,8 +12,7 @@ export const sleep = duration =>
}, duration)
);
export async function LaunchApp() {
await expect(element(by.id(notesnook.ids.default.root))).toBeVisible();
async function LaunchApp() {
await expect(element(by.id('notesnook.splashscreen'))).toBeVisible();
await sleep(500);
await element(by.text('Get started')).tap();
@@ -24,39 +26,39 @@ export async function LaunchApp() {
await sleep(300);
}
export function elementById(id) {
function elementById(id) {
return element(by.id(id)).atIndex(0);
}
export function elementByText(text) {
function elementByText(text) {
return element(by.text(text)).atIndex(0);
}
export async function tapById(id) {
async function tapById(id) {
await elementById(id).tap();
}
export async function tapByText(text) {
async function tapByText(text) {
await elementByText(text).tap();
}
export async function visibleByText(text) {
async function visibleByText(text) {
await expect(elementByText(text)).toBeVisible();
}
export async function visibleById(id) {
async function visibleById(id) {
await expect(elementById(id)).toBeVisible();
}
export async function notVisibleById(id) {
async function notVisibleById(id) {
await expect(elementById(id)).not.toBeVisible();
}
export async function notVisibleByText(text) {
async function notVisibleByText(text) {
await expect(elementByText(text)).not.toBeVisible();
}
export async function createNote(_title, _body) {
async function createNote(_title, _body) {
let title = _title || 'Test note description that ';
let body = _body || 'Test note description that is very long and should not fit in text.';
@@ -73,13 +75,13 @@ export async function createNote(_title, _body) {
return { title, body };
}
export async function openSideMenu() {
async function openSideMenu() {
let menu = elementById(notesnook.ids.default.header.buttons.left);
await menu.tap();
await sleep(100);
}
export async function navigate(screen) {
async function navigate(screen) {
await sleep(500);
let menu = elementById(notesnook.ids.default.header.buttons.left);
await menu.tap();
@@ -91,7 +93,7 @@ const testvars = {
isFirstTest: true
};
export async function prepare() {
async function prepare() {
if (testvars.isFirstTest) {
console.log('Launching App Directly without reset');
testvars.isFirstTest = false;
@@ -104,12 +106,26 @@ export async function prepare() {
await LaunchApp();
}
const jestExpect = require('expect');
const { toMatchImageSnapshot } = require('jest-image-snapshot');
jestExpect.extend({ toMatchImageSnapshot });
export async function matchSnapshot(element, name) {
async function matchSnapshot(element, name) {
let path = await element.takeScreenshot(name);
const bitmapBuffer = fs.readFileSync(path);
jestExpect(bitmapBuffer).toMatchImageSnapshot();
}
module.exports = {
matchSnapshot,
prepare,
LaunchApp,
createNote,
navigate,
openSideMenu,
notVisibleById,
notVisibleByText,
visibleById,
visibleByText,
tapById,
tapByText,
elementByText,
elementById,
sleep
};

View File

@@ -41,6 +41,7 @@ const Intro = ({ navigation, route }) => {
return (
<View
testID="notesnook.splashscreen"
style={{
width: '100%',
height: '100%',

View File

@@ -14,15 +14,8 @@
"esModuleInterop": true,
"skipLibCheck": false,
"maxNodeModuleJsDepth": 6,
"downlevelIteration": true
"downlevelIteration": true,
"types": ["node", "jest", "detox"]
},
"exclude": [
"babel.config.js",
"metro.config.js",
"jest.config.js",
"android",
"ios",
"html",
"e2e"
]
"exclude": ["android", "ios"]
}