2018-04-11 02:42:25 +00:00
|
|
|
describe('perf()', () => {
|
2018-07-18 12:22:00 +00:00
|
|
|
describe('Trace', () => {
|
2018-04-11 02:42:25 +00:00
|
|
|
it('start() & stop()', async () => {
|
|
|
|
const trace = firebase.perf().newTrace('bar');
|
|
|
|
await trace.start();
|
|
|
|
await trace.stop();
|
|
|
|
});
|
|
|
|
|
2018-07-10 19:14:36 +00:00
|
|
|
it('getAttribute() should return null', async () => {
|
|
|
|
const trace = firebase.perf().newTrace('bar');
|
|
|
|
await trace.start();
|
|
|
|
const value = await trace.getAttribute('foo');
|
|
|
|
should.equal(value, null);
|
|
|
|
await trace.stop();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('getAttribute() should return string value', async () => {
|
|
|
|
const trace = firebase.perf().newTrace('bar');
|
|
|
|
await trace.start();
|
|
|
|
await trace.putAttribute('foo', 'bar');
|
|
|
|
const value = await trace.getAttribute('foo');
|
|
|
|
should.equal(value, 'bar');
|
|
|
|
await trace.stop();
|
|
|
|
});
|
2018-04-11 02:42:25 +00:00
|
|
|
|
2018-07-10 19:14:36 +00:00
|
|
|
it('putAttribute()', async () => {
|
|
|
|
const trace = firebase.perf().newTrace('bar');
|
|
|
|
await trace.start();
|
|
|
|
await trace.putAttribute('foo', 'bar');
|
|
|
|
const value = await trace.getAttribute('foo');
|
2018-07-18 12:30:54 +00:00
|
|
|
value.should.equal('bar');
|
2018-07-10 19:14:36 +00:00
|
|
|
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',
|
2018-04-11 02:42:25 +00:00
|
|
|
});
|
2018-07-10 19:14:36 +00:00
|
|
|
await trace.stop();
|
2018-04-11 02:42:25 +00:00
|
|
|
});
|
2018-07-10 19:14:36 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2018-07-18 12:22:00 +00:00
|
|
|
it('incrementMetric()', async () => {
|
2018-07-10 19:14:36 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2018-04-11 02:42:25 +00:00
|
|
|
});
|
|
|
|
});
|