Skip to content

Enhancement/unit tests #290

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

Merged
merged 40 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4133788
✨ Add initial config for circleci
salmamali May 7, 2019
a946d52
change node version
salmamali May 7, 2019
eef5312
📝 ci
salmamali May 7, 2019
4899402
📝 ci
salmamali May 7, 2019
6f3e572
✨ add workflow and one passing test
salmamali May 7, 2019
c46629b
📝 fix working directory
salmamali May 7, 2019
0927be1
📝 ci
salmamali May 7, 2019
03c4ea8
✨ setup the module for tests
salmamali May 9, 2019
3f21747
✨ add Chats module unit tests
salmamali May 9, 2019
e49f87b
Merge branch 'enhancement/circleci' into enhancement/unit_tests
salmamali May 12, 2019
45bc992
✨ add mocks for BugReporting, XhrNetworkInterceptor, InstabugUtils, C…
salmamali May 12, 2019
d17d6ca
✨ add unit tests for bugReporting and replies
salmamali May 12, 2019
d960a37
🎨 clean up
salmamali May 12, 2019
c08a907
📝 change ci to run in the module directory instead of the sample app …
salmamali May 12, 2019
12ab51d
🐛 fix CI path
salmamali May 12, 2019
6c2b1ea
✨ Replies unit tests
salmamali May 12, 2019
7b80896
✨ surveys unit tests
salmamali May 12, 2019
aeb5207
Merge branch 'enhancement/unit_tests' of https://github.com/Instabug/…
alyezz May 13, 2019
0bab360
✨ add Instabug module unit tests
salmamali May 14, 2019
1847432
🐛 fix incorrect API name
salmamali May 14, 2019
e9cd827
📝 add missing unit tests
salmamali May 14, 2019
f6d9ff0
feature requests and report unit tests
salmamali May 14, 2019
378b44f
✨ add xhrNetworkInterceptor unit tests
salmamali May 19, 2019
63c3b1a
✨ add NetworkLogger unit tests
salmamali May 21, 2019
484f3e6
✨ add CrashReporting module unit tests
salmamali May 23, 2019
7c1c8b9
🐛 fix wrong import
salmamali May 23, 2019
5ac077d
🐛 fix failing test
salmamali May 23, 2019
d646a18
✨ job to run sample app tests
salmamali May 23, 2019
b2bd8fc
🐛 fix sample app working directory
salmamali May 23, 2019
0845e8e
✨ add global error handler tests in sample app
salmamali May 23, 2019
1a504e9
📝 CI
salmamali May 23, 2019
85f4d1c
📝CI
salmamali May 23, 2019
65fb6c8
📝 CI
salmamali May 23, 2019
a69de76
fix CI command
salmamali May 23, 2019
ed48fbf
📝 fix CI
salmamali May 27, 2019
2528dee
CI
salmamali May 27, 2019
3f5c924
CI
salmamali May 27, 2019
e2039aa
CI
salmamali May 27, 2019
38aa4a1
Passing CI 🤞🏼
salmamali May 27, 2019
9e63332
Merge commit 'a7ae9724de2e7d0c5b252bbec77e2cc7ba7205ae' into enhancem…
salmamali May 27, 2019
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
99 changes: 99 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,96 @@
version: 2
jobs:
test_module:
working_directory: ~/project
docker:
- image: circleci/node:8
steps:
- checkout:
path: ~/project

- restore_cache:
key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }}

- restore_cache:
key: node-v1-{{ checksum "package.json" }}-{{ arch }}

- run: yarn install

- save_cache:
key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }}
paths:
- ~/.cache/yarn

- save_cache:
key: node-v1-{{ checksum "package.json" }}-{{ arch }}
paths:
- node_modules

- run:
name: jest tests
command: |
mkdir -p test-results/jest
yarn run test
environment:
JEST_JUNIT_OUTPUT: test-results/jest/junit.xml

- persist_to_workspace:
root: ~/project
paths:
- node_modules

- store_test_results:
path: test-results

- store_artifacts:
path: test-results

test_sample:
working_directory: ~/project
docker:
- image: circleci/node:8
steps:
- checkout:
path: ~/project

- restore_cache:
key: yarn-v1-{{ checksum "InstabugSample/yarn.lock" }}-{{ arch }}

