From 6b87ae7056f1c270565ecbd2c4cb47c4e66b9075 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Wed, 18 Jul 2018 13:22:00 +0100 Subject: [PATCH] [perm][android] Fix tests + remove httpMetric instances on stop() --- .../firebase/perf/RNFirebasePerformance.java | 1 + bridge/e2e/perf/httpMetric.e2e.js | 51 ++++++++++--------- bridge/e2e/perf/perf.e2e.js | 11 ---- bridge/e2e/perf/trace.e2e.js | 4 +- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java b/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java index f73dbdfd..c0823f59 100644 --- a/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java +++ b/android/src/main/java/io/invertase/firebase/perf/RNFirebasePerformance.java @@ -178,6 +178,7 @@ public class RNFirebasePerformance extends ReactContextBaseJavaModule { @ReactMethod public void stopHttpMetric(String url, String httpMethod, Promise promise) { getOrCreateHttpMetric(url, httpMethod).stop(); + httpMetrics.remove(url + httpMethod); promise.resolve(null); } diff --git a/bridge/e2e/perf/httpMetric.e2e.js b/bridge/e2e/perf/httpMetric.e2e.js index 2be2debd..a4968e32 100644 --- a/bridge/e2e/perf/httpMetric.e2e.js +++ b/bridge/e2e/perf/httpMetric.e2e.js @@ -6,33 +6,48 @@ describe('perf()', () => { await httpMetric.stop(); }); - it('getAttribute() should return null', async () => { - const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET'); - await httpMetric.start(); - const value = await httpMetric.getAttribute('foo'); - should.equal(value, null); - await httpMetric.stop(); - }); - - xit('getAttribute() should return string value', async () => { + it('removeAttribute()', async () => { const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET'); await httpMetric.start(); await httpMetric.putAttribute('foo', 'bar'); const value = await httpMetric.getAttribute('foo'); should.equal(value, 'bar'); + await httpMetric.removeAttribute('foo'); + const value2 = await httpMetric.getAttribute('foo'); + should.equal(value2, null); await httpMetric.stop(); }); - xit('putAttribute()', async () => { + it('getAttribute() should return null', async () => { + const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET'); + await httpMetric.start(); + const value = await httpMetric.getAttribute('foo'); + should.equal(value, null); + await httpMetric.removeAttribute('foo'); + await httpMetric.stop(); + }); + + it('getAttribute() should return string value', async () => { + const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET'); + await httpMetric.start(); + await httpMetric.putAttribute('foo', 'bar'); + const value = await httpMetric.getAttribute('foo'); + should.equal(value, 'bar'); + await httpMetric.removeAttribute('foo'); + await httpMetric.stop(); + }); + + it('putAttribute()', async () => { const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET'); await httpMetric.start(); await httpMetric.putAttribute('foo', 'bar'); const value = await httpMetric.getAttribute('foo'); value.should.equal('bar'); + await httpMetric.removeAttribute('foo'); await httpMetric.stop(); }); - xit('getAttributes()', async () => { + it('getAttributes()', async () => { const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET'); await httpMetric.start(); await httpMetric.putAttribute('foo', 'bar'); @@ -42,18 +57,8 @@ describe('perf()', () => { foo: 'bar', bar: 'baz', }); - await httpMetric.stop(); - }); - - xit('removeAttribute()', async () => { - const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET'); - await httpMetric.start(); - await httpMetric.putAttribute('foobar', 'bar'); - const value = await httpMetric.getAttribute('foobar'); - value.should.equal('bar'); - await httpMetric.removeAttribute('foobar'); - const removed = await httpMetric.getAttribute('foobar'); - should.equal(removed, null); + await httpMetric.removeAttribute('foo'); + await httpMetric.removeAttribute('bar'); await httpMetric.stop(); }); diff --git a/bridge/e2e/perf/perf.e2e.js b/bridge/e2e/perf/perf.e2e.js index 2936668b..95c84fd2 100644 --- a/bridge/e2e/perf/perf.e2e.js +++ b/bridge/e2e/perf/perf.e2e.js @@ -30,20 +30,10 @@ describe('perf()', () => { describe('newHttpMetric()', () => { it('returns an instance of HttpMetric', async () => { -<<<<<<< Updated upstream const trace = firebase.perf().newHttpMetric('foo', 'bar'); trace.constructor.name.should.be.equal('HttpMetric'); }); - it('errors if url/httpMethod not a string', async () => { - (() => firebase.perf().newHttpMetric(123, [1, 2])).should.throw( - 'firebase.perf().newHttpMetric() requires url and httpMethod string values' - ); -======= - const trace = firebase.perf().newHttpMetric('foo', 'GET'); - trace.constructor.name.should.be.equal('HttpMetric'); - }); - it('errors if url/httpMethod not a string', async () => { (() => firebase.perf().newHttpMetric(123, [1, 2])).should.throw( 'firebase.perf().newHttpMetric() requires url and httpMethod string values' @@ -52,7 +42,6 @@ describe('perf()', () => { it('errors if httpMethod not a valid type', async () => { (() => firebase.perf().newHttpMetric('foo', 'FOO')).should.throw(); // TODO error ->>>>>>> Stashed changes }); }); }); diff --git a/bridge/e2e/perf/trace.e2e.js b/bridge/e2e/perf/trace.e2e.js index 35dedfba..00b5432d 100644 --- a/bridge/e2e/perf/trace.e2e.js +++ b/bridge/e2e/perf/trace.e2e.js @@ -1,5 +1,5 @@ describe('perf()', () => { - describe.only('Trace', () => { + describe('Trace', () => { it('start() & stop()', async () => { const trace = firebase.perf().newTrace('bar'); await trace.start(); @@ -74,7 +74,7 @@ describe('perf()', () => { await trace.stop(); }); - it.only('incrementMetric()', async () => { + it('incrementMetric()', async () => { const trace = firebase.perf().newTrace('bar'); await trace.start(); await trace.putMetric('baz', 1);