Merge pull request #67 from greena13/dev_tests
[tests] Move test suite into same repo
|
@ -60,3 +60,4 @@ docs
|
|||
.idea
|
||||
coverage
|
||||
yarn.lock
|
||||
tests
|
||||
|
|
|
@ -32,7 +32,7 @@ The native SDKs also allow us to hook into device sdk's which are not possible w
|
|||
|
||||
### Test app
|
||||
|
||||
To help ensure changes and features work across both iOS & Android, we've developed an app specifically to test `react-native-firebase` against the [`firebase` web SDK](https://www.npmjs.com/package/firebase). Please see the [`react-native-firebase-tests`](https://github.com/invertase/react-native-firebase-tests) repository for more information.
|
||||
To help ensure changes and features work across both iOS & Android, we've developed an app specifically to test `react-native-firebase` against the [`firebase` web SDK](https://www.npmjs.com/package/firebase). Please see the [`tests`](tests/README.md) directory for more information.
|
||||
|
||||
<hr>
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"presets": [
|
||||
"react-native"
|
||||
],
|
||||
"ignore": [
|
||||
"node_modules/diff/lib/**/*.js",
|
||||
"node_modules/diff/node_modules/**/*.js"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
[android]
|
||||
target = Google Inc.:Google APIs:23
|
||||
|
||||
[maven_repositories]
|
||||
central = https://repo1.maven.org/maven2
|
|
@ -0,0 +1,10 @@
|
|||
# editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"extends": "airbnb",
|
||||
"parser": "babel-eslint",
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"plugins": [
|
||||
"flowtype"
|
||||
],
|
||||
"env": {
|
||||
"es6": true,
|
||||
"jasmine": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"experimentalObjectRestSpread": true
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"class-methods-use-this": 0,
|
||||
"no-underscore-dangle": 0,
|
||||
"no-use-before-define": 0,
|
||||
"arrow-body-style": 0,
|
||||
"import/prefer-default-export": 0,
|
||||
"radix": 0,
|
||||
"new-cap": 0,
|
||||
"max-len": 0,
|
||||
"no-continue": 0,
|
||||
"no-console": 0,
|
||||
"global-require": 0,
|
||||
"import/extensions": 0,
|
||||
"import/no-unresolved": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"react/jsx-filename-extension": 0
|
||||
},
|
||||
"globals": {
|
||||
"__DEV__": true,
|
||||
"window": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
[ignore]
|
||||
; We fork some components by platform
|
||||
.*/*[.]android.js
|
||||
|
||||
; Ignore "BUCK" generated dirs
|
||||
<PROJECT_ROOT>/\.buckd/
|
||||
|
||||
; Ignore unexpected extra "@providesModule"
|
||||
.*/node_modules/.*/node_modules/fbjs/.*
|
||||
|
||||
; Ignore duplicate module providers
|
||||
; For RN Apps installed via npm, "Libraries" folder is inside
|
||||
; "node_modules/react-native" but in the source repo it is in the root
|
||||
.*/Libraries/react-native/React.js
|
||||
.*/Libraries/react-native/ReactNative.js
|
||||
|
||||
[include]
|
||||
|
||||
[libs]
|
||||
node_modules/react-native/Libraries/react-native/react-native-interface.js
|
||||
node_modules/react-native/flow
|
||||
flow/
|
||||
|
||||
[options]
|
||||
emoji=true
|
||||
|
||||
module.system=haste
|
||||
|
||||
experimental.strict_type_args=true
|
||||
|
||||
munge_underscores=true
|
||||
|
||||
module.name_mapper='^~\/\(.*\)$' -> '<PROJECT_ROOT>/\1'
|
||||
|
||||
|
||||
suppress_type=$FlowIssue
|
||||
suppress_type=$FlowFixMe
|
||||
suppress_type=$FixMe
|
||||
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-8]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-8]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
|
||||
|
||||
unsafe.enable_getters_and_setters=true
|
||||
|
||||
[version]
|
||||
^0.38.0
|
|
@ -0,0 +1 @@
|
|||
*.pbxproj -text
|
|
@ -0,0 +1,61 @@
|
|||
# OSX
|
||||
#
|
||||
.DS_Store
|
||||
|
||||
# Xcode
|
||||
#
|
||||
build/
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata
|
||||
*.xccheckout
|
||||
*.moved-aside
|
||||
DerivedData
|
||||
*.hmap
|
||||
*.ipa
|
||||
*.xcuserstate
|
||||
project.xcworkspace
|
||||
|
||||
# Android/IntelliJ
|
||||
#
|
||||
|
||||
android/gradle
|
||||
.idea
|
||||
.gradle
|
||||
local.properties
|
||||
*.iml
|
||||
|
||||
# node.js
|
||||
#
|
||||
node_modules/
|
||||
ios/Pods
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
yarn.lock
|
||||
npm-debug*
|
||||
|
||||
# BUCK
|
||||
buck-out/
|
||||
\.buckd/
|
||||
*.keystore
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
|
||||
# screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
ios/Podfile
|
||||
ios/Podfile.lock
|
||||
ios/Pods/
|
||||
ios/ReactNativeFirebaseDemo.xcworkspace/
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -0,0 +1,363 @@
|
|||
# react-native-firebase test suite
|
||||
|
||||
An **iOS** and **Android** React Native app built to test [`react-native-firebase`](https://github.com/invertase/react-native-firebase).
|
||||
|
||||
## Install
|
||||
|
||||
1. Clone the test application
|
||||
|
||||
```bash
|
||||
git clone https://github.com/invertase/react-native-firebase.git
|
||||
```
|
||||
|
||||
2. Install the dependencies listed in `package.json`
|
||||
|
||||
```bash
|
||||
cd react-native-firebase/tests/ && npm install
|
||||
```
|
||||
|
||||
### iOS Installation
|
||||
|
||||
3. Install the test application's CocoaPods.
|
||||
* See [troubleshooting](#installing-podfiles) if this doesn't work for you.
|
||||
|
||||
```bash
|
||||
npm run ios:pod:install
|
||||
```
|
||||
|
||||
4. Start the React Native packager
|
||||
|
||||
```bash
|
||||
npm run start
|
||||
```
|
||||
|
||||
5. In another terminal window, install the app on your emulator:
|
||||
|
||||
```bash
|
||||
npm run ios:dev
|
||||
```
|
||||
|
||||
### Android Installation
|
||||
|
||||
6. Start your emulator through Android Studio: Tools > Android > AVD Manager
|
||||
|
||||
> You will need a version of the Android emulator that has the Play Store installed (you should be able to find it on the emulator's home screen or on the list of apps).
|
||||
|
||||
7. Start the React Native packager if you haven't already in the iOS instructions.
|
||||
|
||||
```bash
|
||||
npm run start
|
||||
```
|
||||
|
||||
8. Run the test app on your Android emulator:
|
||||
|
||||
```bash
|
||||
npm run android:dev
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
`react-native-firebase` aims to match the Firebase Web API wherever possible. As a result, the tests are largely derived from the [Firebase Web API documentation](https://firebase.google.com/docs/reference/js/).
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
Tests are bootstrapped and ran when the app is booted. The status of each test suite and individual test will update as and when a test has completed or errored.
|
||||
|
||||
### Running tests
|
||||
|
||||
Tests can be run by pressing the play button in the toolbar of the app. Test can be run individually, by suite, or all at once.
|
||||
|
||||
![Test suite Android](/docs/assets/test-suite-screenshot-android.png?raw=true)
|
||||
|
||||
|
||||
### Adding test
|
||||
|
||||
To add tests to an existing test suite, you need to pass a function to `addTests`.
|
||||
|
||||
#### Synchronous tests
|
||||
|
||||
Synchronous tests are created by passing a function to `it`. The next test is run immediately after the last line is executed.
|
||||
|
||||
```javascript
|
||||
testSuite.addTests(({ describe, it }) => {
|
||||
describe('synchronous test', () => {
|
||||
|
||||
it('does something correctly', () => {
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Asynchronous tests
|
||||
|
||||
Tests can be asynchronous if they return a promise. The test suite waits for the promise to resolve before executing the next test.
|
||||
|
||||
```javascript
|
||||
testSuite.addTests(({ describe, it }) => {
|
||||
describe('async successful test', () => {
|
||||
|
||||
it('does something correctly', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// ...
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Asynchronous tests can also be created using the `async` function syntax:
|
||||
|
||||
```javascript
|
||||
testSuite.addTests(({ describe, it }) => {
|
||||
describe('async successful test', () => {
|
||||
|
||||
it('does something correctly', async () => {
|
||||
// ...
|
||||
|
||||
await somethingAsynchronous();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
> When rejecting, always ensure a valid [JavaScript Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) is provided.
|
||||
|
||||
### Creating a new test suite
|
||||
|
||||
A test suite groups together test categories under the same Firebase feature. e.g. *Realtime Database* tests.
|
||||
|
||||
To add a new test suite:
|
||||
|
||||
1. Create a new directory within `src/tests`.
|
||||
2. Create an `index.js` file.
|
||||
|
||||
In this file, you need to create an instance of `TestSuite` - see [TestSuite constructor](#testsuite-constructor).
|
||||
|
||||
```javascript
|
||||
import TestSuite from 'lib/TestSuite';
|
||||
|
||||
const MyNewSuite = new TestSuite('Realtime Database Storage', 'Upload/Download storage tests');
|
||||
|
||||
export default MyNewSuite;
|
||||
```
|
||||
|
||||
3. `addTests` is then used as many times as is necessary to add tests to the test suite, accepting a function that defines one or more tests.
|
||||
4. The test suite must then be imported into `src/tests/index.js` and added to `testSuiteInstances` in order for it to be included in the list of test suites available to run in the app.
|
||||
|
||||
## TestSuite API
|
||||
|
||||
### TestSuite Constructor
|
||||
|
||||
The TestSuite constructor accepts 3 arguments:
|
||||
|
||||
- **name**: String containing the name of the test suite. e.g. 'Realtime Storage'
|
||||
- **description**: String containing description of the test suite
|
||||
- **firebase**: This is the object exported from `src/firebase` and contains both the native and web firebase instances.
|
||||
|
||||
```javascript
|
||||
import firebase from '../firebase';
|
||||
|
||||
new TestSuite('Realtime Database Storage', 'firebase.database()', firebase);
|
||||
```
|
||||
|
||||
### Test Definition
|
||||
|
||||
#### describe()
|
||||
|
||||
The `describe()` function takes 2 - 3 arguments:
|
||||
|
||||
- **description**: String describing the context or target of all the tests defined in `testDefinitions`
|
||||
- **options**: (Optional) object of options:
|
||||
* **focus**: Boolean marking all the tests defined in `testDefinitions` (and any others marked as focused) as the only one(s) that should run
|
||||
* **pending**: Boolean marking all the tests defined in `testDefinitions` as excluded from running in the test suite
|
||||
- **testDefinitions**: Function that defines 1 or more tests by calling `it`, `xit` or `fit`
|
||||
|
||||
```javascript
|
||||
function testCategory({ describe }) {
|
||||
|
||||
describe('a feature', () => {
|
||||
it('does something synchronously', () => {
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export default testCategory;
|
||||
```
|
||||
|
||||
`describe()` statements can be arbitrarily nested.
|
||||
|
||||
#### context()
|
||||
|
||||
`context()` is an alias for `describe()` provided as syntactical sugar. `xcontext()` and `fcontext()` work similar to `xdescribe()` and `fdescribe()`, respectively.
|
||||
|
||||
#### it()
|
||||
|
||||
The `it()` function takes 2 - 3 arguments:
|
||||
|
||||
- **description**: String describing the test defined in `testDefinition`
|
||||
- **options**: (Optional) object of options:
|
||||
* **focus**: Boolean marking the test defined in `testDefinition` (and any others marked as focused) as the only one(s) that should run
|
||||
* **pending**: Boolean marking the test defined in `testDefinition` as excluded from running in the test suite
|
||||
* **timeout**: Time in milliseconds a test is allowed to execute before it's considered to have timed out. Default is 5000ms (5 seconds).
|
||||
- **testDefinition**: Function that defines a test with one or more assertions. Can be a synchronous or asynchronous function. Functions that return a promise cause the test environment to wait for the promise to be resolved before proceding to the next test.
|
||||
|
||||
```javascript
|
||||
it('does something synchronously', () => {
|
||||
|
||||
});
|
||||
|
||||
it('does something asynchronously', async () => {
|
||||
|
||||
});
|
||||
|
||||
it('does something else asynchronously', () => {
|
||||
return new Promise(/* ... */);
|
||||
});
|
||||
```
|
||||
|
||||
`it()` statements can *not* be nested.
|
||||
|
||||
#### xdescribe() & xit()
|
||||
|
||||
##### Pending Tests
|
||||
|
||||
You can mark all tests within a `describe` statement as pending by using the `xdescribe` function instead. The test will appear greyed out and will not be run as part of the test suite.
|
||||
|
||||
You can mark a single test as pending by using `xit` as you would `it`.
|
||||
|
||||
Tests should only be marked as pending temporarily, and should not normally be committed to the test suite unless they are fully implemented.
|
||||
|
||||
#### fdescribe() & fit()
|
||||
|
||||
##### Focused Tests
|
||||
|
||||
You can mark all tests within a `describe` statement as focused by using the `fdescribe` function instead. Tests that are focused will be the only ones that appear and run in the test suite until all tests are removed from being focused. This is useful for running and working on a few tests at a time.
|
||||
|
||||
You can mark a single test as focused by using `fit` as you would `it`.
|
||||
|
||||
#### Test Assertions
|
||||
|
||||
The assertion library Should.js is used in the tests. The complete list of available assertions is available in the [Should.js documentation](https://shouldjs.github.io).
|
||||
|
||||
#### Lifecycle methods
|
||||
|
||||
Four lifecycle methods are provided for each test context:
|
||||
|
||||
- **before** - Run once, before the current test context executes
|
||||
- **beforeEach** - Run before every test in the current test context
|
||||
- **after** - Run once, after the current test context has finished executing
|
||||
- **afterEach** - Run after every test in the current test context
|
||||
|
||||
A new test context is created when the test suite encounters any of `describe`, `xdescribe`, `fdescribe`, `context`, `xcontext` or `fcontext`, and close again when it reaches the end of the block. Test contexts can be nested and lifecycle hooks set for parent contexts apply for all descendents.
|
||||
|
||||
Each lifecycle hook accepts either a synchronous function, a function that returns a promise or an `async` function.
|
||||
|
||||
```javascript
|
||||
function testCategory({ before, beforeEach, afterEach, after }) {
|
||||
|
||||
before(() => console.log('Before all tests start.'));
|
||||
beforeEach(() => console.log('Before every test starts.'));
|
||||
|
||||
describe('sync successful test', function() {
|
||||
// ...
|
||||
});
|
||||
|
||||
afterEach(() => console.log('After each test starts.'));
|
||||
after(() => console.log('After all tests are complete, with success or error.'));
|
||||
}
|
||||
```
|
||||
|
||||
An optional hash of options can also be passed as the first argument, defining one or more of the following values:
|
||||
|
||||
* **timeout**: Time in milliseconds a hook is allowed to execute before it's considered to have timed out. Default is 5000ms (5 seconds).
|
||||
|
||||
#### Accessing Firebase
|
||||
|
||||
`react-native-firebase` is available `firebase.native`:
|
||||
|
||||
```javascript
|
||||
function testCategory({ describe, firebase }) {
|
||||
|
||||
describe('sync successful test', 'category', function() {
|
||||
firebase.native.database();
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
If you need to access the web API for Firebase to compare with the functionality of `react-native-firebase`, you can access it on `firebase.web`.
|
||||
|
||||
> All tests should be written in terms of `react-native-firebase`'s behaviour and should **not** include direct comparisons with the web API. It's available for reference, only.
|
||||
|
||||
## Development
|
||||
|
||||
### Running test suite against latest version of react-native-firebase
|
||||
|
||||
You can use the node module `wml` to automatically copy changes you make to `react-native-firebase` over to the test application so you can run the test suite against them.
|
||||
|
||||
1. Install `wml` globally:
|
||||
|
||||
```bash
|
||||
npm install wml -g
|
||||
```
|
||||
|
||||
2. Configure `wml` to copy changes from `react-native-firebase` to `react-native-firebase/tests/node_modules/react-native-firebase` is:
|
||||
|
||||
```bash
|
||||
wml add /full/path/to/react-native-firebase /full/path/to/react-native-firebase/tests/node_modules/react-native-firebase
|
||||
```
|
||||
|
||||
3. Start `wml`:
|
||||
|
||||
```bash
|
||||
wml start
|
||||
```
|
||||
|
||||
> JavaScript changes require restarting the React Native packager to take effect
|
||||
|
||||
> Java changes will need to be rebuilt in Android Studio
|
||||
|
||||
> Objective-C changes need to be rebuilt in Xcode
|
||||
|
||||
4. Stop `wml` when you are finished:
|
||||
```bash
|
||||
wml stop
|
||||
```
|
||||
|
||||
### Debugging or viewing internals of the test suite
|
||||
|
||||
`react-native-firebase/tests` is compatible with [react-native-debugger](https://github.com/jhen0409/react-native-debugger) and is the recommended way to view the internal state of the test suite for development or troubleshooting.
|
||||
|
||||
It allows you to view state and prop values of the React component tree, view the actions and contents of the Redux store and view and interact with the debugging console.
|
||||
|
||||
Make sure **Remote JS Debugging** when running the application and close any chrome debugging windows that appear and start React Native Debugger.
|
||||
|
||||
### Running the internal tests
|
||||
|
||||
`react-native-firebase-tests` has its own tests to verify the testing framework is working as expected. These are run from the command line:
|
||||
|
||||
```bash
|
||||
npm run internal-tests
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Invalid React.podspec file: no implicit conversion of nil into String
|
||||
|
||||
This error occurs if you are using ruby version 2.1.2. Upgrade your version of ruby and try again.
|
||||
|
||||
|
||||
### Unable to resolve module ../../../node_modules/react-native/packager/...
|
||||
|
||||
Run the packager separately, clearing the cache:
|
||||
|
||||
```bash
|
||||
npm start -- --reset-cache
|
||||
```
|
|
@ -0,0 +1,287 @@
|
|||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function asynchronousHooksTests({ it: _it, describe: _describe }) {
|
||||
_describe('before hooks:', () => {
|
||||
_it('can return a promise that is resolved before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
let valueByTest = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
let resolved = false;
|
||||
|
||||
before(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
before(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueByTest = resolved;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
valueByTest.should.equal(true);
|
||||
});
|
||||
|
||||
_it('can be an asynchronous function that is awaited before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
let valueByTest = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
let resolved = false;
|
||||
|
||||
before(async () => {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
before(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueByTest = resolved;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
valueByTest.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
_describe('beforeEach hooks:', () => {
|
||||
_it('can return a promise that is resolved before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
let valueByTest = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
let resolved = false;
|
||||
|
||||
beforeEach(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueByTest = resolved;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
valueByTest.should.equal(true);
|
||||
});
|
||||
|
||||
_it('can be an asynchronous function that is awaited before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
let valueByTest = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
let resolved = false;
|
||||
|
||||
beforeEach(async () => {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueByTest = resolved;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
valueByTest.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
_describe('afterEach hooks:', () => {
|
||||
_it('can return a promise that is resolved before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
let resolved = false;
|
||||
|
||||
afterEach(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
});
|
||||
|
||||
_it('can be an asynchronous function that is awaited before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
let resolved = false;
|
||||
|
||||
afterEach(async () => {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
_describe('after hooks:', () => {
|
||||
_it('can return a promise that is resolved before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
let resolved = false;
|
||||
|
||||
after(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
});
|
||||
|
||||
_it('can be an asynchronous function that is awaited before executing other hooks and tests', async () => {
|
||||
let valueBySecondHook = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
let resolved = false;
|
||||
|
||||
after(async () => {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
valueBySecondHook = resolved;
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondHook.should.equal(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default asynchronousHooksTests;
|
|
@ -0,0 +1,661 @@
|
|||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function failingHookTests({ it: _it, describe: _describe }) {
|
||||
_describe('before hooks:', () => {
|
||||
_it('capture promise rejections and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
before(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject('failure');
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" before Hook: failure');
|
||||
});
|
||||
|
||||
_it('capture errors thrown in promises and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
before(() => {
|
||||
return new Promise(() => {
|
||||
true.should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" before Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in asynchronous functions and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
before(async () => {
|
||||
await new Promise(() => {
|
||||
true.should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" before Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in synchronous functions and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
before(() => {
|
||||
true.should.equal(false);
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" before Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('beforeEach hooks:', () => {
|
||||
_it('capture promise rejections and marks test that follows as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
beforeEach(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (testRuns > 0) {
|
||||
reject('failure');
|
||||
} else {
|
||||
testRuns += 1;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" beforeEach Hook: failure');
|
||||
});
|
||||
|
||||
_it('capture errors thrown in promises and marks test that follows as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
beforeEach(() => {
|
||||
return new Promise((resolve) => {
|
||||
if (testRuns > 0) {
|
||||
true.should.equal(false);
|
||||
} else {
|
||||
testRuns += 1;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" beforeEach Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in asynchronous functions and marks test that follows as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
beforeEach(async () => {
|
||||
await new Promise((resolve) => {
|
||||
if (testRuns > 0) {
|
||||
true.should.equal(false);
|
||||
} else {
|
||||
testRuns += 1;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" beforeEach Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in synchronous functions and marks test that follows as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
beforeEach(() => {
|
||||
if (testRuns > 0) {
|
||||
true.should.equal(false);
|
||||
} else {
|
||||
testRuns += 1;
|
||||
}
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" beforeEach Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('afterEach hooks:', () => {
|
||||
_it('capture promise rejections and marks test that proceeded as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
afterEach(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (testRuns > 0) {
|
||||
reject('failure');
|
||||
} else {
|
||||
testRuns += 1;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" afterEach Hook: failure');
|
||||
});
|
||||
|
||||
_it('capture errors thrown in promises and marks test that proceeded as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
afterEach(() => {
|
||||
return new Promise((resolve) => {
|
||||
if (testRuns > 0) {
|
||||
true.should.equal(false);
|
||||
} else {
|
||||
testRuns += 1;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" afterEach Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in asynchronous functions and marks test that proceeded as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
afterEach(async () => {
|
||||
await new Promise((resolve) => {
|
||||
if (testRuns > 0) {
|
||||
true.should.equal(false);
|
||||
} else {
|
||||
testRuns += 1;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" afterEach Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in synchronous functions and marks test that proceeded as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
let testRuns = 0;
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
afterEach(() => {
|
||||
if (testRuns > 0) {
|
||||
true.should.equal(false);
|
||||
} else {
|
||||
testRuns += 1;
|
||||
}
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" afterEach Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('after hooks:', () => {
|
||||
_it('capture promise rejections and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
after(() => {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject('failure');
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" after Hook: failure');
|
||||
});
|
||||
|
||||
_it('capture errors thrown in promises and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
after(() => {
|
||||
return new Promise(() => {
|
||||
true.should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" after Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in asynchronous functions and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
after(async () => {
|
||||
await new Promise(() => {
|
||||
true.should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" after Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
|
||||
_it('captures errors thrown in synchronous functions and marks all tests as failed', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
after(() => {
|
||||
true.should.equal(false);
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('2 tests has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" after Hook: AssertionError: expected true to be false');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default failingHookTests;
|
|
@ -0,0 +1,278 @@
|
|||
import sinon from 'sinon';
|
||||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function hookScopeTests({ it: _it, describe: _describe }) {
|
||||
_describe('before hooks:', () => {
|
||||
_it('apply only to the scope they are defined in and any child scopes', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
let value = 0;
|
||||
let valueWhenOtherTestRuns = null;
|
||||
let valueWhenSiblingTestRuns = null;
|
||||
let valueWhenChildTestRuns = null;
|
||||
|
||||
testSuite.addTests(({ it, before, context }) => {
|
||||
context('', () => {
|
||||
before(() => {
|
||||
value = 1;
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueWhenSiblingTestRuns = value;
|
||||
});
|
||||
|
||||
context('', () => {
|
||||
it('', () => {
|
||||
valueWhenChildTestRuns = value;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueWhenOtherTestRuns = value;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueWhenOtherTestRuns.should.equal(0);
|
||||
valueWhenSiblingTestRuns.should.equal(1);
|
||||
valueWhenChildTestRuns.should.equal(1);
|
||||
});
|
||||
|
||||
_it('only run once for the scope they apply', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const beforeHook = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, before, context }) => {
|
||||
context('', () => {
|
||||
before(beforeHook);
|
||||
|
||||
it('', () => { });
|
||||
|
||||
context('', () => {
|
||||
it('', () => { });
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeHook.should.be.calledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
_describe('beforeEach hooks:', () => {
|
||||
_it('apply only to the scope they are defined in and any child scopes', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
let value = 0;
|
||||
let valueWhenOtherTestRuns = null;
|
||||
let valueWhenSiblingTestRuns = null;
|
||||
let valueWhenChildTestRuns = null;
|
||||
|
||||
testSuite.addTests(({ it, beforeEach, context }) => {
|
||||
context('', () => {
|
||||
beforeEach(() => {
|
||||
value = 1;
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueWhenSiblingTestRuns = value;
|
||||
});
|
||||
|
||||
context('', () => {
|
||||
it('', () => {
|
||||
valueWhenChildTestRuns = value;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueWhenOtherTestRuns = value;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueWhenOtherTestRuns.should.equal(0);
|
||||
valueWhenSiblingTestRuns.should.equal(1);
|
||||
valueWhenChildTestRuns.should.equal(1);
|
||||
});
|
||||
|
||||
_it('are called once for every test in its scope', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const beforeEachHook = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, beforeEach, context }) => {
|
||||
context('', () => {
|
||||
beforeEach(beforeEachHook);
|
||||
|
||||
it('', () => { });
|
||||
|
||||
context('', () => {
|
||||
it('', () => { });
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeEachHook.should.be.calledTwice();
|
||||
});
|
||||
});
|
||||
|
||||
_describe('afterEach hooks:', () => {
|
||||
_it('apply only to the scope they are defined in and any child scopes', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
let value = 0;
|
||||
|
||||
testSuite.addTests(({ it, afterEach, context }) => {
|
||||
context('', () => {
|
||||
it('', () => {
|
||||
value += 1;
|
||||
});
|
||||
|
||||
context('', () => {
|
||||
it('', () => {
|
||||
value += 1;
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
value -= 1;
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
value += 1;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
value.should.equal(1);
|
||||
});
|
||||
|
||||
_it('are called once for every test in its scope', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const afterEachHook = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, afterEach, context }) => {
|
||||
context('', () => {
|
||||
afterEach(afterEachHook);
|
||||
|
||||
it('', () => { });
|
||||
|
||||
context('', () => {
|
||||
it('', () => { });
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
afterEachHook.should.be.calledTwice();
|
||||
});
|
||||
});
|
||||
|
||||
_describe('after hooks:', () => {
|
||||
_it('apply only to the scope they are defined in and any child scopes', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
let value = 0;
|
||||
|
||||
testSuite.addTests(({ it, after, context }) => {
|
||||
context('', () => {
|
||||
it('', () => {
|
||||
value += 1;
|
||||
});
|
||||
|
||||
context('', () => {
|
||||
it('', () => {
|
||||
value += 1;
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
value -= 1;
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
value += 1;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
value.should.equal(2);
|
||||
});
|
||||
|
||||
_it('are called once for every test in its scope', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const afterHook = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, after, context }) => {
|
||||
context('', () => {
|
||||
it('', () => { });
|
||||
|
||||
context('', () => {
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
after(afterHook);
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
afterHook.should.be.calledOnce();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default hookScopeTests;
|
|
@ -0,0 +1,310 @@
|
|||
import sinon from 'sinon';
|
||||
import 'should-sinon';
|
||||
import assert from 'assert';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function hooksCallOrderTests({ it: _it, describe: _describe }) {
|
||||
_describe('before hooks:', () => {
|
||||
_it('calls before hooks defined in the same context in the order they are defined', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const beforeCallbackA = sinon.spy();
|
||||
const beforeCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
before(beforeCallbackA);
|
||||
before(beforeCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeCallbackA.should.have.been.called();
|
||||
beforeCallbackB.should.have.been.called();
|
||||
|
||||
assert(beforeCallbackB.calledAfter(beforeCallbackA));
|
||||
});
|
||||
|
||||
_it('calls before hooks defined in child contexts after those in parent contexts', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const beforeCallbackA = sinon.spy();
|
||||
const beforeCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, before, context }) => {
|
||||
before(beforeCallbackA);
|
||||
|
||||
context('', () => {
|
||||
before(beforeCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeCallbackA.should.have.been.called();
|
||||
beforeCallbackB.should.have.been.called();
|
||||
|
||||
assert(beforeCallbackB.calledAfter(beforeCallbackA));
|
||||
});
|
||||
});
|
||||
|
||||
_describe('beforeEach hooks:', () => {
|
||||
_it('calls beforeEach hooks defined in the same context in the order they are defined', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const beforeEachCallbackA = sinon.spy();
|
||||
const beforeEachCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
beforeEach(beforeEachCallbackA);
|
||||
beforeEach(beforeEachCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeEachCallbackA.should.have.been.called();
|
||||
beforeEachCallbackB.should.have.been.called();
|
||||
|
||||
assert(beforeEachCallbackB.calledAfter(beforeEachCallbackA));
|
||||
});
|
||||
|
||||
_it('calls beforeEach hooks defined in child contexts after those in parent contexts', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const beforeEachCallbackA = sinon.spy();
|
||||
const beforeEachCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, beforeEach, context }) => {
|
||||
beforeEach(beforeEachCallbackA);
|
||||
|
||||
context('', () => {
|
||||
beforeEach(beforeEachCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeEachCallbackA.should.have.been.called();
|
||||
beforeEachCallbackB.should.have.been.called();
|
||||
|
||||
assert(beforeEachCallbackB.calledAfter(beforeEachCallbackA));
|
||||
});
|
||||
|
||||
_it('calls beforeEach hooks after before hooks', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const beforeCallbackA = sinon.spy();
|
||||
const beforeEachCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, before, beforeEach }) => {
|
||||
before(beforeCallbackA);
|
||||
beforeEach(beforeEachCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeCallbackA.should.have.been.called();
|
||||
beforeEachCallbackB.should.have.been.called();
|
||||
|
||||
assert(beforeEachCallbackB.calledAfter(beforeCallbackA));
|
||||
});
|
||||
});
|
||||
|
||||
_describe('after hooks:', () => {
|
||||
_it('calls after hooks defined in the same context in the order they are defined', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const afterCallbackA = sinon.spy();
|
||||
const afterCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
after(afterCallbackA);
|
||||
after(afterCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
afterCallbackA.should.have.been.called();
|
||||
afterCallbackB.should.have.been.called();
|
||||
|
||||
assert(afterCallbackB.calledAfter(afterCallbackA));
|
||||
});
|
||||
|
||||
_it('calls after hooks defined in child contexts before those in parent contexts', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const afterCallbackA = sinon.spy();
|
||||
const afterCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, after, context }) => {
|
||||
after(afterCallbackA);
|
||||
|
||||
context('', () => {
|
||||
after(afterCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
afterCallbackA.should.have.been.called();
|
||||
afterCallbackB.should.have.been.called();
|
||||
|
||||
assert(afterCallbackA.calledAfter(afterCallbackB));
|
||||
});
|
||||
});
|
||||
|
||||
_describe('afterEach hooks:', () => {
|
||||
_it('calls afterEach hooks defined in the same context in the order they are defined', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const afterEachCallbackA = sinon.spy();
|
||||
const afterEachCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
afterEach(afterEachCallbackA);
|
||||
afterEach(afterEachCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
afterEachCallbackA.should.have.been.called();
|
||||
afterEachCallbackB.should.have.been.called();
|
||||
|
||||
assert(afterEachCallbackB.calledAfter(afterEachCallbackA));
|
||||
});
|
||||
|
||||
_it('calls afterEach hooks defined in child contexts before those in parent contexts', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const afterEachCallbackA = sinon.spy();
|
||||
const afterEachCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, afterEach, context }) => {
|
||||
afterEach(afterEachCallbackA);
|
||||
|
||||
context('', () => {
|
||||
afterEach(afterEachCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
afterEachCallbackA.should.have.been.called();
|
||||
afterEachCallbackB.should.have.been.called();
|
||||
|
||||
assert(afterEachCallbackA.calledAfter(afterEachCallbackB));
|
||||
});
|
||||
|
||||
_it('calls afterEach hooks before after hooks', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const afterCallbackA = sinon.spy();
|
||||
const afterEachCallbackB = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ it, after, afterEach }) => {
|
||||
after(afterCallbackA);
|
||||
afterEach(afterEachCallbackB);
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
afterCallbackA.should.have.been.called();
|
||||
afterEachCallbackB.should.have.been.called();
|
||||
|
||||
assert(afterCallbackA.calledAfter(afterEachCallbackB));
|
||||
});
|
||||
});
|
||||
|
||||
_describe('when there are no tests in a context or any of its children', () => {
|
||||
_it('then doesn\'t call any hooks', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
const beforeCallback = sinon.spy();
|
||||
const beforeEachCallback = sinon.spy();
|
||||
const afterCallback = sinon.spy();
|
||||
const afterEachCallback = sinon.spy();
|
||||
|
||||
testSuite.addTests(({ before, beforeEach, after, afterEach, context }) => {
|
||||
context('', () => {
|
||||
before(beforeCallback);
|
||||
beforeEach(beforeEachCallback);
|
||||
afterEach(afterEachCallback);
|
||||
after(afterCallback);
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
beforeCallback.should.not.have.been.called();
|
||||
beforeEachCallback.should.not.have.been.called();
|
||||
afterEachCallback.should.not.have.been.called();
|
||||
afterCallback.should.not.have.been.called();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default hooksCallOrderTests;
|
|
@ -0,0 +1,17 @@
|
|||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
import hooksCallOrderTest from './hooksCallOrderTests';
|
||||
import asynchronousHooksTests from './asynchronousHooksTests';
|
||||
import hookScopeTests from './hookScopeTests';
|
||||
import failingHookTests from './failingHookTests';
|
||||
import timingOutHookTests from './timingOutHookTests';
|
||||
|
||||
const suite = new TestSuite('Internal', 'Lifecycle methods', {});
|
||||
|
||||
suite.addTests(hooksCallOrderTest);
|
||||
suite.addTests(asynchronousHooksTests);
|
||||
suite.addTests(hookScopeTests);
|
||||
suite.addTests(failingHookTests);
|
||||
suite.addTests(timingOutHookTests);
|
||||
|
||||
export default suite;
|
|
@ -0,0 +1,327 @@
|
|||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function failingHookTests({ it: _it, describe: _describe }) {
|
||||
_describe('before hooks:', () => {
|
||||
_it('timeout after 5 seconds by default', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
before(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 6000);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" before Hook: TimeoutError: before hook took longer than 5000ms. This can be extended with the timeout option.');
|
||||
});
|
||||
|
||||
_it('allows manually setting timeout', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, before }) => {
|
||||
before({ timeout: 500 }, () => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 600);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" before Hook: TimeoutError: before hook took longer than 500ms. This can be extended with the timeout option.');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('beforeEach hooks:', () => {
|
||||
_it('timeout after 5 seconds by default', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
beforeEach(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 6000);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" beforeEach Hook: TimeoutError: beforeEach hook took longer than 5000ms. This can be extended with the timeout option.');
|
||||
});
|
||||
|
||||
_it('allows manually setting timeout', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, beforeEach }) => {
|
||||
beforeEach({ timeout: 500 }, () => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 600);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" beforeEach Hook: TimeoutError: beforeEach hook took longer than 500ms. This can be extended with the timeout option.');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('afterEach hooks:', () => {
|
||||
_it('timeout after 5 seconds by default', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
afterEach(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 6000);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" afterEach Hook: TimeoutError: afterEach hook took longer than 5000ms. This can be extended with the timeout option.');
|
||||
});
|
||||
|
||||
_it('allows manually setting timeout', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, afterEach }) => {
|
||||
afterEach({ timeout: 500 }, () => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 600);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" afterEach Hook: TimeoutError: afterEach hook took longer than 500ms. This can be extended with the timeout option.');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('after hooks:', () => {
|
||||
_it('timeout after 5 seconds by default', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
after(() => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 6000);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" after Hook: TimeoutError: after hook took longer than 5000ms. This can be extended with the timeout option.');
|
||||
});
|
||||
|
||||
_it('allows manually setting timeout', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
after({ timeout: 500 }, () => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 600);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => { });
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('Error occurred in "" after Hook: TimeoutError: after hook took longer than 500ms. This can be extended with the timeout option.');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default failingHookTests;
|
|
@ -0,0 +1,75 @@
|
|||
import 'babel-core/register';
|
||||
import 'babel-polyfill';
|
||||
import Promise from 'bluebird';
|
||||
import 'colors';
|
||||
|
||||
import RunStatus from './lib/RunStatus';
|
||||
import LifeCycleTestSuite from './hooks/index';
|
||||
import TestsTestSuite from './tests/index';
|
||||
|
||||
let successfulTests = 0;
|
||||
let failingTests = 0;
|
||||
const testErrors = {};
|
||||
|
||||
const suites = [
|
||||
LifeCycleTestSuite,
|
||||
TestsTestSuite,
|
||||
];
|
||||
|
||||
suites.forEach((suite) => {
|
||||
suite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (testSuiteAction) => {
|
||||
if (testSuiteAction.message) {
|
||||
console.error(testSuiteAction.message.red);
|
||||
testErrors[suite.description] = {
|
||||
message: testSuiteAction.message,
|
||||
stackTrace: testSuiteAction.stackTrace,
|
||||
};
|
||||
}
|
||||
},
|
||||
(testAction) => {
|
||||
const test = suite.testDefinitions.tests[testAction.testId];
|
||||
const testContext = suite.testDefinitions.testContexts[test.testContextId];
|
||||
|
||||
const description = (() => {
|
||||
if (testContext.name && !test.description.startsWith(testContext.name)) {
|
||||
return `${testContext.name} ${test.description}`;
|
||||
}
|
||||
|
||||
return test.description;
|
||||
})();
|
||||
|
||||
if (testAction.status === RunStatus.OK) {
|
||||
console.log(` ✅ ${description}`.green);
|
||||
successfulTests += 1;
|
||||
} else if (testAction.status === RunStatus.ERR) {
|
||||
console.log(` ❌ ${description}`.red);
|
||||
testErrors[test.description] = {
|
||||
message: testAction.message,
|
||||
stackTrace: testAction.stackTrace,
|
||||
};
|
||||
failingTests += 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Promise.each(suites, (suite) => {
|
||||
console.log(`\n\n${suite.name} ${suite.description}:\n\r`);
|
||||
return suite.run();
|
||||
}).then(() => {
|
||||
console.log(`\n${successfulTests} tests passed.`);
|
||||
|
||||
if (failingTests) {
|
||||
console.log(`${failingTests} tests failed.`);
|
||||
}
|
||||
|
||||
if (Object.keys(testErrors).length > 0) {
|
||||
console.log('\nErrors:'.red);
|
||||
|
||||
Object.keys(testErrors).forEach((failingTestDescription) => {
|
||||
const error = testErrors[failingTestDescription];
|
||||
console.error(`\n${failingTestDescription}: ${error.message} \n${error.stackTrace}`.red);
|
||||
});
|
||||
}
|
||||
});
|
|
@ -0,0 +1,82 @@
|
|||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function asynchronousTestTests({ it: _it, describe: _describe }) {
|
||||
_describe('tests', () => {
|
||||
_it('can return a promise that is resolved before executing hooks and other tests', async () => {
|
||||
let valueBySecondTest = null;
|
||||
let valueByHook = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
let resolved = false;
|
||||
|
||||
it('', () => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueBySecondTest = resolved;
|
||||
});
|
||||
|
||||
after(() => {
|
||||
valueByHook = resolved;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondTest.should.equal(true);
|
||||
valueByHook.should.equal(true);
|
||||
});
|
||||
|
||||
_it('can be an asynchronous function that is awaited before executing hooks and other tests', async () => {
|
||||
let valueBySecondTest = null;
|
||||
let valueByHook = null;
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, after }) => {
|
||||
let resolved = false;
|
||||
|
||||
it('', async () => {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolved = true;
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
||||
it('', () => {
|
||||
valueBySecondTest = resolved;
|
||||
});
|
||||
|
||||
after(() => {
|
||||
valueByHook = resolved;
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
valueBySecondTest.should.equal(true);
|
||||
valueByHook.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export default asynchronousTestTests;
|
|
@ -0,0 +1,146 @@
|
|||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function failingTestTests({ it: _it, describe: _describe }) {
|
||||
_describe('running a test that is a function that returns a promise', () => {
|
||||
_it('correctly reports a failure when the promise is rejected', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it }) => {
|
||||
it('', () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
reject('failure');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('failure');
|
||||
});
|
||||
|
||||
_it('correctly reports a failure when an error is thrown', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it }) => {
|
||||
|
||||
it('', () => {
|
||||
return new Promise(() => {
|
||||
false.should.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('AssertionError: expected false to be true');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('running an async function test', () => {
|
||||
_it('correctly reports a failure when an error is thrown', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it }) => {
|
||||
it('', async () => {
|
||||
false.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('AssertionError: expected false to be true');
|
||||
});
|
||||
});
|
||||
|
||||
_describe('running an synchronous function test', () => {
|
||||
_it('correctly reports a failure when an error is thrown', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it }) => {
|
||||
it('', () => {
|
||||
false.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('AssertionError: expected false to be true');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default failingTestTests;
|
|
@ -0,0 +1,84 @@
|
|||
import sinon from 'sinon';
|
||||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function focusedTestTests({ it: _it, describe: _describe }) {
|
||||
_describe('when fit is used instead of it', () => {
|
||||
_it('a test is marked as focused', async () => {
|
||||
const focusedTest = sinon.spy();
|
||||
const otherTest = sinon.spy();
|
||||
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, fit }) => {
|
||||
fit('', focusedTest);
|
||||
|
||||
it('', otherTest);
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run(Object.keys(testSuite.testDefinitions.focusedTestIds));
|
||||
|
||||
focusedTest.should.be.called();
|
||||
otherTest.should.not.be.called();
|
||||
});
|
||||
});
|
||||
|
||||
_describe('when fdescribe is used instead of describe', () => {
|
||||
_it('child tests are marked as focused', async () => {
|
||||
const focusedTest = sinon.spy();
|
||||
const otherTest = sinon.spy();
|
||||
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, fdescribe }) => {
|
||||
fdescribe('', () => {
|
||||
it('', focusedTest);
|
||||
});
|
||||
|
||||
it('', otherTest);
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run(Object.keys(testSuite.testDefinitions.focusedTestIds));
|
||||
|
||||
focusedTest.should.be.called();
|
||||
otherTest.should.not.be.called();
|
||||
});
|
||||
});
|
||||
|
||||
_describe('when fcontext is used instead of context', () => {
|
||||
_it('child tests are marked as focused', async () => {
|
||||
const focusedTest = sinon.spy();
|
||||
const otherTest = sinon.spy();
|
||||
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, fcontext }) => {
|
||||
fcontext('', () => {
|
||||
it('', focusedTest);
|
||||
});
|
||||
|
||||
it('', otherTest);
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
await testSuite.run(Object.keys(testSuite.testDefinitions.focusedTestIds));
|
||||
|
||||
focusedTest.should.be.called();
|
||||
otherTest.should.not.be.called();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default focusedTestTests;
|
|
@ -0,0 +1,17 @@
|
|||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
import asynchronousTestTests from './asynchronousTestTests';
|
||||
import focusedTestTests from './focusedTestTests';
|
||||
import pendingTestTests from './pendingTestTests';
|
||||
import failingTestTests from './failingTestTests';
|
||||
import timingOutTests from './timingOutTests';
|
||||
|
||||
const suite = new TestSuite('Internal', 'Test Definitions', {});
|
||||
|
||||
suite.addTests(asynchronousTestTests);
|
||||
suite.addTests(focusedTestTests);
|
||||
suite.addTests(pendingTestTests);
|
||||
suite.addTests(failingTestTests);
|
||||
suite.addTests(timingOutTests);
|
||||
|
||||
export default suite;
|
|
@ -0,0 +1,108 @@
|
|||
import sinon from 'sinon';
|
||||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function pendingTestTests({ it: _it, describe: _describe }) {
|
||||
_describe('when xit is used instead of it', () => {
|
||||
_it('a test is marked as pending', async () => {
|
||||
const pendingTest = sinon.spy();
|
||||
const otherTest = sinon.spy();
|
||||
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, xit }) => {
|
||||
xit('', pendingTest);
|
||||
|
||||
it('', otherTest);
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
const testIdsToRun = Object.keys(testSuite.testDefinitions.tests).reduce((memo, testId) => {
|
||||
if (!testSuite.testDefinitions.pendingTestIds[testId]) {
|
||||
memo.push(testId);
|
||||
}
|
||||
|
||||
return memo;
|
||||
}, []);
|
||||
|
||||
await testSuite.run(testIdsToRun);
|
||||
|
||||
pendingTest.should.not.be.called();
|
||||
otherTest.should.be.called();
|
||||
});
|
||||
});
|
||||
|
||||
_describe('when xdescribe is used instead of describe', () => {
|
||||
_it('child tests are marked as pending', async () => {
|
||||
const pendingTest = sinon.spy();
|
||||
const otherTest = sinon.spy();
|
||||
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, xdescribe }) => {
|
||||
xdescribe('', () => {
|
||||
it('', pendingTest);
|
||||
});
|
||||
|
||||
it('', otherTest);
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
const testIdsToRun = Object.keys(testSuite.testDefinitions.tests).reduce((memo, testId) => {
|
||||
if (!testSuite.testDefinitions.pendingTestIds[testId]) {
|
||||
memo.push(testId);
|
||||
}
|
||||
|
||||
return memo;
|
||||
}, []);
|
||||
|
||||
await testSuite.run(testIdsToRun);
|
||||
|
||||
pendingTest.should.not.be.called();
|
||||
otherTest.should.be.called();
|
||||
});
|
||||
});
|
||||
|
||||
_describe('when xcontext is used instead of context', () => {
|
||||
_it('child tests are marked as pending', async () => {
|
||||
const pendingTest = sinon.spy();
|
||||
const otherTest = sinon.spy();
|
||||
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
|
||||
testSuite.addTests(({ it, xcontext }) => {
|
||||
xcontext('', () => {
|
||||
it('', pendingTest);
|
||||
});
|
||||
|
||||
it('', otherTest);
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
});
|
||||
|
||||
const testIdsToRun = Object.keys(testSuite.testDefinitions.tests).reduce((memo, testId) => {
|
||||
if (!testSuite.testDefinitions.pendingTestIds[testId]) {
|
||||
memo.push(testId);
|
||||
}
|
||||
|
||||
return memo;
|
||||
}, []);
|
||||
|
||||
await testSuite.run(testIdsToRun);
|
||||
|
||||
pendingTest.should.not.be.called();
|
||||
otherTest.should.be.called();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default pendingTestTests;
|
|
@ -0,0 +1,84 @@
|
|||
|
||||
import 'should-sinon';
|
||||
|
||||
import TestSuite from '../lib/TestSuite';
|
||||
|
||||
function timingOutTests({ it: _it, describe: _describe }) {
|
||||
_describe('tests', () => {
|
||||
_it('time out after 5 seconds by default', { timeout: 7000 }, async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it }) => {
|
||||
it('', () => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 6000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('TimeoutError: Test took longer than 5000ms. This can be extended with the timeout option.');
|
||||
});
|
||||
|
||||
_it('can set custom timeout', async () => {
|
||||
const testSuite = new TestSuite('', '', {});
|
||||
const testSuiteStatuses = [];
|
||||
const testStatuses = [];
|
||||
|
||||
testSuite.addTests(({ it }) => {
|
||||
it('', { timeout: 500 }, () => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
testSuite.setStore({
|
||||
getState: () => { return {}; },
|
||||
}, (value) => {
|
||||
testSuiteStatuses.push(value);
|
||||
}, (value) => {
|
||||
testStatuses.push(value);
|
||||
});
|
||||
|
||||
await testSuite.run();
|
||||
|
||||
const lastTestSuiteStatus = testSuiteStatuses[testSuiteStatuses.length - 1];
|
||||
|
||||
lastTestSuiteStatus.progress.should.equal(100);
|
||||
lastTestSuiteStatus.status.should.equal('error');
|
||||
lastTestSuiteStatus.message.should.equal('1 test has error(s).');
|
||||
|
||||
const lastTestStatus = testStatuses[testStatuses.length - 1];
|
||||
|
||||
lastTestStatus.status.should.equal('error');
|
||||
lastTestStatus.message.should.equal('TimeoutError: Test took longer than 500ms. This can be extended with the timeout option.');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default timingOutTests;
|
|
@ -0,0 +1,66 @@
|
|||
import re
|
||||
|
||||
# To learn about Buck see [Docs](https://buckbuild.com/).
|
||||
# To run your application with Buck:
|
||||
# - install Buck
|
||||
# - `npm start` - to start the packager
|
||||
# - `cd android`
|
||||
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
|
||||
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
|
||||
# - `buck install -r android/app` - compile, install and run application
|
||||
#
|
||||
|
||||
lib_deps = []
|
||||
for jarfile in glob(['libs/*.jar']):
|
||||
name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile)
|
||||
lib_deps.append(':' + name)
|
||||
prebuilt_jar(
|
||||
name = name,
|
||||
binary_jar = jarfile,
|
||||
)
|
||||
|
||||
for aarfile in glob(['libs/*.aar']):
|
||||
name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile)
|
||||
lib_deps.append(':' + name)
|
||||
android_prebuilt_aar(
|
||||
name = name,
|
||||
aar = aarfile,
|
||||
)
|
||||
|
||||
android_library(
|
||||
name = 'all-libs',
|
||||
exported_deps = lib_deps
|
||||
)
|
||||
|
||||
android_library(
|
||||
name = 'app-code',
|
||||
srcs = glob([
|
||||
'src/main/java/**/*.java',
|
||||
]),
|
||||
deps = [
|
||||
':all-libs',
|
||||
':build_config',
|
||||
':res',
|
||||
],
|
||||
)
|
||||
|
||||
android_build_config(
|
||||
name = 'build_config',
|
||||
package = 'com.reactnativefirebasedemo',
|
||||
)
|
||||
|
||||
android_resource(
|
||||
name = 'res',
|
||||
res = 'src/main/res',
|
||||
package = 'com.reactnativefirebasedemo',
|
||||
)
|
||||
|
||||
android_binary(
|
||||
name = 'app',
|
||||
package_type = 'debug',
|
||||
manifest = 'src/main/AndroidManifest.xml',
|
||||
keystore = '//android/keystores:debug',
|
||||
deps = [
|
||||
':app-code',
|
||||
],
|
||||
)
|
|
@ -0,0 +1,144 @@
|
|||
apply plugin: "com.android.application"
|
||||
|
||||
import com.android.build.OutputFile
|
||||
|
||||
/**
|
||||
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
|
||||
* and bundleReleaseJsAndAssets).
|
||||
* These basically call `react-native bundle` with the correct arguments during the Android build
|
||||
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
|
||||
* bundle directly from the development server. Below you can see all the possible configurations
|
||||
* and their defaults. If you decide to add a configuration block, make sure to add it before the
|
||||
* `apply from: "../../node_modules/react-native/react.gradle"` line.
|
||||
*
|
||||
* project.ext.react = [
|
||||
* // the name of the generated asset file containing your JS bundle
|
||||
* bundleAssetName: "index.android.bundle",
|
||||
*
|
||||
* // the entry file for bundle generation
|
||||
* entryFile: "index.android.js",
|
||||
*
|
||||
* // whether to bundle JS and assets in debug mode
|
||||
* bundleInDebug: false,
|
||||
*
|
||||
* // whether to bundle JS and assets in release mode
|
||||
* bundleInRelease: true,
|
||||
*
|
||||
* // whether to bundle JS and assets in another build variant (if configured).
|
||||
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
|
||||
* // The configuration property can be in the following formats
|
||||
* // 'bundleIn${productFlavor}${buildType}'
|
||||
* // 'bundleIn${buildType}'
|
||||
* // bundleInFreeDebug: true,
|
||||
* // bundleInPaidRelease: true,
|
||||
* // bundleInBeta: true,
|
||||
*
|
||||
* // the root of your project, i.e. where "package.json" lives
|
||||
* root: "../../",
|
||||
*
|
||||
* // where to put the JS bundle asset in debug mode
|
||||
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
|
||||
*
|
||||
* // where to put the JS bundle asset in release mode
|
||||
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
|
||||
*
|
||||
* // where to put drawable resources / React Native assets, e.g. the ones you use via
|
||||
* // require('./image.png')), in debug mode
|
||||
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
|
||||
*
|
||||
* // where to put drawable resources / React Native assets, e.g. the ones you use via
|
||||
* // require('./image.png')), in release mode
|
||||
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
|
||||
*
|
||||
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
|
||||
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
|
||||
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
|
||||
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
|
||||
* // for example, you might want to remove it from here.
|
||||
* inputExcludes: ["android/**", "ios/**"],
|
||||
*
|
||||
* // override which node gets called and with what additional arguments
|
||||
* nodeExecutableAndArgs: ["node"]
|
||||
*
|
||||
* // supply additional arguments to the packager
|
||||
* extraPackagerArgs: []
|
||||
* ]
|
||||
*/
|
||||
|
||||
apply from: "../../node_modules/react-native/react.gradle"
|
||||
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
|
||||
|
||||
/**
|
||||
* Set this to true to create two separate APKs instead of one:
|
||||
* - An APK that only works on ARM devices
|
||||
* - An APK that only works on x86 devices
|
||||
* The advantage is the size of the APK is reduced by about 4MB.
|
||||
* Upload all the APKs to the Play Store and people will download
|
||||
* the correct one based on the CPU architecture of their device.
|
||||
*/
|
||||
def enableSeparateBuildPerCPUArchitecture = false
|
||||
|
||||
/**
|
||||
* Run Proguard to shrink the Java bytecode in release builds.
|
||||
*/
|
||||
def enableProguardInReleaseBuilds = false
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion '25.0.2'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.reactnativefirebasedemo"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "x86"
|
||||
}
|
||||
}
|
||||
splits {
|
||||
abi {
|
||||
reset()
|
||||
enable enableSeparateBuildPerCPUArchitecture
|
||||
universalApk false // If true, also generate a universal APK
|
||||
include "armeabi-v7a", "x86"
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled enableProguardInReleaseBuilds
|
||||
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
||||
}
|
||||
}
|
||||
// applicationVariants are e.g. debug, release
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
// For each separate APK per architecture, set a unique version code as described here:
|
||||
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
|
||||
def versionCodes = ["armeabi-v7a": 1, "x86": 2]
|
||||
def abi = output.getFilter(OutputFile.ABI)
|
||||
if (abi != null) { // null for the universal-debug, universal-release variants
|
||||
output.versionCodeOverride =
|
||||
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':react-native-firebase')
|
||||
compile project(':react-native-vector-icons')
|
||||
compile fileTree(dir: "libs", include: ["*.jar"])
|
||||
compile "com.android.support:appcompat-v7:24.0.0"
|
||||
compile "com.facebook.react:react-native:+" // From node_modules
|
||||
}
|
||||
|
||||
// Run this once to be able to run the application with BUCK
|
||||
// puts all compile dependencies into folder libs for BUCK to use
|
||||
task copyDownloadableDepsToLibs(type: Copy) {
|
||||
from configurations.compile
|
||||
into 'libs'
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"project_info": {
|
||||
"project_number": "305229645282",
|
||||
"firebase_url": "https://rnfirebase-b9ad4.firebaseio.com",
|
||||
"project_id": "rnfirebase-b9ad4",
|
||||
"storage_bucket": "rnfirebase-b9ad4.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:305229645282:android:efe37851d57e1d05",
|
||||
"android_client_info": {
|
||||
"package_name": "com.reactnativefirebasedemo"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "305229645282-j8ij0jev9ut24odmlk9i215pas808ugn.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyCzbBYFyX8d6VdSu7T4s10IWYbPc-dguwM"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"analytics_service": {
|
||||
"status": 1
|
||||
},
|
||||
"appinvite_service": {
|
||||
"status": 1,
|
||||
"other_platform_oauth_client": []
|
||||
},
|
||||
"ads_service": {
|
||||
"status": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Disabling obfuscation is useful if you collect stack traces from production crashes
|
||||
# (unless you are using a system that supports de-obfuscate the stack traces).
|
||||
-dontobfuscate
|
||||
|
||||
# React Native
|
||||
|
||||
# Keep our interfaces so they can be used by other ProGuard rules.
|
||||
# See http://sourceforge.net/p/proguard/bugs/466/
|
||||
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
|
||||
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
|
||||
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
|
||||
|
||||
# Do not strip any method/class that is annotated with @DoNotStrip
|
||||
-keep @com.facebook.proguard.annotations.DoNotStrip class *
|
||||
-keep @com.facebook.common.internal.DoNotStrip class *
|
||||
-keepclassmembers class * {
|
||||
@com.facebook.proguard.annotations.DoNotStrip *;
|
||||
@com.facebook.common.internal.DoNotStrip *;
|
||||
}
|
||||
|
||||
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
|
||||
void set*(***);
|
||||
*** get*();
|
||||
}
|
||||
|
||||
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
|
||||
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
|
||||
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
|
||||
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
|
||||
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
|
||||
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
|
||||
|
||||
-dontwarn com.facebook.react.**
|
||||
|
||||
# okhttp
|
||||
|
||||
-keepattributes Signature
|
||||
-keepattributes *Annotation*
|
||||
-keep class okhttp3.** { *; }
|
||||
-keep interface okhttp3.** { *; }
|
||||
-dontwarn okhttp3.**
|
||||
|
||||
# okio
|
||||
|
||||
-keep class sun.misc.Unsafe { *; }
|
||||
-dontwarn java.nio.file.*
|
||||
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
|
||||
-dontwarn okio.**
|
|
@ -0,0 +1,51 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.reactnativefirebasedemo"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="16"
|
||||
android:targetSdkVersion="22" />
|
||||
|
||||
<application
|
||||
android:name=".MainApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/AppTheme">
|
||||
<service
|
||||
android:name="io.invertase.firebase.messaging.MessagingService"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service android:name="io.invertase.firebase.messaging.InstanceIdService" android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,15 @@
|
|||
package com.reactnativefirebasedemo;
|
||||
|
||||
import com.facebook.react.ReactActivity;
|
||||
|
||||
public class MainActivity extends ReactActivity {
|
||||
|
||||
/**
|
||||
* Returns the name of the main component registered from JavaScript.
|
||||
* This is used to schedule rendering of the component.
|
||||
*/
|
||||
@Override
|
||||
protected String getMainComponentName() {
|
||||
return "ReactNativeFirebaseDemo";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.reactnativefirebasedemo;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.facebook.react.ReactApplication;
|
||||
import io.invertase.firebase.RNFirebasePackage;
|
||||
import com.oblador.vectoricons.VectorIconsPackage;
|
||||
import com.facebook.react.ReactNativeHost;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.shell.MainReactPackage;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
|
||||
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
|
||||
@Override
|
||||
protected boolean getUseDeveloperSupport() {
|
||||
return BuildConfig.DEBUG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ReactPackage> getPackages() {
|
||||
return Arrays.<ReactPackage>asList(
|
||||
new MainReactPackage(),
|
||||
new VectorIconsPackage(),
|
||||
new RNFirebasePackage()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public ReactNativeHost getReactNativeHost() {
|
||||
return mReactNativeHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
SoLoader.init(this, /* native exopackage */ false);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 16 KiB |
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">ReactNativeFirebaseDemo</string>
|
||||
</resources>
|
|
@ -0,0 +1,8 @@
|
|||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -0,0 +1,48 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
||||
classpath 'com.google.gms:google-services:3.0.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven {
|
||||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
||||
url "$rootDir/../node_modules/react-native/android"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
ext {
|
||||
compileSdk = 25
|
||||
buildTools = "25.0.2"
|
||||
minSdk = 16
|
||||
targetSdk = 25
|
||||
}
|
||||
|
||||
afterEvaluate { project ->
|
||||
if (!project.name.equalsIgnoreCase("app")
|
||||
&& project.hasProperty("android")) {
|
||||
android {
|
||||
compileSdkVersion compileSdk
|
||||
buildToolsVersion buildTools
|
||||
defaultConfig {
|
||||
minSdkVersion minSdk
|
||||
targetSdkVersion targetSdk
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
|
||||
android.useDeprecatedNdk=true
|
|
@ -0,0 +1,160 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
|
@ -0,0 +1,90 @@
|
|||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
|
@ -0,0 +1,8 @@
|
|||
keystore(
|
||||
name = 'debug',
|
||||
store = 'debug.keystore',
|
||||
properties = 'debug.keystore.properties',
|
||||
visibility = [
|
||||
'PUBLIC',
|
||||
],
|
||||
)
|
|
@ -0,0 +1,4 @@
|
|||
key.store=debug.keystore
|
||||
key.alias=androiddebugkey
|
||||
key.store.password=android
|
||||
key.alias.password=android
|
|
@ -0,0 +1,7 @@
|
|||
rootProject.name = 'ReactNativeFirebaseDemo'
|
||||
include ':react-native-firebase'
|
||||
project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android')
|
||||
include ':react-native-vector-icons'
|
||||
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
|
||||
|
||||
include ':app'
|
After Width: | Height: | Size: 21 KiB |
|
@ -0,0 +1,5 @@
|
|||
import { AppRegistry } from 'react-native';
|
||||
import bootstrap from './src/main';
|
||||
|
||||
|
||||
AppRegistry.registerComponent('ReactNativeFirebaseDemo', () => bootstrap);
|
|
@ -0,0 +1,4 @@
|
|||
import { AppRegistry } from 'react-native';
|
||||
import bootstrap from './src/main';
|
||||
|
||||
AppRegistry.registerComponent('ReactNativeFirebaseDemo', () => bootstrap);
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>AD_UNIT_ID_FOR_BANNER_TEST</key>
|
||||
<string>ca-app-pub-3940256099942544/2934735716</string>
|
||||
<key>AD_UNIT_ID_FOR_INTERSTITIAL_TEST</key>
|
||||
<string>ca-app-pub-3940256099942544/4411468910</string>
|
||||
<key>CLIENT_ID</key>
|
||||
<string>305229645282-22imndi01abc2p6esgtu1i1m9mqrd0ib.apps.googleusercontent.com</string>
|
||||
<key>REVERSED_CLIENT_ID</key>
|
||||
<string>com.googleusercontent.apps.305229645282-22imndi01abc2p6esgtu1i1m9mqrd0ib</string>
|
||||
<key>API_KEY</key>
|
||||
<string>AIzaSyAcdVLG5dRzA1ck_fa_xd4Z0cY7cga7S5A</string>
|
||||
<key>GCM_SENDER_ID</key>
|
||||
<string>305229645282</string>
|
||||
<key>PLIST_VERSION</key>
|
||||
<string>1</string>
|
||||
<key>BUNDLE_ID</key>
|
||||
<string>com.invertase.ReactNativeFirebaseDemo</string>
|
||||
<key>PROJECT_ID</key>
|
||||
<string>rnfirebase-b9ad4</string>
|
||||
<key>STORAGE_BUCKET</key>
|
||||
<string>rnfirebase-b9ad4.appspot.com</string>
|
||||
<key>IS_ADS_ENABLED</key>
|
||||
<true/>
|
||||
<key>IS_ANALYTICS_ENABLED</key>
|
||||
<false/>
|
||||
<key>IS_APPINVITE_ENABLED</key>
|
||||
<false/>
|
||||
<key>IS_GCM_ENABLED</key>
|
||||
<true/>
|
||||
<key>IS_SIGNIN_ENABLED</key>
|
||||
<true/>
|
||||
<key>GOOGLE_APP_ID</key>
|
||||
<string>1:305229645282:ios:7b45748cb1117d2d</string>
|
||||
<key>DATABASE_URL</key>
|
||||
<string>https://rnfirebase-b9ad4.firebaseio.com</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string></string>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
|
||||
<dict>
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>localhost</key>
|
||||
<dict>
|
||||
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,129 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0820"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "NO"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2D2A28121D9B038B00D4039D"
|
||||
BuildableName = "libReact.a"
|
||||
BlueprintName = "React-tvOS"
|
||||
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
|
||||
BuildableName = "ReactNativeFirebaseDemo-tvOS.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo-tvOS"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
|
||||
BuildableName = "ReactNativeFirebaseDemo-tvOSTests.xctest"
|
||||
BlueprintName = "ReactNativeFirebaseDemo-tvOSTests"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
|
||||
BuildableName = "ReactNativeFirebaseDemo-tvOSTests.xctest"
|
||||
BlueprintName = "ReactNativeFirebaseDemo-tvOSTests"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
|
||||
BuildableName = "ReactNativeFirebaseDemo-tvOS.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo-tvOS"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
|
||||
BuildableName = "ReactNativeFirebaseDemo-tvOS.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo-tvOS"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
|
||||
BuildableName = "ReactNativeFirebaseDemo-tvOS.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo-tvOS"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,129 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0620"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "NO"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "83CBBA2D1A601D0E00E9B192"
|
||||
BuildableName = "libReact.a"
|
||||
BlueprintName = "React"
|
||||
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
|
||||
BuildableName = "ReactNativeFirebaseDemo.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
|
||||
BuildableName = "ReactNativeFirebaseDemoTests.xctest"
|
||||
BlueprintName = "ReactNativeFirebaseDemoTests"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "00E356ED1AD99517003FC87E"
|
||||
BuildableName = "ReactNativeFirebaseDemoTests.xctest"
|
||||
BlueprintName = "ReactNativeFirebaseDemoTests"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
|
||||
BuildableName = "ReactNativeFirebaseDemo.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
|
||||
BuildableName = "ReactNativeFirebaseDemo.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
|
||||
BuildableName = "ReactNativeFirebaseDemo.app"
|
||||
BlueprintName = "ReactNativeFirebaseDemo"
|
||||
ReferencedContainer = "container:ReactNativeFirebaseDemo.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||
|
||||
@property (nonatomic, strong) UIWindow *window;
|
||||
|
||||
@end
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import <React/RCTBundleURLProvider.h>
|
||||
#import <React/RCTRootView.h>
|
||||
#import <Firebase.h>
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
[FIRApp configure];
|
||||
NSURL *jsCodeLocation;
|
||||
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
|
||||
|
||||
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
|
||||
moduleName:@"ReactNativeFirebaseDemo"
|
||||
initialProperties:nil
|
||||
launchOptions:launchOptions];
|
||||
|
||||
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
|
||||
|
||||
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||
UIViewController *rootViewController = [UIViewController new];
|
||||
rootViewController.view = rootView;
|
||||
self.window.rootViewController = rootViewController;
|
||||
[self.window makeKeyAndVisible];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="iN0-l3-epB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
|
||||
<rect key="frame" x="20" y="439" width="441" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ReactNativeFirebaseDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
|
||||
<rect key="frame" x="20" y="140" width="441" height="43"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<constraints>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
|
||||
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
|
||||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
|
||||
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
|
||||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<point key="canvasLocation" x="548" y="455"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"images" : [
|
||||
{
|
||||
"size" : "20x20",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-20@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "20x20",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-20@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-29.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-29@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "29x29",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-29@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-40@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "40x40",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-40@3x.png",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"size" : "57x57",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-57.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "57x57",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-57@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-60@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "60x60",
|
||||
"idiom" : "iphone",
|
||||
"filename" : "Icon-60@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 8.3 KiB |
After Width: | Height: | Size: 7.5 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 20 KiB |
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSExceptionDomains</key>
|
||||
<dict>
|
||||
<key>localhost</key>
|
||||
<dict>
|
||||
<key>NSExceptionAllowsInsecureHTTPLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string></string>
|
||||
<key>UIAppFonts</key>
|
||||
<array>
|
||||
<string>Entypo.ttf</string>
|
||||
<string>EvilIcons.ttf</string>
|
||||
<string>FontAwesome.ttf</string>
|
||||
<string>Foundation.ttf</string>
|
||||
<string>Ionicons.ttf</string>
|
||||
<string>MaterialCommunityIcons.ttf</string>
|
||||
<string>MaterialIcons.ttf</string>
|
||||
<string>Octicons.ttf</string>
|
||||
<string>SimpleLineIcons.ttf</string>
|
||||
<string>Zocial.ttf</string>
|
||||
</array>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
@autoreleasepool {
|
||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTRootView.h>
|
||||
|
||||
#define TIMEOUT_SECONDS 600
|
||||
#define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
|
||||
|
||||
@interface ReactNativeFirebaseDemoTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation ReactNativeFirebaseDemoTests
|
||||
|
||||
- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
|
||||
{
|
||||
if (test(view)) {
|
||||
return YES;
|
||||
}
|
||||
for (UIView *subview in [view subviews]) {
|
||||
if ([self findSubviewInView:subview matching:test]) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)testRendersWelcomeScreen
|
||||
{
|
||||
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
|
||||
BOOL foundElement = NO;
|
||||
|
||||
__block NSString *redboxError = nil;
|
||||
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
|
||||
if (level >= RCTLogLevelError) {
|
||||
redboxError = message;
|
||||
}
|
||||
});
|
||||
|
||||
while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
|
||||
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||
|
||||
foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
|
||||
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}];
|
||||
}
|
||||
|
||||
RCTSetLogFunction(RCTDefaultLogFunction);
|
||||
|
||||
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
|
||||
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
RUNNING: 'running',
|
||||
OK: 'success',
|
||||
ERR: 'error',
|
||||
};
|
|
@ -0,0 +1,251 @@
|
|||
/**
|
||||
* Class that provides DSL for declaratively defining tests. Provides a declarative
|
||||
* interface for {@link TestSuiteDefinition} and only reveals methods that are part
|
||||
* of the test definition DSL.
|
||||
*/
|
||||
class TestDSL {
|
||||
/**
|
||||
* Create a new instance of TestDSL
|
||||
* @param {TestSuiteDefinition} testSuiteDefinition - Class to delegate the heavy lifting
|
||||
* of satisfying the DSL, to.
|
||||
* @param {Object} firebase - Object containing native and web firebase instances
|
||||
* @param {Object} firebase.native - Native firebase instance
|
||||
* @para {Object} firebase.web - Web firebase instance
|
||||
*/
|
||||
constructor(testSuiteDefinition, firebase) {
|
||||
this._testSuiteDefinition = testSuiteDefinition;
|
||||
|
||||
this.firebase = firebase;
|
||||
|
||||
this.after = this.after.bind(this);
|
||||
this.afterEach = this.afterEach.bind(this);
|
||||
|
||||
this.before = this.before.bind(this);
|
||||
this.beforeEach = this.beforeEach.bind(this);
|
||||
|
||||
this.describe = this.describe.bind(this);
|
||||
/** Alias for {@link TestDSL#describe } */
|
||||
this.context = this.describe;
|
||||
this.fdescribe = this.fdescribe.bind(this);
|
||||
/** Alias for {@link TestDSL#fdescribe } */
|
||||
this.fcontext = this.fdescribe;
|
||||
this.xdescribe = this.xdescribe.bind(this);
|
||||
/** Alias for {@link TestDSL#xdescribe } */
|
||||
this.xcontext = this.xdescribe;
|
||||
|
||||
this.tryCatch = this.tryCatch.bind(this);
|
||||
|
||||
this.it = this.it.bind(this);
|
||||
this.xit = this.xit.bind(this);
|
||||
this.fit = this.fit.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a before hook to the current test context
|
||||
* @param {Object=} options - Options object
|
||||
* @param {Number=10000} options.timeout - Number of milliseconds before callback times
|
||||
* out
|
||||
* @param {Function} callback - Function to add as before hook to current test context
|
||||
*/
|
||||
before(options, callback = undefined) {
|
||||
const _options = callback ? options : {};
|
||||
const _callback = callback || options;
|
||||
|
||||
this._testSuiteDefinition.addBeforeHook(_callback, _options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a before each hook to the current test context
|
||||
* @param {Object=} options - Options object
|
||||
* @param {Number=10000} options.timeout - Number of milliseconds before callback times
|
||||
* out
|
||||
* @param {Function} callback - Function to add as before each hook to current test
|
||||
* context
|
||||
*/
|
||||
beforeEach(options, callback = undefined) {
|
||||
const _options = callback ? options : {};
|
||||
const _callback = callback || options;
|
||||
|
||||
this._testSuiteDefinition.addBeforeEachHook(_callback, _options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a after each hook to the current test context
|
||||
* @param {Object=} options - Options object
|
||||
* @param {Number=10000} options.timeout - Number of milliseconds before callback times
|
||||
* out
|
||||
* @param {Function} callback - Function to add as after each hook to current test context
|
||||
*/
|
||||
afterEach(options, callback = undefined) {
|
||||
const _options = callback ? options : {};
|
||||
const _callback = callback || options;
|
||||
|
||||
this._testSuiteDefinition.addAfterEachHook(_callback, _options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a after hook to the current test context
|
||||
* @param {Object=} options - Options object
|
||||
* @param {Number=10000} options.timeout - Number of milliseconds before callback times
|
||||
* out
|
||||
* @param {Function} callback - Function to add as after hook to current test context
|
||||
*/
|
||||
after(options, callback = undefined) {
|
||||
const _options = callback ? options : {};
|
||||
const _callback = callback || options;
|
||||
|
||||
this._testSuiteDefinition.addAfterHook(_callback, _options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new test context
|
||||
* @param {String} name - name of new test context
|
||||
* @param {ContextOptions} options - options for context
|
||||
* @param {Function} [testDefinitions={}] - function that defines further test contexts and
|
||||
* tests using the test DSL
|
||||
*/
|
||||
describe(name, options, testDefinitions) {
|
||||
let _testDefinitions;
|
||||
let _options;
|
||||
|
||||
if (testDefinitions) {
|
||||
_testDefinitions = testDefinitions;
|
||||
_options = options;
|
||||
} else {
|
||||
_testDefinitions = options;
|
||||
_options = {};
|
||||
}
|
||||
|
||||
this._testSuiteDefinition.pushTestContext(name, _options);
|
||||
_testDefinitions();
|
||||
this._testSuiteDefinition.popTestContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new pending test context. Tests in a pending test context are not
|
||||
* run when the test suite is executed. They also appear greyed out.
|
||||
* @param {String} name - name of new test context
|
||||
* @param {ContextOptions} [options={}] - options for context
|
||||
* @param {Function} testDefinitions - function that defines further test contexts and
|
||||
* tests using the test DSL
|
||||
*/
|
||||
xdescribe(name, options, testDefinitions = undefined) {
|
||||
let _options = {};
|
||||
let _testDefinitions;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
_options = { pending: true };
|
||||
_testDefinitions = options;
|
||||
} else {
|
||||
Object.assign(_options, options, { pending: true });
|
||||
_testDefinitions = testDefinitions;
|
||||
}
|
||||
|
||||
this.describe(name, _options, _testDefinitions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new focused test context. Tests in a focused test context are the only
|
||||
* ones that appear and are run when the test suite is executed.
|
||||
* @param {String} name - name of new test context
|
||||
* @param {ContextOptions} [options={}] - options for context
|
||||
* @param {Function} testDefinitions - function that defines further test contexts and
|
||||
* tests using the test DSL
|
||||
*/
|
||||
fdescribe(name, options, testDefinitions = undefined) {
|
||||
let _options = {};
|
||||
let _testDefinitions;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
_options = { focus: true };
|
||||
_testDefinitions = options;
|
||||
} else {
|
||||
Object.assign(_options, options, { focus: true });
|
||||
_testDefinitions = testDefinitions;
|
||||
}
|
||||
|
||||
this.describe(name, _options, _testDefinitions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a new test.
|
||||
* @param {String} description - Brief description of what the test expects
|
||||
* @param {TestOptions} options - Options of whether test should be focused or pending
|
||||
* @param {Function} testFunction - Body of the test containing setup and assertions
|
||||
*/
|
||||
it(description, options, testFunction = undefined) {
|
||||
this._testSuiteDefinition.addTest(description, options, testFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a new pending test. Pending tests are not run when the test suite is
|
||||
* executed. They also appear greyed out.
|
||||
* @param {String} description - Brief description of what the test expects
|
||||
* @param {ContextOptions} [options={}] - Options of whether test should be focused or pending
|
||||
* @param {Function} testFunction - Body of the test containing setup and assertions
|
||||
*/
|
||||
xit(description, options, testFunction = undefined) {
|
||||
let _options = {};
|
||||
let _testFunction;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
_options = { pending: true };
|
||||
_testFunction = options;
|
||||
} else {
|
||||
Object.assign(_options, options, { pending: true });
|
||||
_testFunction = testFunction;
|
||||
}
|
||||
|
||||
this.it(description, _options, _testFunction);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines a new focused test. Focused tests are the only
|
||||
* ones that appear and are run when the test suite is executed.
|
||||
* @param {String} description - Brief description of what the test expects
|
||||
* @param {ContextOptions} [options={}] - Options of whether test should be focused or pending
|
||||
* @param {Function} testFunction - Body of the test containing setup and assertions
|
||||
*/
|
||||
fit(description, options, testFunction = undefined) {
|
||||
let _options = {};
|
||||
let _testFunction;
|
||||
|
||||
if (typeof options === 'function') {
|
||||
_options = { focus: true };
|
||||
_testFunction = options;
|
||||
} else {
|
||||
Object.assign(_options, options, { focus: true });
|
||||
_testFunction = testFunction;
|
||||
}
|
||||
|
||||
this.it(description, _options, _testFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries evaluating a function and calls a reject callback if it throws an error
|
||||
* @param {Function} callback - Function to evaluate
|
||||
* @param {Function} reject - Function to call if callback throws an error
|
||||
* @returns {function(...[*])} a function that will catch any errors thrown by callback,
|
||||
* passing them to reject instead.
|
||||
*/
|
||||
tryCatch(callback, reject) {
|
||||
return (...args) => {
|
||||
try {
|
||||
callback(...args);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a test DSL error to the console.
|
||||
* @param {String} error - Message to included in message logged to the console
|
||||
*/
|
||||
function testDSLError(error) {
|
||||
console.error(`ReactNativeFirebaseTests.TestDSLError: ${error}`);
|
||||
console.error('This test was ignored.');
|
||||
}
|
||||
export default TestDSL;
|
|
@ -0,0 +1,386 @@
|
|||
import Promise from 'bluebird';
|
||||
import RunStatus from './RunStatus';
|
||||
|
||||
const EVENTS = {
|
||||
TEST_SUITE_STATUS: 'TEST_SUITE_STATUS',
|
||||
TEST_STATUS: 'TEST_STATUS',
|
||||
};
|
||||
|
||||
/**
|
||||
* Class that encapsulates synchronously running a suite's tests.
|
||||
*/
|
||||
class TestRun {
|
||||
/**
|
||||
* The number of tests that have been executed so far
|
||||
* @type {number}
|
||||
*/
|
||||
completedTests = 0;
|
||||
|
||||
/**
|
||||
* Creates a new TestRun
|
||||
* @param {TestSuite} testSuite - Test suite that tests belong to
|
||||
* @param {Test[]} tests - List of test to run
|
||||
* @param {TestSuiteDefinition} testDefinitions - Definition of tests and contexts
|
||||
*/
|
||||
constructor(testSuite, tests, testDefinitions) {
|
||||
this.testSuite = testSuite;
|
||||
|
||||
this.tests = tests;
|
||||
|
||||
this.rootContextId = testDefinitions.rootTestContextId;
|
||||
|
||||
this.testContexts = tests.reduce((memo, test) => {
|
||||
const testContextId = test.testContextId;
|
||||
|
||||
this._recursivelyAddContextsTo(memo, testContextId, testDefinitions.testContexts);
|
||||
|
||||
memo[testContextId].tests.unshift(test);
|
||||
|
||||
return memo;
|
||||
}, {});
|
||||
|
||||
this.listeners = {
|
||||
[EVENTS.TEST_STATUS]: [],
|
||||
[EVENTS.TEST_SUITE_STATUS]: [],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener for a change event
|
||||
* @param {String} action - one of the actions in EVENTS
|
||||
* @param {Function} callback - Callback that accepts event object
|
||||
*/
|
||||
onChange(action, callback) {
|
||||
this.listeners[action].push(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks up a context tree, copying test contexts from a source object to a target one.
|
||||
* Used for ensuring all of a test's parent contexts are added to the target object.
|
||||
* @param {Object<Number,TestContext>} target - Object to put test contexts in
|
||||
* @param {Number} id - Id of current context to add to target
|
||||
* @param {Object<Number,TestContext>} source - Object to get complete list of test contexts
|
||||
* from.
|
||||
* @param {Number} childContextId - id of child of current context
|
||||
* @private
|
||||
*/
|
||||
_recursivelyAddContextsTo(target, id, source, childContextId = null) {
|
||||
const testContext = source[id];
|
||||
|
||||
if (!target[id]) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
target[id] = {
|
||||
...testContext,
|
||||
tests: [],
|
||||
childContextIds: {},
|
||||
};
|
||||
}
|
||||
|
||||
if (childContextId) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
target[id].childContextIds[childContextId] = true;
|
||||
}
|
||||
|
||||
const parentContextId = testContext.parentContextId;
|
||||
|
||||
if (parentContextId) {
|
||||
this._recursivelyAddContextsTo(target, parentContextId, source, id);
|
||||
}
|
||||
}
|
||||
|
||||
_updateStatus(action, values) {
|
||||
const listeners = this.listeners[action];
|
||||
|
||||
listeners.forEach(listener => listener(values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the tests TestRun was initialised with.
|
||||
* @returns {Promise.<void>} Resolves once all the tests in the test suite have
|
||||
* completed running.
|
||||
*/
|
||||
async execute() {
|
||||
const store = this.testSuite.reduxStore;
|
||||
|
||||
if (!store) {
|
||||
testRuntimeError(`Failed to run ${this.testSuite.name} tests as no Redux store has been provided`);
|
||||
}
|
||||
|
||||
this._updateStatus(EVENTS.TEST_SUITE_STATUS, {
|
||||
suiteId: this.testSuite.id,
|
||||
status: RunStatus.RUNNING,
|
||||
|
||||
progress: 0,
|
||||
time: 0,
|
||||
});
|
||||
|
||||
// Start timing
|
||||
|
||||
this.runStartTime = Date.now();
|
||||
|
||||
const rootContext = this.testContexts[this.rootContextId];
|
||||
|
||||
if (rootContext) {
|
||||
await this._runTestsInContext(rootContext);
|
||||
|
||||
const errors = this.tests.filter(test => test.status === RunStatus.ERR);
|
||||
|
||||
if (errors.length) {
|
||||
this._updateStatus(EVENTS.TEST_SUITE_STATUS, {
|
||||
suiteId: this.testSuite.id,
|
||||
status: RunStatus.ERR,
|
||||
progress: 100,
|
||||
|
||||
time: Date.now() - this.runStartTime,
|
||||
message: `${errors.length} test${errors.length > 1 ? 's' : ''} has error(s).`,
|
||||
});
|
||||
} else {
|
||||
this._updateStatus(EVENTS.TEST_SUITE_STATUS, ({
|
||||
suiteId: this.testSuite.id,
|
||||
status: RunStatus.OK,
|
||||
progress: 100,
|
||||
|
||||
time: Date.now() - this.runStartTime,
|
||||
message: '',
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively enter a test context and run its before, beforeEach hooks where
|
||||
* appropriate; execute the test and then run afterEach and after hooks where
|
||||
* appropriate.
|
||||
* @param {TestContext} testContext - context to run hooks for
|
||||
* @param {Function[][]} beforeEachHooks - stack of beforeEach hooks defined
|
||||
* in parent contexts that should be run beforeEach test in child contexts
|
||||
* @param {Function[][]} afterEachHooks - stack of afterEach hooks defined
|
||||
* in parent contexts that should be run afterEach test in child contexts
|
||||
* @returns {Promise.<void>} Resolves once all tests and their hooks have run
|
||||
* @private
|
||||
*/
|
||||
async _runTestsInContext(testContext, beforeEachHooks = [], afterEachHooks = []) {
|
||||
const beforeHookRan = await this._runContextHooks(testContext, 'before');
|
||||
|
||||
if (beforeHookRan) {
|
||||
beforeEachHooks.push(testContext.beforeEachHooks || []);
|
||||
afterEachHooks.unshift(testContext.afterEachHooks || []);
|
||||
|
||||
await this._runTests(testContext, testContext.tests, flatten(beforeEachHooks), flatten(afterEachHooks));
|
||||
|
||||
await Promise.each(Object.keys(testContext.childContextIds), (childContextId) => {
|
||||
const childContext = this.testContexts[childContextId];
|
||||
return this._runTestsInContext(childContext, beforeEachHooks, afterEachHooks);
|
||||
});
|
||||
|
||||
beforeEachHooks.pop();
|
||||
afterEachHooks.shift();
|
||||
|
||||
await this._runContextHooks(testContext, 'after');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously run hooks in context's (before|after) hooks, starting from the first
|
||||
* hook
|
||||
* @param {TestContext} testContext - context containing hooks
|
||||
* @param {('before'|'after')} hookName - name of hooks to run callbacks for
|
||||
* @returns {Promise.<*>} Resolves when last hook in list has been executed
|
||||
* @private
|
||||
*/
|
||||
async _runContextHooks(testContext, hookName) {
|
||||
const hooks = testContext[`${hookName}Hooks`] || [];
|
||||
|
||||
return this._runHookChain(null, Date.now(), testContext, hookName, hooks);
|
||||
}
|
||||
|
||||
_runHookChain(test, testStart, testContext, hookName, hooks) {
|
||||
return Promise.each(hooks, async (hook) => {
|
||||
const error = await this._safelyRunFunction(hook.callback, hook.timeout, `${hookName} hook`);
|
||||
|
||||
if (error) {
|
||||
const errorPrefix = `Error occurred in "${testContext.name}" ${hookName} Hook: `;
|
||||
|
||||
if (test) {
|
||||
this._reportTestError(test, error, Date.now() - testStart, errorPrefix);
|
||||
} else {
|
||||
this._reportAllTestsAsFailed(testContext, error, testStart, errorPrefix);
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
}).then(() => true).catch(() => false);
|
||||
}
|
||||
|
||||
_reportAllTestsAsFailed(testContext, error, testStart, errorPrefix) {
|
||||
testContext.tests.forEach((test) => {
|
||||
this._reportTestError(test, error, Date.now() - testStart, errorPrefix);
|
||||
});
|
||||
|
||||
testContext.childContextIds.forEach((contextId) => {
|
||||
this._reportAllTestsAsFailed(this.testContext[contextId], error, testStart, errorPrefix);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously run a list of tests
|
||||
* @param {TestContext} testContext - Test context to run beforeEach and AfterEach hooks
|
||||
* for
|
||||
* @param {Test[]} tests - List of tests to run
|
||||
* @param {Function[]} beforeEachHooks - list of functions to run before each test
|
||||
* @param {Function[]} afterEachHooks - list of functions to run after each test
|
||||
* @returns {Promise.<void>} - Resolves once all tests and their afterEach hooks have
|
||||
* been run
|
||||
* @private
|
||||
*/
|
||||
async _runTests(testContext, tests, beforeEachHooks, afterEachHooks) {
|
||||
return Promise.each(tests, async (test) => {
|
||||
this._updateStatus(EVENTS.TEST_STATUS, {
|
||||
testId: test.id,
|
||||
status: RunStatus.RUNNING,
|
||||
time: 0,
|
||||
message: '',
|
||||
});
|
||||
|
||||
const testStart = Date.now();
|
||||
|
||||
const beforeEachRan = await this._runHookChain(test, testStart, testContext, 'beforeEach', beforeEachHooks);
|
||||
|
||||
if (beforeEachRan) {
|
||||
const error = await this._safelyRunFunction(test.func.bind(null, [test, this.testSuite.reduxStore.getState()]), test.timeout, 'Test');
|
||||
|
||||
// Update test status
|
||||
|
||||
if (error) {
|
||||
this._reportTestError(test, error, Date.now() - testStart);
|
||||
} else {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
test.status = RunStatus.OK;
|
||||
|
||||
this._updateStatus(EVENTS.TEST_STATUS, {
|
||||
testId: test.id,
|
||||
status: RunStatus.OK,
|
||||
time: Date.now() - testStart,
|
||||
message: '',
|
||||
});
|
||||
}
|
||||
|
||||
// Update suite progress
|
||||
|
||||
this.completedTests += 1;
|
||||
|
||||
this._updateStatus(EVENTS.TEST_SUITE_STATUS, {
|
||||
suiteId: this.testSuite.id,
|
||||
status: RunStatus.RUNNING,
|
||||
progress: (this.completedTests / this.tests.length) * 100,
|
||||
time: Date.now() - this.runStartTime,
|
||||
message: '',
|
||||
});
|
||||
|
||||
await this._runHookChain(test, testStart, testContext, 'afterEach', afterEachHooks);
|
||||
}
|
||||
})
|
||||
|
||||
.catch((error) => {
|
||||
this._updateStatus(EVENTS.TEST_SUITE_STATUS, {
|
||||
suiteId: this.testSuite.id,
|
||||
status: RunStatus.ERR,
|
||||
time: Date.now() - this.runStartTime,
|
||||
message: `Test suite failed: ${error.message}`,
|
||||
stackTrace: error.stack,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_reportTestError(test, error, time, errorPrefix = '') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
test.status = RunStatus.ERR;
|
||||
|
||||
this._updateStatus(EVENTS.TEST_STATUS, {
|
||||
testId: test.id,
|
||||
status: RunStatus.ERR,
|
||||
time,
|
||||
message: `${errorPrefix}${error.message ? `${error.name}: ${error.message}` : error}`,
|
||||
stackTrace: error.stack,
|
||||
});
|
||||
}
|
||||
|
||||
async _safelyRunFunction(func, timeOutDuration, description) {
|
||||
const syncResultOrPromise = tryCatcher(func);
|
||||
|
||||
if (syncResultOrPromise.error) {
|
||||
// Synchronous Error
|
||||
return syncResultOrPromise.error;
|
||||
}
|
||||
|
||||
// Asynchronous Error
|
||||
return promiseToCallBack(syncResultOrPromise.value, timeOutDuration, description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Try catch to object
|
||||
* @returns {{}}
|
||||
* @private
|
||||
*/
|
||||
|
||||
function tryCatcher(func) {
|
||||
const result = {};
|
||||
|
||||
try {
|
||||
result.value = func();
|
||||
} catch (e) {
|
||||
result.error = e;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a promise callback-able to trap errors
|
||||
* @param promise
|
||||
* @private
|
||||
*/
|
||||
|
||||
function promiseToCallBack(promise, timeoutDuration, description) {
|
||||
let returnValue = null;
|
||||
|
||||
try {
|
||||
returnValue = Promise.resolve(promise)
|
||||
.then(() => {
|
||||
return null;
|
||||
}, (error) => {
|
||||
return Promise.resolve(error);
|
||||
})
|
||||
.timeout(timeoutDuration, `${description} took longer than ${timeoutDuration}ms. This can be extended with the timeout option.`)
|
||||
.catch((error) => {
|
||||
return Promise.resolve(error);
|
||||
});
|
||||
} catch (error) {
|
||||
returnValue = Promise.resolve(error);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a two dimensional array to a single dimensional array
|
||||
* @param {*[]} list - two dimensional array
|
||||
* @returns {*[]} One-dimensional array
|
||||
*/
|
||||
function flatten(list) {
|
||||
return list.reduce((memo, contextHooks) => {
|
||||
return memo.concat(contextHooks);
|
||||
}, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a runtime error to the console
|
||||
* @param {String} error - Message to log to the console
|
||||
*/
|
||||
function testRuntimeError(error) {
|
||||
console.error(`ReactNativeFirebaseTests.TestRuntimeError: ${error}`);
|
||||
}
|
||||
|
||||
export default TestRun;
|
|
@ -0,0 +1,148 @@
|
|||
import 'should';
|
||||
import 'should-sinon';
|
||||
|
||||
import TestSuiteDefinition from './TestSuiteDefinition';
|
||||
import TestRun from './TestRun';
|
||||
|
||||
/**
|
||||
* Incrementing counter to assign each test suite a globally unique id. Should be
|
||||
* accessed only through assignTestSuiteId
|
||||
* @type {number} Counter that maintains globally unique id and increments each time
|
||||
* a new id is assigned
|
||||
*/
|
||||
let testSuiteCounter = 0;
|
||||
|
||||
/**
|
||||
* Increment the testSuiteCounter and return the new value. Used
|
||||
* for assigning a new globally unique id to a test suite.
|
||||
* @returns {number} globally unique id assigned to each test suite
|
||||
*/
|
||||
function assignTestSuiteId() {
|
||||
testSuiteCounter += 1;
|
||||
return testSuiteCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class that provides imperative interface for constructing and running a test suite.
|
||||
* Used for instantiating a new test suite, adding tests to it and then running all or
|
||||
* a subset of those tests.
|
||||
*
|
||||
* @example
|
||||
* // Creates a new test suite
|
||||
* const testSuit = new TestSuite('Feature Group A', 'Feature a, b and c');
|
||||
*/
|
||||
class TestSuite {
|
||||
/**
|
||||
* Creates a new test suite.
|
||||
* @param {String} name - The name of the test suite
|
||||
* @param {String} description - A short description of the test suite
|
||||
* @param {Object} firebase - Object containing native and web firebase instances
|
||||
* @param {Object} firebase.native - Native firebase instance
|
||||
* @para {Object} firebase.web - Web firebase instance
|
||||
*/
|
||||
constructor(name, description, firebase) {
|
||||
this.id = assignTestSuiteId();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
|
||||
this.reduxStore = null;
|
||||
this.testDefinitions = new TestSuiteDefinition(this, firebase);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Function} TestDefinitionFunction
|
||||
* @param {TestDSL} testDSL - class instance that defines the testing DSL that can
|
||||
* be used in defining tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds tests defined in a function to the test suite
|
||||
* @param {TestDefinitionFunction} testDefinition - A function that defines one or
|
||||
* more test suites using the test DSL.
|
||||
* @example
|
||||
* // Adding tests
|
||||
* const testDefinition = function({ describe, it }) {
|
||||
* describe('Some context', () => {
|
||||
* it('then does something', () => {
|
||||
* // Test assertions here
|
||||
* })
|
||||
* })
|
||||
* testSuite.addTests(testDefinition);
|
||||
*/
|
||||
addTests(testDefinition) {
|
||||
testDefinition(this.testDefinitions.DSL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} ReduxStore
|
||||
* @property {Function} getState - Returns the current state of the store
|
||||
* @property {Function} dispatch - Dispatches a new action to update to store
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets the redux store assigned to the test suite
|
||||
* @param {ReduxStore} store - The redux store to add to the test suite
|
||||
* @param {Function} testSuiteAction - Function that accepts an object of
|
||||
* event values and returns another that is suitable to dispatch to the
|
||||
* redux store. Responsible for handling events when the test suite's status
|
||||
* has changed.
|
||||
* @param {Function} testAction - Function that accepts an object of
|
||||
* event values and returns another that is suitable to dispatch to the
|
||||
* redux store. Responsible for handling events when a test's status
|
||||
* has changed.
|
||||
*/
|
||||
setStore(store, testSuiteAction, testAction) {
|
||||
this.reduxStore = store;
|
||||
this.suiteChangHandler = testSuiteAction;
|
||||
this.testChangHandler = testAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all the tests matching an array of ids. If the array is not provided, run all
|
||||
* test in the test suite.
|
||||
* @param {number[]=} testIds - array of ids for tests to run
|
||||
* @throws {RangeError} testIds must correspond with tests in the test suite
|
||||
* @example
|
||||
* // Running all tests in the test suite
|
||||
* testSuite.run();
|
||||
* @example
|
||||
* // Run only tests with id 1 and 2
|
||||
* testSuite.run([1, 2]);
|
||||
*/
|
||||
async run(testIds = undefined) {
|
||||
const testsToRun = (() => {
|
||||
if (testIds) {
|
||||
return testIds.map((id) => {
|
||||
const test = this.testDefinitions.tests[id];
|
||||
|
||||
if (!test) {
|
||||
throw new RangeError(`ReactNativeFirebaseTests.TestRunError: Test with id ${id} not found in test suite ${this.name}`);
|
||||
}
|
||||
|
||||
return test;
|
||||
});
|
||||
}
|
||||
|
||||
return Object.values(this.testDefinitions.tests);
|
||||
})();
|
||||
|
||||
const testRun = new TestRun(this, testsToRun.reverse(), this.testDefinitions);
|
||||
|
||||
testRun.onChange('TEST_SUITE_STATUS', (values) => {
|
||||
if (this.suiteChangHandler) {
|
||||
this.suiteChangHandler(values);
|
||||
}
|
||||
});
|
||||
|
||||
testRun.onChange('TEST_STATUS', (values) => {
|
||||
if (this.testChangHandler) {
|
||||
this.testChangHandler(values);
|
||||
}
|
||||
});
|
||||
|
||||
await testRun.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default TestSuite;
|
|
@ -0,0 +1,360 @@
|
|||
import TestDSL from './TestDSL';
|
||||
|
||||
/**
|
||||
* Incrementing counter to assign each test context a globally unique id.
|
||||
* @type {number} Counter that maintains globally unique id and increments each time
|
||||
* a new id is assigned
|
||||
*/
|
||||
let testContextCounter = 0;
|
||||
|
||||
/**
|
||||
* Incrementing counter to assign each test a globally unique id.
|
||||
* @type {number} Counter that maintains globally unique id and increments each time
|
||||
* a new id is assigned
|
||||
*/
|
||||
let testCounter = 0;
|
||||
|
||||
/**
|
||||
* Increment the testCounter and return the new value. Used
|
||||
* for assigning a new globally unique id to a test.
|
||||
* @returns {number} globally unique id assigned to each test
|
||||
*/
|
||||
function assignTestId() {
|
||||
testCounter += 1;
|
||||
return testCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the testContextCounter and return the new value. Used
|
||||
* for assigning a new globally unique id to a test context.
|
||||
* @returns {number} globally unique id assigned to each test context
|
||||
*/
|
||||
function assignContextId() {
|
||||
testContextCounter += 1;
|
||||
return testContextCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum for operators that can be used when combining test properties with their
|
||||
* parents at definition time.
|
||||
* @readonly
|
||||
* @enum {String} ContextOperator
|
||||
*/
|
||||
const CONTEXT_OPERATORS = {
|
||||
/** Perform OR of test value with context chain values **/
|
||||
OR: 'OR',
|
||||
};
|
||||
|
||||
/**
|
||||
* Class that provides imperative interface for defining tests. When defining tests
|
||||
* the declarative interface for this class, {@link TestDSL} should be use instead.
|
||||
*/
|
||||
class TestSuiteDefinition {
|
||||
/**
|
||||
* Creates a new TestSuiteDefinition
|
||||
* @param {TestSuite} testSuite - The {@link TestSuite} instance for which to
|
||||
* define tests for.
|
||||
* @param {Object} firebase - Object containing native and web firebase instances
|
||||
* @param {Object} firebase.native - Native firebase instance
|
||||
* @para {Object} firebase.web - Web firebase instance
|
||||
*/
|
||||
constructor(testSuite, firebase) {
|
||||
this.testSuite = testSuite;
|
||||
|
||||
this.tests = {};
|
||||
this.pendingTestIds = {};
|
||||
this.focusedTestIds = {};
|
||||
|
||||
this.testContexts = {};
|
||||
|
||||
this.rootTestContextId = assignContextId();
|
||||
this.rootTestContext = this._initialiseContext(this.rootTestContextId, {
|
||||
name: '',
|
||||
focus: false,
|
||||
pending: false,
|
||||
parentContextId: null,
|
||||
});
|
||||
|
||||
this.currentTestContext = this.rootTestContext;
|
||||
|
||||
this._testDSL = new TestDSL(this, firebase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance of {@link TestDSL} used for declaratively defining tests
|
||||
* @returns {TestDSL} The TestDSL used for defining tests
|
||||
*/
|
||||
get DSL() {
|
||||
return this._testDSL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a before hook to the current test context
|
||||
* @param {Function} callback - Function to add as before hook to current test context
|
||||
*/
|
||||
addBeforeHook(callback, options = {}) {
|
||||
this._addHook('before', callback, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a before each hook to the current test context
|
||||
* @param {Function} callback - Function to add as before each hook to current test
|
||||
* context
|
||||
*/
|
||||
addBeforeEachHook(callback, options = {}) {
|
||||
this._addHook('beforeEach', callback, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a after each hook to the current test context
|
||||
* @param {Function} callback - Function to add as after each hook to current test context
|
||||
*/
|
||||
addAfterEachHook(callback, options = {}) {
|
||||
this._addHook('afterEach', callback, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function as a after hook to the current test context
|
||||
* @param {Function} callback - Function to add as after hook to current test context
|
||||
*/
|
||||
addAfterHook(callback, options = {}) {
|
||||
this._addHook('after', callback, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function to the list of hooks matching hookName, for the current test context
|
||||
* @param {('before'|'beforeEach'|'afterEach'|'after')} hookName - The name of the hook to add the function to
|
||||
* @param {Function} callback - Function to add as a hook
|
||||
* @param {Object=} options - Hook configuration options
|
||||
* @private
|
||||
*/
|
||||
_addHook(hookName, callback, options = {}) {
|
||||
const hookAttribute = `${hookName}Hooks`;
|
||||
|
||||
if (callback && typeof callback === 'function') {
|
||||
this.currentTestContext[hookAttribute] = this.currentTestContext[hookAttribute] || [];
|
||||
this.currentTestContext[hookAttribute].push({
|
||||
callback,
|
||||
timeout: options.timeout || 5000,
|
||||
});
|
||||
} else {
|
||||
testDefinitionError(`non-function value ${callback} passed to ${hookName} for '${this.currentTestContext.name}'`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} ContextOptions
|
||||
* @property {Boolean} [focused=undefined] - whether context is focused or not.
|
||||
* @property {Boolean} [pending=undefined] - whether context is pending or not.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} TestOptions
|
||||
* @extends ContextOptions
|
||||
* @property {Number} [timeout=5000] - Number of milliseconds before test times out
|
||||
*/
|
||||
|
||||
/**
|
||||
* Push a test context onto the context stack, making it the new current test context
|
||||
* @param {String} name - The name of the new context
|
||||
* @param {ContextOptions} options - Options for new context
|
||||
*/
|
||||
pushTestContext(name, options = {}) {
|
||||
const testContextId = assignContextId();
|
||||
const parentContext = this.currentTestContext;
|
||||
this.currentTestContext = this._initialiseContext(testContextId, Object.assign({ name, parentContextId: parentContext.id }, options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop test context off the context stack, making the previous context the new
|
||||
* current context.
|
||||
*/
|
||||
popTestContext() {
|
||||
const parentContextId = this.currentTestContext.parentContextId;
|
||||
this.currentTestContext = this.testContexts[parentContextId];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a test to the current test context
|
||||
* @param {String} description - The new test's description
|
||||
* @param {ContextOptions} options - The options for the new test
|
||||
* @param {Function} testFunction - The function that comprises the test's body
|
||||
*/
|
||||
addTest(description, options, testFunction = undefined) {
|
||||
let _testFunction;
|
||||
let _options;
|
||||
|
||||
if (testFunction) {
|
||||
_testFunction = testFunction;
|
||||
_options = options;
|
||||
} else {
|
||||
_testFunction = options;
|
||||
_options = {};
|
||||
}
|
||||
|
||||
if (_testFunction && typeof _testFunction === 'function') {
|
||||
// Create test
|
||||
const testId = assignTestId();
|
||||
|
||||
this._createTest(testId, {
|
||||
testContextId: this.currentTestContext.id,
|
||||
testSuiteId: this.testSuite.id,
|
||||
description: this._testDescriptionContextPrefix(this.currentTestContext) + description,
|
||||
func: _testFunction,
|
||||
timeout: _options.timeout || 5000,
|
||||
});
|
||||
|
||||
// Add tests to context
|
||||
this.currentTestContext.testIds.push(testId);
|
||||
|
||||
if (_options.focus || this.currentTestContext.focus) {
|
||||
this.focusedTestIds[testId] = true;
|
||||
}
|
||||
|
||||
if (_options.pending || this.currentTestContext.pending) {
|
||||
this.pendingTestIds[testId] = true;
|
||||
}
|
||||
} else {
|
||||
testDefinitionError(`Invalid test function for "${description}".`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the prefix to prepend to a test to fully describe it. Any context that is
|
||||
* nested 2 or more deep, i.e. non the root context nor a child of the root context,
|
||||
* has its name recursively prepended to all tests in that context or contexts it
|
||||
* contains. This allows tests to be easily displayed in a LinkedList during viewing
|
||||
* and reporting the test suite.
|
||||
* @param {Object} contextProperties - Properties of current context
|
||||
* @param {Number} contextProperties.id - Id of context
|
||||
* @param {String} contextProperties.name - Name of context
|
||||
* @param {Number} contextProperties.parentContextId - Id of context's parent
|
||||
* @param {String} [suffix=''] - Accumulation of context prefixes so far. Starts empty
|
||||
* and collects context prefixes as it recursively calls itself to iterate up the
|
||||
* context tree.
|
||||
* @returns {String} Prefix to be prepended to current accumulative string of context
|
||||
* names
|
||||
* @private
|
||||
*/
|
||||
_testDescriptionContextPrefix({ id, name, parentContextId }, suffix = '') {
|
||||
if (id === this.rootTestContextId || parentContextId === this.rootTestContextId) {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
return this._testDescriptionContextPrefix(this.testContexts[parentContextId], `${name} ${suffix}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} TestContext
|
||||
* @property {Number} id - Globally unique id
|
||||
* @property {String} name - Short description of context
|
||||
* @property {Boolean} [focus=false] - Whether context is focused
|
||||
* @property {Boolean} [pending=false] - Whether context is pending
|
||||
* @property {Number} [parentContextId=undefined] - Id of context that contains the current one
|
||||
* @property {Number[]} testIds - List of ids of tests to be run in current context
|
||||
* @property {Number} testSuiteId - Id of test suite test context is apart of
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a context from options provided
|
||||
* @param {Number} testContextId - Id to assign to new context once it's created
|
||||
* @param {Object} options - options to use to create the context
|
||||
* @param {String} options.name - Name of context to create
|
||||
* @param {Boolean} options.focus - Whether context is focused or not
|
||||
* @param {Boolean} options.pending - Whether context is pending or not
|
||||
* @param {Number} [options.parentContextId=undefined] - Id of context's parent
|
||||
* @returns {TestContext} New test context once it has been initialised
|
||||
* @private
|
||||
*/
|
||||
_initialiseContext(testContextId, { name, focus, pending, parentContextId }) {
|
||||
const existingContext = this.testContexts[testContextId];
|
||||
|
||||
if (existingContext) {
|
||||
return existingContext;
|
||||
}
|
||||
|
||||
const parentContext = this.testContexts[parentContextId];
|
||||
|
||||
const newTestContext = {
|
||||
id: testContextId,
|
||||
name,
|
||||
focus: this._incorporateParentValue(parentContext, 'focus', focus, CONTEXT_OPERATORS.OR),
|
||||
pending: this._incorporateParentValue(parentContext, 'pending', pending, CONTEXT_OPERATORS.OR),
|
||||
parentContextId,
|
||||
testIds: [],
|
||||
testSuiteId: this.testSuite.id,
|
||||
};
|
||||
|
||||
this.testContexts[testContextId] = newTestContext;
|
||||
|
||||
return newTestContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively use an operator to consolidate a test's value with that of its test
|
||||
* context chain.
|
||||
* @param {TestContext} parentContext - Parent context to examine for its value
|
||||
* @param {String} attributeName - name of the attribute to use from parent
|
||||
* @param {*} value - Value of current context or test to use as one operand with
|
||||
* the parent context's value
|
||||
* @param {('OR')} operator - Operator to use to consolidate current value and
|
||||
* parent context's value
|
||||
* @returns {*} Consolidated value, encorporating context parents' values
|
||||
* @private
|
||||
*/
|
||||
_incorporateParentValue(parentContext, attributeName, value, operator) {
|
||||
if (!parentContext) {
|
||||
return value;
|
||||
}
|
||||
|
||||
switch (operator) {
|
||||
case CONTEXT_OPERATORS.OR:
|
||||
return parentContext[attributeName] || value;
|
||||
default:
|
||||
throw new Error(`Unknown context operator ${operator}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new test from the options provided and add it to the suite
|
||||
* @param {Number} testId - Unique id to give to the test
|
||||
* @param {Object} testAttributes - attributes to create the test with
|
||||
* @param {Number} testAttributes.testContextId - Id of context test belongs to
|
||||
* @param {String} testAttributes.description - Short description of the test
|
||||
* @param {Function} testAttributes.func - Function that comprises the body of the test
|
||||
* @param {Number} testAttributes.testSuiteId - Id of test suite test belongs to
|
||||
* @param {Number} testAttributes.timeout - Number of milliseconds before test times out
|
||||
* @returns {Test} New test matching provided options
|
||||
* @private
|
||||
*/
|
||||
_createTest(testId, { testContextId, description, func, testSuiteId, timeout }) {
|
||||
const newTest = {
|
||||
id: testId,
|
||||
testContextId,
|
||||
description,
|
||||
func,
|
||||
testSuiteId,
|
||||
status: null,
|
||||
message: null,
|
||||
time: 0,
|
||||
timeout,
|
||||
};
|
||||
|
||||
this.tests[testId] = newTest;
|
||||
|
||||
return newTest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Log test definition error to the console with a message indicating the test
|
||||
* definition was skipped.
|
||||
* @param {String} error - Error message to include in message logged to the console
|
||||
*/
|
||||
function testDefinitionError(error) {
|
||||
console.error(`ReactNativeFirebaseTests.TestDefinitionError: ${error}`);
|
||||
console.error('This test was ignored.');
|
||||
}
|
||||
|
||||
export default TestSuiteDefinition;
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"name": "react-native-firebase-tests",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "node node_modules/react-native/local-cli/cli.js start",
|
||||
"android:dev": "react-native run-android",
|
||||
"android:prod": "react-native run-android --configuration=release",
|
||||
"ios:dev": "react-native run-ios",
|
||||
"ios:prod": "react-native run-ios --configuration=release",
|
||||
"ios:pod:install": "cd ios && rm -rf ReactNativeFirebaseDemo.xcworkspace && pod install && cd ..",
|
||||
"test": "echo 'Tests should be run from within the RN application.\n\rSee https://github.com/invertase/react-native-firebase-tests/blob/master/tests/README.md for more info.'",
|
||||
"build-lib-for-tests": "babel --presets=es2015-mod,es3,react-native ./lib/ -d ./__tests__/build/lib/ --source-maps",
|
||||
"internal-tests": "npm run build-lib-for-tests && babel --presets=es2015-mod,es3 ./__tests__/src/ -d ./__tests__/build/ --source-maps && node ./__tests__/build/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/invertase/react-native-firebase.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/invertase/react-native-firebase/issues"
|
||||
},
|
||||
"homepage": "https://github.com/invertase/react-native-firebase/tests/#readme",
|
||||
"dependencies": {
|
||||
"babel-preset-es2015-mod": "^6.6.0",
|
||||
"babel-preset-es3": "^1.0.1",
|
||||
"bluebird": "^3.5.0",
|
||||
"bows": "^1.6.0",
|
||||
"cuid": "^1.3.8",
|
||||
"deeps": "^1.4.4",
|
||||
"firebase": "^3.7.0",
|
||||
"js-beautify": "^1.6.11",
|
||||
"lodash.groupby": "^4.6.0",
|
||||
"lodash.some": "^4.6.0",
|
||||
"react": "~15.4.1",
|
||||
"react-native": "0.40.0",
|
||||
"react-native-firebase": "file:..",
|
||||
"react-native-simple-toast": "0.0.5",
|
||||
"react-native-vector-icons": "^4.0.0",
|
||||
"react-navigation": "^1.0.0-beta.7",
|
||||
"react-redux": "^5.0.3",
|
||||
"redux": "^3.6.0",
|
||||
"redux-logger": "^2.8.2",
|
||||
"redux-persist": "^4.4.2",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"should": "^11.2.0",
|
||||
"should-sinon": "^0.0.5",
|
||||
"sinon": "https://github.com/greena13/sinon.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.24.0",
|
||||
"babel-eslint": "^7.1.1",
|
||||
"babel-jest": "19.0.0",
|
||||
"babel-plugin-flow-react-proptypes": "^0.21.0",
|
||||
"babel-preset-react-native": "1.9.1",
|
||||
"colors": "^1.1.2",
|
||||
"eslint": "^3.16.1",
|
||||
"eslint-config-airbnb": "^14.1.0",
|
||||
"eslint-plugin-flowtype": "^2.30.0",
|
||||
"eslint-plugin-import": "^2.2.0",
|
||||
"eslint-plugin-jsx-a11y": "^4.0.0",
|
||||
"eslint-plugin-react": "^6.10.0",
|
||||
"jest": "19.0.2",
|
||||
"react-test-renderer": "~15.4.1",
|
||||
"redux-immutable-state-invariant": "^1.2.4"
|
||||
},
|
||||
"jest": {
|
||||
"preset": "react-native"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
export const APP_SET_NETWORK_STATE: string = 'APP_SET_NETWORK_STATE';
|
||||
export const APP_SET_APP_STATE: string = 'APP_SET_APP_STATE';
|
||||
|
||||
export function setNetworkState(isConnected: boolean): Object {
|
||||
return {
|
||||
type: APP_SET_NETWORK_STATE,
|
||||
isConnected,
|
||||
};
|
||||
}
|
||||
|
||||
export function setAppState(appState: 'active' | 'background' | 'inactive'): Object {
|
||||
return {
|
||||
type: APP_SET_APP_STATE,
|
||||
appState,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
export const FCM_SET_TOKEN: string = 'FCM_SET_TOKEN';
|
||||
|
||||
export function setToken(token: string): Object {
|
||||
return {
|
||||
type: FCM_SET_TOKEN,
|
||||
token,
|
||||
};
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
export const TEST_SET_SUITE_STATUS: string = 'TEST_SET_SUITE_STATUS';
|
||||
export const TEST_SET_STATUS: string = 'TEST_SET_STATUS';
|
||||
|
||||
export function setSuiteStatus({ suiteId, status, time, message, progress }) {
|
||||
return {
|
||||
type: TEST_SET_SUITE_STATUS,
|
||||
suiteId,
|
||||
|
||||
status,
|
||||
message,
|
||||
|
||||
time,
|
||||
progress,
|
||||
};
|
||||
}
|
||||
|
||||
export function setTestStatus({ testId, status, time = 0, message = null }) {
|
||||
return {
|
||||
type: TEST_SET_STATUS,
|
||||
testId,
|
||||
|
||||
status,
|
||||
message,
|
||||
time,
|
||||
};
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
import React from 'react';
|
||||
import { StyleSheet, View, Text } from 'react-native';
|
||||
|
||||
function Banner({ type, children, style, textStyle }) {
|
||||
return (
|
||||
<View style={[styles.banner, styles[type || 'default'], style]}>
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
style={[styles.bannerText, textStyle]}
|
||||
>
|
||||
{children}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Banner.propTypes = {
|
||||
type: React.PropTypes.oneOf([
|
||||
'success',
|
||||
'warning',
|
||||
'error',
|
||||
'info',
|
||||
]),
|
||||
children: React.PropTypes.oneOfType([
|
||||
React.PropTypes.string,
|
||||
React.PropTypes.array,
|
||||
]).isRequired,
|
||||
style: View.propTypes.style,
|
||||
textStyle: Text.propTypes.style,
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
banner: {
|
||||
alignItems: 'center',
|
||||
elevation: 3,
|
||||
},
|
||||
bannerText: {
|
||||
color: '#ffffff',
|
||||
},
|
||||
warning: {
|
||||
backgroundColor: '#FFC107',
|
||||
},
|
||||
error: {
|
||||
backgroundColor: '#f44336',
|
||||
},
|
||||
success: {
|
||||
backgroundColor: '#4CAF50',
|
||||
},
|
||||
});
|
||||
|
||||
export default Banner;
|
|
@ -0,0 +1,75 @@
|
|||
import React from 'react';
|
||||
import { View, TouchableHighlight } from 'react-native';
|
||||
import VectorIcon from 'react-native-vector-icons/MaterialIcons';
|
||||
|
||||
type Props = {
|
||||
name: string,
|
||||
size?: number,
|
||||
color?: string,
|
||||
allowFontScaling?: boolean,
|
||||
style?: Object,
|
||||
rotate?: number,
|
||||
onPress?: () => void,
|
||||
underlayColor?: string,
|
||||
};
|
||||
|
||||
// TODO Spin?
|
||||
class Icon extends React.Component {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.measured = false;
|
||||
this.state = {
|
||||
width: 0,
|
||||
};
|
||||
}
|
||||
|
||||
setDimensions(e) {
|
||||
if (!this.measured) {
|
||||
this.measured = true;
|
||||
this.setState({
|
||||
width: e.nativeEvent.layout.width,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
props: Props;
|
||||
|
||||
render() {
|
||||
const { name, size = 24, color = '#757575', allowFontScaling = true, style, rotate, onPress, underlayColor } = this.props;
|
||||
|
||||
const icon = (
|
||||
<View
|
||||
onLayout={(e) => this.setDimensions(e)}
|
||||
style={[
|
||||
style,
|
||||
rotate ? { transform: [{ rotate: `${rotate}deg` }] } : null,
|
||||
]}
|
||||
>
|
||||
<VectorIcon
|
||||
name={name.toLowerCase().replace(/\s+/g, '-')}
|
||||
size={size}
|
||||
color={color}
|
||||
allowFontScaling={allowFontScaling}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
|
||||
if (!onPress) {
|
||||
return icon;
|
||||
}
|
||||
|
||||
return (
|
||||
<TouchableHighlight
|
||||
underlayColor={underlayColor || 'rgba(0, 0, 0, 0.054)'}
|
||||
onPress={onPress}
|
||||
style={{ padding: 8, borderRadius: (this.state.width + 8) / 2 }}
|
||||
>
|
||||
{icon}
|
||||
</TouchableHighlight>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default Icon;
|
|
@ -0,0 +1,70 @@
|
|||
import React, { PropTypes, Component } from 'react';
|
||||
import some from 'lodash.some';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import Toast from 'react-native-simple-toast';
|
||||
|
||||
import { runTests } from '../tests/index';
|
||||
import RunStatus from '../../lib/RunStatus';
|
||||
|
||||
import Icon from '../components/Icon';
|
||||
|
||||
class OverviewControlButton extends Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.handleOnPress = this.handleOnPress.bind(this);
|
||||
}
|
||||
|
||||
testSuitesAreRunning() {
|
||||
const { testSuites } = this.props;
|
||||
|
||||
return some(Object.values(testSuites), ({ status }) => status === RunStatus.RUNNING);
|
||||
}
|
||||
|
||||
handleOnPress() {
|
||||
const { focusedTestIds, pendingTestIds, tests } = this.props;
|
||||
runTests(tests, { focusedTestIds, pendingTestIds });
|
||||
Toast.show('Running all suite tests.');
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.testSuitesAreRunning()) {
|
||||
return (
|
||||
<Icon
|
||||
color={'#ffffff'}
|
||||
size={28}
|
||||
name="autorenew"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Icon
|
||||
color={'#ffffff'}
|
||||
size={28}
|
||||
name="play circle filled"
|
||||
onPress={this.handleOnPress}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
OverviewControlButton.propTypes = {
|
||||
tests: PropTypes.objectOf(PropTypes.object).isRequired,
|
||||
testSuites: PropTypes.objectOf(PropTypes.object).isRequired,
|
||||
focusedTestIds: PropTypes.objectOf(PropTypes.bool).isRequired,
|
||||
pendingTestIds: PropTypes.objectOf(PropTypes.bool).isRequired,
|
||||
};
|
||||
|
||||
|
||||
function mapStateToProps({ tests, testSuites, focusedTestIds, pendingTestIds }) {
|
||||
return {
|
||||
tests,
|
||||
testSuites,
|
||||
focusedTestIds,
|
||||
pendingTestIds,
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(OverviewControlButton);
|
|
@ -0,0 +1,52 @@
|
|||
import { View, Text } from 'react-native';
|
||||
import React, { PropTypes, Component } from 'react';
|
||||
|
||||
import RunStatus from '../../lib/RunStatus';
|
||||
import Icon from './Icon';
|
||||
|
||||
class StatusIndicator extends Component {
|
||||
|
||||
render() {
|
||||
const { status, progress } = this.props;
|
||||
|
||||
switch (status) {
|
||||
case RunStatus.RUNNING:
|
||||
if (progress > 0) {
|
||||
return (
|
||||
<View style={{ width: 30, flex: 1, justifyContent: 'flex-end' }}>
|
||||
<Text style={{ fontSize: 11, marginBottom: 20 }}>
|
||||
{progress.toFixed(0)}%
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Icon color={'rgba(0, 0, 0, 0.2)'} name="autorenew" />
|
||||
);
|
||||
case RunStatus.OK:
|
||||
return (
|
||||
<Icon name={'done'} />
|
||||
);
|
||||
case RunStatus.ERR:
|
||||
return (
|
||||
<Icon color={'#f44336'} name="clear" />
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
StatusIndicator.propTypes = {
|
||||
status: PropTypes.oneOf(Object.values(RunStatus)),
|
||||
progress: PropTypes.number,
|
||||
};
|
||||
|
||||
StatusIndicator.defaultProps = {
|
||||
status: null,
|
||||
progress: 0
|
||||
};
|
||||
|
||||
module.exports = StatusIndicator;
|
|
@ -0,0 +1,71 @@
|
|||
import React, { PropTypes, Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import Toast from 'react-native-simple-toast';
|
||||
|
||||
import RunStatus from '../../lib/RunStatus';
|
||||
import { runTest } from '../tests/index';
|
||||
|
||||
import Icon from './Icon';
|
||||
|
||||
class TestControlButton extends Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.handleOnPress = this.handleOnPress.bind(this);
|
||||
}
|
||||
|
||||
testIsPending() {
|
||||
const { test: { id }, pendingTestIds } = this.props;
|
||||
return !!pendingTestIds[id];
|
||||
}
|
||||
|
||||
handleOnPress() {
|
||||
const { test: { id, description } } = this.props;
|
||||
|
||||
runTest(id);
|
||||
Toast.show(`Running ${description}.`);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { test: { status } } = this.props;
|
||||
|
||||
if (status !== RunStatus.STARTED && !this.testIsPending()) {
|
||||
return (
|
||||
<Icon
|
||||
color={'#ffffff'}
|
||||
size={28}
|
||||
name="play circle filled"
|
||||
onPress={this.handleOnPress}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TestControlButton.propTypes = {
|
||||
test: PropTypes.shape({
|
||||
id: PropTypes.number.isRequired,
|
||||
status: PropTypes.string,
|
||||
description: PropTypes.string.isRequired,
|
||||
}).isRequired,
|
||||
|
||||
pendingTestIds: PropTypes.objectOf(PropTypes.bool).isRequired,
|
||||
};
|
||||
|
||||
TestControlButton.defaultProps = {
|
||||
|
||||
};
|
||||
|
||||
function mapStateToProps({ tests, pendingTestIds }, { testId }) {
|
||||
const test = tests[testId];
|
||||
|
||||
return {
|
||||
test,
|
||||
pendingTestIds,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = connect(mapStateToProps)(TestControlButton);
|
|
@ -0,0 +1,96 @@
|
|||
import React, { PropTypes, Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import Toast from 'react-native-simple-toast';
|
||||
|
||||
import RunStatus from '../../lib/RunStatus';
|
||||
import { runTests } from '../tests/index';
|
||||
|
||||
import Icon from './Icon';
|
||||
|
||||
class TestSuiteControlButton extends Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
|
||||
this.toggleOnlyShowFailingTests = this.toggleOnlyShowFailingTests.bind(this);
|
||||
this.startTestSuite = this.startTestSuite.bind(this);
|
||||
}
|
||||
|
||||
startTestSuite() {
|
||||
const { testSuite: { name, testIds }, tests, focusedTestIds, pendingTestIds } = this.props;
|
||||
|
||||
const testSuiteTests = testIds.reduce((memo, testId) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
memo[testId] = tests[testId];
|
||||
return memo;
|
||||
}, {});
|
||||
|
||||
runTests(testSuiteTests, { focusedTestIds, pendingTestIds });
|
||||
|
||||
Toast.show(`Running ${name} tests.`);
|
||||
}
|
||||
|
||||
toggleOnlyShowFailingTests() {
|
||||
const { onlyShowFailingTests, onFilterChange } = this.props;
|
||||
onFilterChange({ onlyShowFailingTests: !onlyShowFailingTests });
|
||||
}
|
||||
|
||||
render() {
|
||||
const { testSuite: { status }, onlyShowFailingTests } = this.props;
|
||||
|
||||
if (status === RunStatus.ERR) {
|
||||
return (
|
||||
<Icon
|
||||
color={onlyShowFailingTests ? '#ffffff' : 'rgba(255, 255, 255, 0.54)'}
|
||||
size={28}
|
||||
name="error outline"
|
||||
onPress={this.toggleOnlyShowFailingTests}
|
||||
/>
|
||||
);
|
||||
} else if (status !== RunStatus.RUNNING) {
|
||||
return (
|
||||
<Icon
|
||||
color={'#ffffff'}
|
||||
size={28}
|
||||
name="play circle filled"
|
||||
onPress={this.startTestSuite}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TestSuiteControlButton.propTypes = {
|
||||
testSuite: PropTypes.shape({
|
||||
status: PropTypes.oneOf(Object.values(RunStatus)),
|
||||
}).isRequired,
|
||||
|
||||
tests: PropTypes.objectOf(PropTypes.object).isRequired,
|
||||
focusedTestIds: PropTypes.objectOf(PropTypes.bool).isRequired,
|
||||
pendingTestIds: PropTypes.objectOf(PropTypes.bool).isRequired,
|
||||
|
||||
onlyShowFailingTests: PropTypes.bool,
|
||||
|
||||
onFilterChange: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
TestSuiteControlButton.defaultProps = {
|
||||
onlyShowFailingTests: false,
|
||||
};
|
||||
|
||||
|
||||
function mapStateToProps({ tests, testSuites, focusedTestIds, pendingTestIds }, { testSuiteId }) {
|
||||
const testSuite = testSuites[testSuiteId];
|
||||
|
||||
return {
|
||||
tests,
|
||||
testSuite,
|
||||
focusedTestIds,
|
||||
pendingTestIds,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = connect(mapStateToProps)(TestSuiteControlButton);
|
|
@ -0,0 +1,82 @@
|
|||
// @flow
|
||||
import React from 'react';
|
||||
import { View, Text, AppState, NetInfo, StatusBar, Platform } from 'react-native';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import Navigator from '../navigator';
|
||||
import { setNetworkState, setAppState } from '../actions/AppActions';
|
||||
|
||||
type Props = {
|
||||
dispatch: () => void,
|
||||
};
|
||||
|
||||
class CoreContainer extends React.Component {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._isConnected = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* On app mount, listen for changes to app & network state
|
||||
*/
|
||||
componentDidMount() {
|
||||
if (Platform.OS === 'android') {
|
||||
StatusBar.setBackgroundColor('#0279ba');
|
||||
}
|
||||
if (Platform.OS === 'ios') {
|
||||
StatusBar.setBarStyle('light-content')
|
||||
}
|
||||
AppState.addEventListener('change', this.handleAppStateChange);
|
||||
NetInfo.isConnected.fetch().then((isConnected) => {
|
||||
this.handleAppStateChange('active'); // Force connect (react debugger issue)
|
||||
this.props.dispatch(setNetworkState(isConnected));
|
||||
NetInfo.isConnected.addEventListener('change', this.handleNetworkChange);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove listeners on app unmount
|
||||
*/
|
||||
componentWillUnmount() {
|
||||
AppState.removeEventListener('change', this.handleAppStateChange);
|
||||
NetInfo.isConnected.removeEventListener('change', this.handleNetworkChange);
|
||||
}
|
||||
|
||||
props: Props;
|
||||
|
||||
/**
|
||||
* Handle app state changes
|
||||
* https://facebook.github.io/react-native/docs/appstate.html
|
||||
* @param state
|
||||
*/
|
||||
handleAppStateChange = (state) => {
|
||||
this.props.dispatch(setAppState(state));
|
||||
if (state === 'active' && this._isConnected) {
|
||||
// firestack.database().goOnline();
|
||||
} else if (state === 'background') {
|
||||
// firestack.database().goOffline();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle app network changes
|
||||
* https://facebook.github.io/react-native/docs/netinfo.html
|
||||
* @param isConnected
|
||||
*/
|
||||
handleNetworkChange = (isConnected) => {
|
||||
this._isConnected = isConnected;
|
||||
this.props.dispatch(setNetworkState(isConnected));
|
||||
if (isConnected) {
|
||||
// firestack.database().goOnline();
|
||||
} else {
|
||||
// firestack.database().goOffline();
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return <Navigator />;
|
||||
}
|
||||
}
|
||||
|
||||
export default connect()(CoreContainer);
|