- restore_cache:
key: node-v1-{{ checksum "InstabugSample/package.json" }}-{{ arch }}

- run: cd InstabugSample && yarn install

- save_cache:
key: yarn-v1-{{ checksum "InstabugSample/yarn.lock" }}-{{ arch }}
paths:
- ~/.cache/yarn

- save_cache:
key: node-v1-{{ checksum "InstabugSample/package.json" }}-{{ arch }}
paths:
- InstabugSample/node_modules

- run:
name: jest tests
command: |
cd InstabugSample
mkdir -p test-results/jest
yarn test
environment:
JEST_JUNIT_OUTPUT: test-results/jest/junit.xml

- persist_to_workspace:
root: ~/project
paths:
- InstabugSample/node_modules

- store_test_results:
path: InstabugSample/test-results

- store_artifacts:
path: InstabugSample/test-results

publish:
macos:
xcode: "10.1.0"
Expand All @@ -10,11 +101,18 @@ jobs:
- run: cd Escape/.build/release; cp -f Escape /usr/local/bin/escape
- run: Escape react-native publish



workflows:
version: 2
publish:
jobs:
- test_module
- test_sample
- hold:
requires:
- test_module
- test_sample
type: approval
filters:
branches:
Expand All @@ -25,3 +123,4 @@ workflows:
filters:
branches:
only: master

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DerivedData/
xcuserdata/


coverage/
*node_modules/
*Pods/
*Podfile.lock
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ android/local.properties
ios/.DS_Store

build/
InstabugSample
InstabugSample/
node_modules/
coverage/
15 changes: 0 additions & 15 deletions InstabugSample/__tests__/App.js

This file was deleted.

80 changes: 80 additions & 0 deletions InstabugSample/__tests__/instabugUtils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* @format
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/

import 'react-native';
import { NativeModules, Platform } from 'react-native';
import '../../jest/mockInstabug';
import Instabug from 'instabug-reactnative';
import IBGEventEmitter from 'instabug-reactnative/utils/IBGEventEmitter';
import IBGConstants from 'instabug-reactnative/utils/InstabugConstants';
// import console = require('console');

jest.mock('../node_modules/instabug-reactnative/utils/XhrNetworkInterceptor', () => {
return {
enableInterception: jest.fn(),
setOnDoneCallback: jest.fn()
}
})

describe('Test global error handler', () => {

const sendJSCrash = jest.spyOn(NativeModules.Instabug, 'sendJSCrash');

beforeEach(() => {
// var InstabugUtils = require('../utils/InstabugUtils');
});

it('should call sendJSCrash when platform is ios', () => {

Platform.OS = 'ios';
const handler = global.ErrorUtils.getGlobalHandler();
handler({ name: 'TypeError', message: 'This is a type error.' }, false);
const expected = {
message: 'TypeError - This is a type error.',
os: 'ios',
platform: 'react_native',
exception: []
}
expect(sendJSCrash).toHaveBeenCalledWith(expected);

});

it('should call sendJSCrash when platform is android', () => {

Platform.OS = 'android';
const handler = global.ErrorUtils.getGlobalHandler();
handler({ name: 'TypeError', message: 'This is a type error.' }, false);
const expected = {
message: 'TypeError - This is a type error.',
os: 'android',
platform: 'react_native',
exception: []
}
expect(sendJSCrash).toHaveBeenCalledWith(JSON.stringify(expected));

});

it('should emit event IBGSendUnhandledJSCrash when platform is android and onReportSubmitHandler is set', (done) => {

Platform.OS = 'android';
Instabug._isOnReportHandlerSet = jest.fn(() => true);
const handler = global.ErrorUtils.getGlobalHandler();
IBGEventEmitter.addListener(IBGConstants.SEND_UNHANDLED_CRASH, (actual) => {
const expected = {
message: 'TypeError - This is a type error.',
os: 'android',
platform: 'react_native',
exception: []
};
expect(actual).toEqual(expected);
done();
});
handler({ name: 'TypeError', message: 'This is a type error.' }, false);


});


});
5 changes: 4 additions & 1 deletion InstabugSample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!react-native|react-navigation)/"
]
}
}
Loading