diff --git a/tests/.watchmanconfig b/tests/.watchmanconfig index 9e26dfee..0967ef42 100755 --- a/tests/.watchmanconfig +++ b/tests/.watchmanconfig @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tests/app.js b/tests/app.js index d2de3d7b..64672821 100755 --- a/tests/app.js +++ b/tests/app.js @@ -16,7 +16,7 @@ class Root extends Component { message: '', }; - jet.setBridgeProperty('module', firebase); + jet.exposeContextProperty('module', firebase); } render() { diff --git a/tests/e2e/bridge.spec.js b/tests/e2e/bridge.spec.js deleted file mode 100755 index 087191a6..00000000 --- a/tests/e2e/bridge.spec.js +++ /dev/null @@ -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()); - }); -}); diff --git a/tests/e2e/database/ref/once.e2e.js b/tests/e2e/database/ref/once.e2e.js index 8a61eb6a..cf5553e2 100644 --- a/tests/e2e/database/ref/once.e2e.js +++ b/tests/e2e/database/ref/once.e2e.js @@ -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)); }); }) ); diff --git a/tests/e2e/database/ref/set.e2e.js b/tests/e2e/database/ref/set.e2e.js index bd568f9a..144ff34f 100644 --- a/tests/e2e/database/ref/set.e2e.js +++ b/tests/e2e/database/ref/set.e2e.js @@ -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'); diff --git a/tests/e2e/database/snapshot.e2e.js b/tests/e2e/database/snapshot.e2e.js index 7e8dff77..d91187ca 100644 --- a/tests/e2e/database/snapshot.e2e.js +++ b/tests/e2e/database/snapshot.e2e.js @@ -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 () => { diff --git a/tests/e2e/firestore/collectionReference.e2e.js b/tests/e2e/firestore/collectionReference.e2e.js index caa7fead..d42eb78f 100644 --- a/tests/e2e/firestore/collectionReference.e2e.js +++ b/tests/e2e/firestore/collectionReference.e2e.js @@ -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()', () => { diff --git a/tests/e2e/firestore/documentReference.e2e.js b/tests/e2e/firestore/documentReference.e2e.js index a52b0c59..8936b57b 100644 --- a/tests/e2e/firestore/documentReference.e2e.js +++ b/tests/e2e/firestore/documentReference.e2e.js @@ -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()); }); diff --git a/tests/e2e/firestore/documentSnapshot.e2e.js b/tests/e2e/firestore/documentSnapshot.e2e.js index 34606079..ec79ca7b 100644 --- a/tests/e2e/firestore/documentSnapshot.e2e.js +++ b/tests/e2e/firestore/documentSnapshot.e2e.js @@ -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); diff --git a/tests/e2e/firestore/fieldValue.e2e.js b/tests/e2e/firestore/fieldValue.e2e.js index 4b10ad0e..b70176bf 100644 --- a/tests/e2e/firestore/fieldValue.e2e.js +++ b/tests/e2e/firestore/fieldValue.e2e.js @@ -42,7 +42,7 @@ describe('firestore()', () => { ).get(); dataAfterUpdate().creationDate.should.be.instanceof( - bridge.context.window.Date + jet.context.window.Date ); }); }); diff --git a/tests/e2e/firestore/path.e2e.js b/tests/e2e/firestore/path.e2e.js index 3f13f52d..b5c8ce6d 100644 --- a/tests/e2e/firestore/path.e2e.js +++ b/tests/e2e/firestore/path.e2e.js @@ -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); diff --git a/tests/e2e/jet.spec.js b/tests/e2e/jet.spec.js new file mode 100755 index 00000000..ffb6b5b6 --- /dev/null +++ b/tests/e2e/jet.spec.js @@ -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()); + }); +}); diff --git a/tests/helpers/firestore.js b/tests/helpers/firestore.js index 60c4b4a9..f2fae4cc 100644 --- a/tests/helpers/firestore.js +++ b/tests/helpers/firestore.js @@ -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), }; }, diff --git a/tests/helpers/index.js b/tests/helpers/index.js index be55a79a..dac994a7 100644 --- a/tests/helpers/index.js +++ b/tests/helpers/index.js @@ -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', }); diff --git a/tests/ios/Podfile.lock b/tests/ios/Podfile.lock index ea59ddad..973a5a23 100644 --- a/tests/ios/Podfile.lock +++ b/tests/ios/Podfile.lock @@ -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) diff --git a/tests/yarn.lock b/tests/yarn.lock index 0e7fd1f6..8441631d 100644 --- a/tests/yarn.lock +++ b/tests/yarn.lock @@ -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"