[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,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());
});
});