[tests] refactor to use latest Jet setup

This commit is contained in:
Salakar
2018-09-12 21:05:48 +01:00
parent 953484a334
commit 93d39412f5
16 changed files with 178 additions and 206 deletions

View File

@@ -1 +1 @@
{}
{}

View File

@@ -16,7 +16,7 @@ class Root extends Component {
message: '',
};
jet.setBridgeProperty('module', firebase);
jet.exposeContextProperty('module', firebase);
}
render() {

View File

@@ -1,124 +0,0 @@
const should = require('should');
describe('bridge', () => {
// beforeEach(async function beforeEach() {
// await device.reloadReactNative();
// bridge.root.setState({ message: this.currentTest.title });
// });
it('should provide -> global.bridge', async () => {
should(bridge).not.be.undefined();
return Promise.resolve();
});
// main react-native module you're testing on
// in our case react-native-firebase
it('should provide -> bridge.module', async () => {
should(bridge.module).not.be.undefined();
return Promise.resolve();
});
// react-native module access
it('should provide -> bridge.rn', () => {
should(bridge.rn).not.be.undefined();
should(bridge.rn.Platform.OS).be.a.String();
should(bridge.rn.Platform.OS).equal(device.getPlatform());
return Promise.resolve();
});
// 'global' context of the app's JS environment
it('should provide -> bridge.context', () => {
should(bridge.context).not.be.undefined();
should(bridge.context.setTimeout).be.a.Function();
should(bridge.context.window).be.a.Object();
// etc ... e.g. __coverage__ is here also if covering
return Promise.resolve();
});
// the apps root component
// allows you to read and set state if required
xit('should provide -> bridge.root', async () => {
should(bridge.root).not.be.undefined();
should(bridge.root.setState).be.a.Function();
should(bridge.root.state).be.a.Object();
// test setting state
await new Promise(resolve =>
bridge.root.setState({ message: 'hello world' }, resolve)
);
should(bridge.root.state.message).equal('hello world');
return Promise.resolve();
});
// we shim our own reloadReactNative functionality as the detox reloadReactNative built-in
// hangs often and seems unpredictable - todo: investigate & PR if solution found
// reloadReactNative is replaced on init with bridge.root automatically
xit('should allow reloadReactNative usage without breaking remote debug', async () => {
should(bridge.reload).be.a.Function();
// and check it works without breaking anything
await device.reloadReactNative();
should(bridge.reload).be.a.Function();
return Promise.resolve();
});
it('should allow launchApp usage without breaking remote debug', async () => {
should(bridge.module).not.be.undefined();
should(bridge.reload).be.a.Function();
should(bridge.rn).not.be.undefined();
should(bridge.rn.Platform.OS).be.a.String();
should(bridge.rn.Platform.OS).equal(device.getPlatform());
await device.launchApp({ newInstance: true });
should(bridge.module).not.be.undefined();
should(bridge.reload).be.a.Function();
should(bridge.rn).not.be.undefined();
should(bridge.rn.Platform.OS).be.a.String();
should(bridge.rn.Platform.OS).equal(device.getPlatform());
return Promise.resolve();
});
// TIMERS
it('timing.setTimeout', cb => {
const start = Date.now();
bridge.context.setTimeout(() => {
const timeTaken = Date.now() - start;
if (timeTaken >= 50) cb();
else cb(new Error('setTimeout fn called too soon.'));
}, 50);
});
it('timing.setInterval', cb => {
let times = 0;
let interval;
const start = Date.now();
interval = bridge.context.setInterval(() => {
const timeTaken = Date.now() - start;
times++;
bridge.context.clearInterval(interval);
if (times >= 2) {
return cb(new Error('Interval did not cancel correctly.'));
}
if (timeTaken < 50) {
return cb(new Error('setInterval fn called too soon.'));
}
return bridge.context.setTimeout(cb, 100);
}, 50);
});
it('timing.setImmediate', cb => {
bridge.context.setImmediate(() => cb());
});
it('timing.requestIdleCallback', cb => {
bridge.context.requestIdleCallback(() => cb());
});
it('timing.requestAnimationFrame', cb => {
bridge.context.requestAnimationFrame(() => cb());
});
});

View File

@@ -16,7 +16,7 @@ describe('database()', () => {
const dataTypeValue = CONTENTS.DEFAULT[dataRef];
const ref = firebase.database().ref(`tests/types/${dataRef}`);
return ref.once('value').then(snapshot => {
snapshot.val().should.eql(bridge.contextify(dataTypeValue));
snapshot.val().should.eql(jet.contextify(dataTypeValue));
});
})
);

View File

