[tests] new test infra - coverage for days
This commit is contained in:
parent
8c4a0261cd
commit
2fa3ee006d
|
@ -6,8 +6,10 @@
|
|||
"development": {
|
||||
"plugins": [
|
||||
["istanbul", {
|
||||
"useInlineSourceMaps": true,
|
||||
"instrument": true,
|
||||
"include": [
|
||||
"**/firebase/**.js"
|
||||
"firebase"
|
||||
]
|
||||
}]
|
||||
]
|
||||
|
|
|
@ -16,28 +16,25 @@ module.exports = {
|
|||
if (global.bridge.beforeContextReset) {
|
||||
await global.bridge.beforeContextReset();
|
||||
}
|
||||
try {
|
||||
for (const name in global.bridge.context.__fbBatchedBridge) {
|
||||
global.bridge.context.__fbBatchedBridge[name] = undefined;
|
||||
delete global.bridge.context.__fbBatchedBridge[name];
|
||||
}
|
||||
|
||||
for (const name in global.bridge.context.__fbGenNativeModule) {
|
||||
global.bridge.context.__fbGenNativeModule[name] = undefined;
|
||||
delete global.bridge.context.__fbGenNativeModule[name];
|
||||
}
|
||||
for (const name in global.bridge.context.__fbBatchedBridge) {
|
||||
global.bridge.context.__fbBatchedBridge[name] = undefined;
|
||||
delete global.bridge.context.__fbBatchedBridge[name];
|
||||
}
|
||||
|
||||
for (const name in global.bridge.context.__fbBatchedBridgeConfig) {
|
||||
global.bridge.context.__fbBatchedBridgeConfig[name] = undefined;
|
||||
delete global.bridge.context.__fbBatchedBridgeConfig[name];
|
||||
}
|
||||
for (const name in global.bridge.context.__fbGenNativeModule) {
|
||||
global.bridge.context.__fbGenNativeModule[name] = undefined;
|
||||
delete global.bridge.context.__fbGenNativeModule[name];
|
||||
}
|
||||
|
||||
for (const name in global.bridge.context) {
|
||||
global.bridge.context[name] = undefined;
|
||||
delete global.bridge.context[name];
|
||||
}
|
||||
} catch (e) {
|
||||
// do nothing;
|
||||
for (const name in global.bridge.context.__fbBatchedBridgeConfig) {
|
||||
global.bridge.context.__fbBatchedBridgeConfig[name] = undefined;
|
||||
delete global.bridge.context.__fbBatchedBridgeConfig[name];
|
||||
}
|
||||
|
||||
for (const name in global.bridge.context) {
|
||||
global.bridge.context[name] = undefined;
|
||||
delete global.bridge.context[name];
|
||||
}
|
||||
|
||||
global.bridge.context = undefined;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
const { createCoverageMap } = require('istanbul-lib-coverage');
|
||||
|
||||
const rootMap = createCoverageMap({});
|
||||
|
||||
module.exports = {
|
||||
collect() {
|
||||
if (bridge.context && bridge.context.__coverage__) {
|
||||
rootMap.merge(Object.assign({}, bridge.context.__coverage__));
|
||||
global.__coverage__ = rootMap.toJSON();
|
||||
}
|
||||
},
|
||||
summary() {
|
||||
return rootMap.getCoverageSummary();
|
||||
},
|
||||
|
||||
json() {
|
||||
return rootMap.toJSON();
|
||||
},
|
||||
};
|
|
@ -4,6 +4,7 @@ global.bridge = {};
|
|||
const detox = require('detox');
|
||||
const ws = require('./ws');
|
||||
const ready = require('./ready');
|
||||
const coverage = require('./coverage');
|
||||
|
||||
/* ---------------------
|
||||
* DEVICE OVERRIDES
|
||||
|
@ -54,6 +55,17 @@ detox.init = async (...args) => {
|
|||
// detox.cleanup()
|
||||
const detoxOriginalCleanup = detox.cleanup.bind(detox);
|
||||
detox.cleanup = async (...args) => {
|
||||
ws.close();
|
||||
try {
|
||||
ws.close();
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
await detoxOriginalCleanup(...args);
|
||||
};
|
||||
|
||||
// setup after hook to ensure final context coverage is captured
|
||||
process.nextTick(() => {
|
||||
after(() => {
|
||||
coverage.collect();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@ const chalk = require('chalk');
|
|||
const invariant = require('assert');
|
||||
const { Script } = require('vm');
|
||||
const context = require('./context');
|
||||
const coverage = require('./coverage');
|
||||
|
||||
let send;
|
||||
let bundle;
|
||||
|
@ -72,6 +73,7 @@ module.exports = {
|
|||
// console.log(request.method);
|
||||
switch (method) {
|
||||
case PREPARE:
|
||||
coverage.collect();
|
||||
await context.cleanup();
|
||||
context.create();
|
||||
reply(request.id);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
describe('.auth()', () => {
|
||||
beforeEach(async function beforeEach() {
|
||||
beforeEach(async () => {
|
||||
await device.reloadReactNative();
|
||||
// just an example of setting the root components state from inside a test :)
|
||||
bridge.root.setState({ message: this.currentTest.title });
|
||||
// bridge.root.setState({ message: this.currentTest.title });
|
||||
});
|
||||
|
||||
describe('.signInAnonymously()', () => {
|
||||
|
@ -15,12 +14,12 @@ describe('.auth()', () => {
|
|||
currentUser.isAnonymous.should.equal(true);
|
||||
currentUser.providerId.should.equal('firebase');
|
||||
|
||||
currentUser.should.equal(bridge.module.auth().currentUser);
|
||||
currentUser.should.equal(firebase.auth().currentUser);
|
||||
|
||||
return bridge.module.auth().signOut();
|
||||
return firebase.auth().signOut();
|
||||
};
|
||||
|
||||
return bridge.module
|
||||
return firebase
|
||||
.auth()
|
||||
.signInAnonymously()
|
||||
.then(successCb);
|
||||
|
@ -37,15 +36,15 @@ describe('.auth()', () => {
|
|||
should.equal(currentUser.toJSON().email, null);
|
||||
currentUser.isAnonymous.should.equal(true);
|
||||
currentUser.providerId.should.equal('firebase');
|
||||
currentUser.should.equal(bridge.module.auth().currentUser);
|
||||
currentUser.should.equal(firebase.auth().currentUser);
|
||||
|
||||
const { additionalUserInfo } = currentUserCredential;
|
||||
additionalUserInfo.should.be.an.Object();
|
||||
|
||||
return bridge.module.auth().signOut();
|
||||
return firebase.auth().signOut();
|
||||
};
|
||||
|
||||
return bridge.module
|
||||
return firebase
|
||||
.auth()
|
||||
.signInAnonymouslyAndRetrieveData()
|
||||
.then(successCb);
|
||||
|
@ -64,12 +63,12 @@ describe('.auth()', () => {
|
|||
currentUser.toJSON().email.should.eql('test@test.com');
|
||||
currentUser.isAnonymous.should.equal(false);
|
||||
currentUser.providerId.should.equal('firebase');
|
||||
currentUser.should.equal(bridge.module.auth().currentUser);
|
||||
currentUser.should.equal(firebase.auth().currentUser);
|
||||
|
||||
return bridge.module.auth().signOut();
|
||||
return firebase.auth().signOut();
|
||||
};
|
||||
|
||||
return bridge.module
|
||||
return firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(email, pass)
|
||||
.then(successCb);
|
||||
|
@ -89,7 +88,7 @@ describe('.auth()', () => {
|
|||
return Promise.resolve();
|
||||
};
|
||||
|
||||
return bridge.module
|
||||
return firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(email, pass)
|
||||
.then(successCb)
|
||||
|
@ -110,7 +109,7 @@ describe('.auth()', () => {
|
|||
return Promise.resolve();
|
||||
};
|
||||
|
||||
return bridge.module
|
||||
return firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(email, pass)
|
||||
.then(successCb)
|
||||
|
@ -131,7 +130,7 @@ describe('.auth()', () => {
|
|||
return Promise.resolve();
|
||||
};
|
||||
|
||||
return bridge.module
|
||||
return firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(email, pass)
|
||||
.then(successCb)
|
||||
|
@ -141,25 +140,25 @@ describe('.auth()', () => {
|
|||
|
||||
describe('.onAuthStateChanged()', () => {
|
||||
it('calls callback with the current user and when auth state changes', async () => {
|
||||
await bridge.module.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
|
||||
// Test
|
||||
const callback = sinon.spy();
|
||||
|
||||
let unsubscribe;
|
||||
await new Promise(resolve => {
|
||||
unsubscribe = bridge.module.auth().onAuthStateChanged(user => {
|
||||
unsubscribe = firebase.auth().onAuthStateChanged(user => {
|
||||
callback(user);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
callback.should.be.calledWith(bridge.module.auth().currentUser);
|
||||
callback.should.be.calledWith(firebase.auth().currentUser);
|
||||
callback.should.be.calledOnce();
|
||||
|
||||
// Sign out
|
||||
|
||||
await bridge.module.auth().signOut();
|
||||
await firebase.auth().signOut();
|
||||
|
||||
await new Promise(resolve => {
|
||||
setTimeout(() => resolve(), 100);
|
||||
|
@ -176,25 +175,25 @@ describe('.auth()', () => {
|
|||
});
|
||||
|
||||
it('stops listening when unsubscribe called', async () => {
|
||||
await bridge.module.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
|
||||
// Test
|
||||
const callback = sinon.spy();
|
||||
|
||||
let unsubscribe;
|
||||
await new Promise(resolve => {
|
||||
unsubscribe = bridge.module.auth().onAuthStateChanged(user => {
|
||||
unsubscribe = firebase.auth().onAuthStateChanged(user => {
|
||||
callback(user);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
callback.should.be.calledWith(bridge.module.auth().currentUser);
|
||||
callback.should.be.calledWith(firebase.auth().currentUser);
|
||||
callback.should.be.calledOnce();
|
||||
|
||||
// Sign out
|
||||
|
||||
await bridge.module.auth().signOut();
|
||||
await firebase.auth().signOut();
|
||||
|
||||
await new Promise(resolve => {
|
||||
setTimeout(() => resolve(), 100);
|
||||
|
@ -211,7 +210,7 @@ describe('.auth()', () => {
|
|||
|
||||
// Sign back in
|
||||
|
||||
await bridge.module.auth().signInAnonymouslyAndRetrieveData();
|
||||
await firebase.auth().signInAnonymouslyAndRetrieveData();
|
||||
|
||||
// Assertions
|
||||
|
||||
|
@ -219,7 +218,7 @@ describe('.auth()', () => {
|
|||
|
||||
// Tear down
|
||||
|
||||
await bridge.module.auth().signOut();
|
||||
await firebase.auth().signOut();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,6 +13,19 @@ after(async () => {
|
|||
await detox.cleanup();
|
||||
});
|
||||
|
||||
bridge.beforeContextReset = () => {
|
||||
// console.dir(bridge.context.__coverage__);
|
||||
};
|
||||
// bridge.beforeContextReset = () => {
|
||||
// console.log('hello');
|
||||
// };
|
||||
|
||||
Object.defineProperty(global, 'firebase', {
|
||||
get() {
|
||||
return bridge.module;
|
||||
},
|
||||
set() {
|
||||
// do nothing
|
||||
},
|
||||
});
|
||||
|
||||
// Object.defineProperty(global, 'firebase', { value: undefined });
|
||||
|
||||
// delete global.firebase;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
--recursive
|
||||
--timeout 120000
|
||||
--slow 1400
|
||||
--slow 1
|
||||
--bail
|
||||
--exit
|
||||
--grep auth
|
||||
--require ./bridge/env/node
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,13 +3,20 @@
|
|||
"version": "7.2.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start-local-debug": "node node_modules/react-native/local-cli/cli.js start --platforms ios,android --skipflow",
|
||||
"start": "REACT_DEBUGGER='echo nope' node node_modules/react-native/local-cli/cli.js start --platforms ios,android --skipflow",
|
||||
"start-ci": "REACT_DEBUGGER='todo' node node_modules/react-native/local-cli/cli.js start --platforms ios,android --skipflow --nonPersistent",
|
||||
"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",
|
||||
"packager-chrome": "node node_modules/react-native/local-cli/cli.js start --platforms ios,android",
|
||||
"packager-bridge": "REACT_DEBUGGER='echo nope' node node_modules/react-native/local-cli/cli.js start --platforms ios,android",
|
||||
|
||||
"build-android": "detox build --configuration android.emu.debug",
|
||||
|
||||
"test": "npm run test-android && test-ios",
|
||||
|
||||
"test-android": "detox test --configuration android.emu.debug",
|
||||
"test-android-reuse": "detox test --configuration android.emu.debug --reuse",
|
||||
"test-android-cover": "nyc detox test --configuration android.emu.debug",
|
||||
"test-android-cover-reuse": "nyc detox test --configuration android.emu.debug --reuse",
|
||||
|
||||
"test-ios": "detox test --configuration ios.sim.debug",
|
||||
"test-ios-cover": "nyc detox test --configuration ios.sim.debug",
|
||||
"ios:pod:install": "cd ios && rm -rf ReactNativeFirebaseDemo.xcworkspace && pod install && cd .."
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -18,6 +25,7 @@
|
|||
"chalk": "^2.3.2",
|
||||
"deeps": "^1.4.4",
|
||||
"detox": "^7.2.0",
|
||||
"istanbul-lib-coverage": "^1.2.0",
|
||||
"mocha": "^4.0.1",
|
||||
"react": "^16.2.0",
|
||||
"react-native": "^0.52.3",
|
||||
|
@ -39,7 +47,19 @@
|
|||
"eslint-plugin-flowtype": "^2.46.1",
|
||||
"eslint-plugin-import": "^2.9.0",
|
||||
"eslint-plugin-jsx-a11y": "^4.0.0",
|
||||
"eslint-plugin-react": "^6.10.0"
|
||||
"eslint-plugin-react": "^6.10.0",
|
||||
"nyc": "^11.6.0"
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": false,
|
||||
"lines": 95,
|
||||
"statements": 95,
|
||||
"functions": 95,
|
||||
"branches": 95,
|
||||
"include": ["firebase"],
|
||||
"sourceMap": false,
|
||||
"instrument": false,
|
||||
"reporter": ["lcov", "text-summary"]
|
||||
},
|
||||
"detox": {
|
||||
"test-runner": "mocha",
|
||||
|
|
Loading…
Reference in New Issue