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