@@ -16,14 +16,14 @@ describe('database()', () => {
it('changes value', async () => {
await Promise.all(
Object.keys(CONTENTS.DEFAULT).map(async dataRef => {
const previousValue = bridge.contextify(CONTENTS.DEFAULT[dataRef]);
const previousValue = jet.contextify(CONTENTS.DEFAULT[dataRef]);
const ref = firebase.database().ref(`tests/types/${dataRef}`);
const snapshot = await ref.once('value');
snapshot.val().should.eql(previousValue);
const newValue = bridge.contextify(CONTENTS.NEW[dataRef]);
const newValue = jet.contextify(CONTENTS.NEW[dataRef]);
await ref.set(newValue);
@@ -36,7 +36,7 @@ describe('database()', () => {
it('can unset values', async () => {
await Promise.all(
Object.keys(CONTENTS.DEFAULT).map(async dataRef => {
const previousValue = bridge.contextify(CONTENTS.DEFAULT[dataRef]);
const previousValue = jet.contextify(CONTENTS.DEFAULT[dataRef]);
const ref = firebase.database().ref(`tests/types/${dataRef}`);
const snapshot = await ref.once('value');

View File

@@ -12,7 +12,7 @@ describe('database()', () => {
.once('value');
snapshot.val.should.be.a.Function();
snapshot.val().should.eql(bridge.Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
snapshot.val().should.eql(jet.Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));
});
it('should provide a functioning child() method', async () => {
@@ -71,7 +71,7 @@ describe('database()', () => {
const snapshot = await ref.once('value');
snapshot.getPriority.should.be.a.Function();
snapshot.getPriority().should.equal(666);
snapshot.val().should.eql(bridge.Object({ foo: 'bar' }));
snapshot.val().should.eql(jet.Object({ foo: 'bar' }));
});
it('should provide a functioning forEach() method', async () => {

View File

@@ -11,19 +11,19 @@ const {
} = TestHelpers.firestore;
function getCollectionReferenceClass() {
return bridge.require('src/modules/firestore/CollectionReference');
return jet.require('src/modules/firestore/CollectionReference');
}
function getDocumentReferenceClass() {
return bridge.require('src/modules/firestore/DocumentReference');
return jet.require('src/modules/firestore/DocumentReference');
}
function getDocumentSnapshotClass() {
return bridge.require('src/modules/firestore/DocumentSnapshot');
return jet.require('src/modules/firestore/DocumentSnapshot');
}
function getPathClass() {
return bridge.require('src/modules/firestore/Path');
return jet.require('src/modules/firestore/Path');
}
describe('firestore()', () => {

View File

@@ -622,14 +622,14 @@ describe('firestore()', () => {
});
it('should handle Date field', async () => {
const date = new bridge.context.window.Date();
const date = new jet.context.window.Date();
const docRef = test2DocRef('reference');
await docRef.set({
field: date,
});
const doc = await docRef.get();
doc.data().field.should.be.instanceof(bridge.context.window.Date);
doc.data().field.should.be.instanceof(jet.context.window.Date);
should.equal(doc.data().field.toISOString(), date.toISOString());
should.equal(doc.data().field.getTime(), date.getTime());
});

View File

@@ -23,7 +23,7 @@ describe('firestore()', () => {
describe('ref', () => {
it('returns a DocumentReference', async () => {
const snapshot = await testCollectionDoc(COL_DOC_1_PATH).get();
const DocumentReference = bridge.require(
const DocumentReference = jet.require(
'src/modules/firestore/DocumentReference'
);
snapshot.ref.should.be.an.instanceOf(DocumentReference);

View File

@@ -42,7 +42,7 @@ describe('firestore()', () => {
).get();
dataAfterUpdate().creationDate.should.be.instanceof(
bridge.context.window.Date
jet.context.window.Date
);
});
});

View File

@@ -2,14 +2,14 @@ describe('firestore()', () => {
describe('Path', () => {
describe('id', () => {
it('returns the document id', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection/documentId');
path.id.should.be.equal('documentId');
});
it('returns null if no path', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('');
should.equal(path.id, null);
@@ -18,14 +18,14 @@ describe('firestore()', () => {
describe('isDocument', () => {
it('returns true if path is a document', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection/documentId');
path.isDocument.should.be.equal(true);
});
it('returns false if path is a collection', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection');
path.isDocument.should.be.equal(false);
@@ -34,14 +34,14 @@ describe('firestore()', () => {
describe('isCollection', () => {
it('returns true if path is a collection', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection');
path.isCollection.should.be.equal(true);
});
it('returns false if path is a document', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection/documentId');
path.isCollection.should.be.equal(false);
@@ -50,7 +50,7 @@ describe('firestore()', () => {
describe('relativeName', () => {
it('returns original full path', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection');
const path2 = Path.fromName('collection/documentId');
@@ -61,7 +61,7 @@ describe('firestore()', () => {
describe('child()', () => {
it('returns original path joined with the provided child path', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection');
const path2 = path.child('documentId');
@@ -72,7 +72,7 @@ describe('firestore()', () => {
describe('parent()', () => {
it('returns the parent of the current child path', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection/documentId');
const path2 = path.parent();
@@ -81,7 +81,7 @@ describe('firestore()', () => {
});
it('returns null if no path', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('');
const path2 = path.parent();
@@ -92,7 +92,7 @@ describe('firestore()', () => {
describe('static fromName()', () => {
it('returns a new instance from a / delimited path string', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('collection/document');
path.should.be.instanceOf(Path);
@@ -100,7 +100,7 @@ describe('firestore()', () => {
});
it('returns a new instance from an empty string', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName('');
path.should.be.instanceOf(Path);
@@ -109,7 +109,7 @@ describe('firestore()', () => {
});
it('returns a new instance with no args provided', async () => {
const Path = bridge.require('src/modules/firestore/Path');
const Path = jet.require('src/modules/firestore/Path');
const path = Path.fromName();
path.should.be.instanceOf(Path);

126
tests/e2e/jet.spec.js Executable file
View File

@@ -0,0 +1,126 @@
const should = require('should');
describe('jet', () => {
// beforeEach(async function beforeEach() {
// await device.reloadReactNative();
// jet.root.setState({ message: this.currentTest.title });
// });
it('should provide -> global.jet', async () => {
should(jet).not.be.undefined();
return Promise.resolve();
});
// main react-native module you're testing on
// in our case react-native-firebase
it('should provide -> jet.module', async () => {
should(jet.module).not.be.undefined();
return Promise.resolve();
});
// react-native module access
it('should provide -> jet.rn', () => {
should(jet.rn).not.be.undefined();
should(jet.rn.Platform.OS).be.a.String();
should(jet.rn.Platform.OS).equal(device.getPlatform());
return Promise.resolve();
});
// 'global' context of the app's JS environment
it('should provide -> jet.context', () => {
should(jet.context).not.be.undefined();
should(jet.context.setTimeout).be.a.Function();
should(jet.context.window).be.a.Object();
// etc ... e.g. __coverage__ is here also if covering
return Promise.resolve();
});
// the apps root component
// allows you to read and set state if required
xit('should provide -> jet.root', async () => {
should(jet.root).not.be.undefined();
should(jet.root.setState).be.a.Function();
should(jet.root.state).be.a.Object();
// test setting state
await new Promise(resolve =>
jet.root.setState({ message: 'hello world' }, resolve)
);
should(jet.root.state.message).equal('hello world');
return Promise.resolve();
});
// we shim our own reloadReactNative functionality as the detox reloadReactNative built-in
// hangs often and seems unpredictable - todo: investigate & PR if solution found
// reloadReactNative is replaced on init with jet.root automatically
xit('should allow reloadReactNative usage without breaking remote debug', async () => {
should(jet.reload).be.a.Function();
// and check it works without breaking anything
await device.reloadReactNative();
should(jet.reload).be.a.Function();
return Promise.resolve();
});
// TODO flakey - "This method must not be called before the JS thread is created"
// https://github.com/facebook/react-native/blob/master/React/CxxBridge/RCTCxxBridge.mm
xit('should allow launchApp usage without breaking remote debug', async () => {
should(jet.module).not.be.undefined();
should(jet.reload).be.a.Function();
should(jet.rn).not.be.undefined();
should(jet.rn.Platform.OS).be.a.String();
should(jet.rn.Platform.OS).equal(device.getPlatform());
await device.launchApp({ newInstance: true });
should(jet.module).not.be.undefined();
should(jet.reload).be.a.Function();
should(jet.rn).not.be.undefined();
should(jet.rn.Platform.OS).be.a.String();
should(jet.rn.Platform.OS).equal(device.getPlatform());
return Promise.resolve();
});
// TIMERS
it('timing.setTimeout', cb => {
const start = Date.now();
jet.context.setTimeout(() => {
const timeTaken = Date.now() - start;
if (timeTaken >= 50) cb();
else cb(new Error('setTimeout fn called too soon.'));
}, 50);
});
it('timing.setInterval', cb => {
let times = 0;
let interval;
const start = Date.now();
interval = jet.context.setInterval(() => {
const timeTaken = Date.now() - start;
times++;
jet.context.clearInterval(interval);
if (times >= 2) {
return cb(new Error('Interval did not cancel correctly.'));
}
if (timeTaken < 50) {
return cb(new Error('setInterval fn called too soon.'));
}
return jet.context.setTimeout(cb, 100);
}, 50);
});
it('timing.setImmediate', cb => {
jet.context.setImmediate(() => cb());
});
it('timing.requestIdleCallback', cb => {
jet.context.requestIdleCallback(() => cb());
});
it('timing.requestAnimationFrame', cb => {
jet.context.requestAnimationFrame(() => cb());
});
});

View File

@@ -41,7 +41,7 @@ module.exports = {
object: {
daz: 123,
},
timestamp: new bridge.context.window.Date(2017, 2, 10, 10, 0, 0),
timestamp: new jet.context.window.Date(2017, 2, 10, 10, 0, 0),
};
},
@@ -58,7 +58,7 @@ module.exports = {
object: {
daz: 123,
},
timestamp: new bridge.context.window.Date(2017, 2, 10, 10, 0, 0),
timestamp: new jet.context.window.Date(2017, 2, 10, 10, 0, 0),
};
},

View File

@@ -5,39 +5,7 @@ global.should = require('should');
Object.defineProperty(global, 'firebase', {
get() {
return bridge.module;
},
});
// TODO move as part of bridge
const { Uint8Array } = global;
Object.defineProperty(global, 'Uint8Array', {
get() {
const { stack } = new Error();
if (
(stack.includes('Context.it') || stack.includes('Context.beforeEach')) &&
global.bridge &&
global.bridge.context
) {
return bridge.context.window.Uint8Array;
}
return Uint8Array;
},
});
// TODO move as part of bridge
const { Array } = global;
Object.defineProperty(global, 'Array', {
get() {
const { stack } = new Error();
if (
(stack.includes('Context.it') || stack.includes('Context.beforeEach')) &&
global.bridge &&
global.bridge.context
) {
return bridge.context.window.Array;
}
return Array;
return jet.module;
},
});
@@ -76,7 +44,9 @@ global.firebaseAdmin = require('firebase-admin');
firebaseAdmin.initializeApp({
credential: firebaseAdmin.credential.cert(
JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT)
JSON.parse(
process.env.FIREBASE_SERVICE_ACCOUNT
)
),
databaseURL: 'https://rnfirebase-b9ad4.firebaseio.com',
});

View File

@@ -221,25 +221,25 @@ PODS:
- nanopb/decode (0.3.8)
- nanopb/encode (0.3.8)
- Protobuf (3.6.1)
- React (0.57.0-rc.4):
- React/Core (= 0.57.0-rc.4)
- React/Core (0.57.0-rc.4):
- yoga (= 0.57.0-rc.4.React)
- React/fishhook (0.57.0-rc.4)
- React/RCTBlob (0.57.0-rc.4):
- React (0.57.0):
- React/Core (= 0.57.0)
- React/Core (0.57.0):
- yoga (= 0.57.0.React)
- React/fishhook (0.57.0)
- React/RCTBlob (0.57.0):
- React/Core
- React/RCTNetwork (0.57.0-rc.4):
- React/RCTNetwork (0.57.0):
- React/Core
- React/RCTText (0.57.0-rc.4):
- React/RCTText (0.57.0):
- React/Core
- React/RCTWebSocket (0.57.0-rc.4):
- React/RCTWebSocket (0.57.0):
- React/Core
- React/fishhook
- React/RCTBlob
- RNFirebase (5.0.0-rc1):
- Firebase/Core
- React
- yoga (0.57.0-rc.4.React)
- yoga (0.57.0.React)
DEPENDENCIES:
- Crashlytics (~> 3.10.7)

View File

@@ -6485,9 +6485,9 @@ react-deep-force-update@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-1.1.2.tgz#3d2ae45c2c9040cbb1772be52f8ea1ade6ca2ee1"
react-devtools-core@^3.2.2:
version "3.3.3"
resolved "https://registry.yarnpkg.com/react-devtools-core/-/react-devtools-core-3.3.3.tgz#3f41c5e8a61142c1022f173151ee4d4e699b81b9"
react-devtools-core@3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/react-devtools-core/-/react-devtools-core-3.3.4.tgz#9e497a94b73413b91774bf3e3197e539d5f9a21d"
dependencies:
shell-quote "^1.6.1"
ws "^3.3.1"
@@ -6522,9 +6522,9 @@ react-motion@^0.5.2:
prop-types "^15.5.8"
raf "^3.1.0"
react-native@^0.57.0-rc.4:
version "0.57.0-rc.4"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.57.0-rc.4.tgz#d8227aad5b7a7f49d066fccb02b36938a3dd4506"
react-native@^0.57.0:
version "0.57.0"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.57.0.tgz#b0d098bbd5393fc3c079f8d7c2a8bf9a10b86b9e"
dependencies:
absolute-path "^0.0.0"
art "^0.10.0"
@@ -6565,7 +6565,7 @@ react-native@^0.57.0-rc.4:
promise "^7.1.1"
prop-types "^15.5.8"
react-clone-referenced-element "^1.0.1"
react-devtools-core "^3.2.2"
react-devtools-core "3.3.4"
react-timer-mixin "^0.13.2"
regenerator-runtime "^0.11.0"
rimraf "^2.5.4"