[perf] Update/add perf method tests
This commit is contained in:
parent
8f6299f07f
commit
417b6ba542
|
@ -0,0 +1,88 @@
|
||||||
|
describe('perf()', () => {
|
||||||
|
describe('HttpMetric', () => {
|
||||||
|
it('start() & stop()', async () => {
|
||||||
|
const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET');
|
||||||
|
await httpMetric.start();
|
||||||
|
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 () => {
|
||||||
|
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.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
xit('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.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
xit('getAttributes()', async () => {
|
||||||
|
const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET');
|
||||||
|
await httpMetric.start();
|
||||||
|
await httpMetric.putAttribute('foo', 'bar');
|
||||||
|
await httpMetric.putAttribute('bar', 'baz');
|
||||||
|
const value = await httpMetric.getAttributes();
|
||||||
|
value.should.deepEqual({
|
||||||
|
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.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setHttpResponseCode()', async () => {
|
||||||
|
const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET');
|
||||||
|
await httpMetric.start();
|
||||||
|
await httpMetric.setHttpResponseCode(500);
|
||||||
|
await httpMetric.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setRequestPayloadSize()', async () => {
|
||||||
|
const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET');
|
||||||
|
await httpMetric.start();
|
||||||
|
await httpMetric.setRequestPayloadSize(1234567);
|
||||||
|
await httpMetric.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setResponseContentType()', async () => {
|
||||||
|
const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET');
|
||||||
|
await httpMetric.start();
|
||||||
|
await httpMetric.setResponseContentType('application/foobar');
|
||||||
|
await httpMetric.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setResponsePayloadSize()', async () => {
|
||||||
|
const httpMetric = firebase.perf().newHttpMetric('http://foo.com', 'GET');
|
||||||
|
await httpMetric.start();
|
||||||
|
await httpMetric.setResponsePayloadSize(123456789);
|
||||||
|
await httpMetric.stop();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -8,9 +8,10 @@ describe('perf()', () => {
|
||||||
await firebase.perf().setPerformanceCollectionEnabled(false);
|
await firebase.perf().setPerformanceCollectionEnabled(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('errors if not boolean', async () => {
|
it('errors if not boolean', async () => {
|
||||||
// TODO add validations to lib
|
(() => firebase.perf().setPerformanceCollectionEnabled()).should.throw(
|
||||||
await firebase.perf().setPerformanceCollectionEnabled();
|
'firebase.perf().setPerformanceCollectionEnabled() requires a boolean value'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,15 +21,23 @@ describe('perf()', () => {
|
||||||
trace.constructor.name.should.be.equal('Trace');
|
trace.constructor.name.should.be.equal('Trace');
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('errors if identifier not a string', async () => {
|
it('errors if identifier not a string', async () => {
|
||||||
// TODO add validations to lib
|
(() => firebase.perf().newTrace([1, 2, 3, 4])).should.throw(
|
||||||
try {
|
'firebase.perf().newTrace() requires a string value'
|
||||||
firebase.perf().newTrace([1, 2, 3, 4]);
|
);
|
||||||
} catch (e) {
|
});
|
||||||
return undefined;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error('Trace did not error on invalid identifier');
|
describe('newHttpMetric()', () => {
|
||||||
|
it('returns an instance of HttpMetric', async () => {
|
||||||
|
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'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,28 +1,88 @@
|
||||||
describe('perf()', () => {
|
describe('perf()', () => {
|
||||||
describe('Trace', () => {
|
describe.only('Trace', () => {
|
||||||
it('start() & stop()', async () => {
|
it('start() & stop()', async () => {
|
||||||
const trace = firebase.perf().newTrace('bar');
|
const trace = firebase.perf().newTrace('bar');
|
||||||
await trace.start();
|
await trace.start();
|
||||||
await trace.stop();
|
await trace.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('incrementCounter()', () => {
|
it('getAttribute() should return null', async () => {
|
||||||
it('accepts a string event', async () => {
|
|
||||||
const trace = firebase.perf().newTrace('bar');
|
const trace = firebase.perf().newTrace('bar');
|
||||||
await trace.start();
|
await trace.start();
|
||||||
await trace.incrementCounter('fooby');
|
const value = await trace.getAttribute('foo');
|
||||||
await trace.incrementCounter('fooby');
|
should.equal(value, null);
|
||||||
await trace.incrementCounter('fooby');
|
|
||||||
await trace.incrementCounter('fooby');
|
|
||||||
await trace.stop();
|
await trace.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('errors if event is not a string', async () => {
|
it('getAttribute() should return string value', async () => {
|
||||||
const trace = firebase.perf().newTrace('bar');
|
const trace = firebase.perf().newTrace('bar');
|
||||||
await trace.start();
|
await trace.start();
|
||||||
await trace.incrementCounter([1, 2, 3, 4]);
|
await trace.putAttribute('foo', 'bar');
|
||||||
|
const value = await trace.getAttribute('foo');
|
||||||
|
should.equal(value, 'bar');
|
||||||
await trace.stop();
|
await trace.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('putAttribute()', async () => {
|
||||||
|
const trace = firebase.perf().newTrace('bar');
|
||||||
|
await trace.start();
|
||||||
|
await trace.putAttribute('foo', 'bar');
|
||||||
|
const value = await trace.getAttribute('foo');
|
||||||
|
value.shoud.equal('bar');
|
||||||
|
await trace.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getAttributes()', async () => {
|
||||||
|
const trace = firebase.perf().newTrace('bar');
|
||||||
|
await trace.start();
|
||||||
|
await trace.putAttribute('foo', 'bar');
|
||||||
|
await trace.putAttribute('bar', 'baz');
|
||||||
|
const value = await trace.getAttributes();
|
||||||
|
value.should.deepEqual({
|
||||||
|
foo: 'bar',
|
||||||
|
bar: 'baz',
|
||||||
|
});
|
||||||
|
await trace.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removeAttribute()', async () => {
|
||||||
|
const trace = firebase.perf().newTrace('bar');
|
||||||
|
await trace.start();
|
||||||
|
await trace.putAttribute('foobar', 'bar');
|
||||||
|
const value = await trace.getAttribute('foobar');
|
||||||
|
value.should.equal('bar');
|
||||||
|
await trace.removeAttribute('foobar');
|
||||||
|
const removed = await trace.getAttribute('foobar');
|
||||||
|
should.equal(removed, null);
|
||||||
|
await trace.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getMetric()', async () => {
|
||||||
|
const trace = firebase.perf().newTrace('bar');
|
||||||
|
await trace.start();
|
||||||
|
const metric = await trace.getMetric('foo');
|
||||||
|
metric.should.equal(0);
|
||||||
|
await trace.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('putMetric()', async () => {
|
||||||
|
const trace = firebase.perf().newTrace('bar');
|
||||||
|
await trace.start();
|
||||||
|
await trace.putMetric('baz', 1);
|
||||||
|
const metric = await trace.getMetric('baz');
|
||||||
|
metric.should.equal(1);
|
||||||
|
await trace.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.only('incrementMetric()', async () => {
|
||||||
|
const trace = firebase.perf().newTrace('bar');
|
||||||
|
await trace.start();
|
||||||
|
await trace.putMetric('baz', 1);
|
||||||
|
await trace.incrementMetric('baz', 2);
|
||||||
|
const metric = await trace.getMetric('baz');
|
||||||
|
metric.should.equal(3);
|
||||||
|
await trace.stop();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue