mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-23 03:59:18 +08:00
@@ -1,9 +1,106 @@
|
||||
import perf from '../lib';
|
||||
import perf, { firebase } from '../lib';
|
||||
|
||||
describe('Performance Monitoring', () => {
|
||||
describe('namespace', () => {
|
||||
it('accessible from firebase.app()', () => {
|
||||
const app = firebase.app();
|
||||
expect(app.perf).toBeDefined();
|
||||
expect(app.perf().app).toEqual(app);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setPerformanceCollectionEnabled', () => {
|
||||
it('errors if not boolean', async () => {
|
||||
it('errors if not boolean', () => {
|
||||
expect(() => perf().setPerformanceCollectionEnabled()).toThrow('must be a boolean');
|
||||
});
|
||||
});
|
||||
|
||||
describe('newTrace()', () => {
|
||||
it('returns an instance of Trace', () => {
|
||||
const trace = perf().newTrace('invertase');
|
||||
expect(trace.constructor.name).toEqual('Trace');
|
||||
expect(trace._identifier).toEqual('invertase');
|
||||
});
|
||||
|
||||
it('errors if identifier not a string', () => {
|
||||
try {
|
||||
perf().newTrace(1337);
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(
|
||||
"firebase.perf().newTrace(*) 'identifier' must be a string with a maximum length of 100 characters.",
|
||||
);
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
it('errors if identifier length > 100', () => {
|
||||
try {
|
||||
perf().newTrace(new Array(101).fill('i').join(''));
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(
|
||||
"firebase.perf().newTrace(*) 'identifier' must be a string with a maximum length of 100 characters.",
|
||||
);
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('newHttpMetric()', () => {
|
||||
it('returns an instance of HttpMetric', async () => {
|
||||
const metric = perf().newHttpMetric('https://invertase.io', 'GET');
|
||||
expect(metric.constructor.name).toEqual('HttpMetric');
|
||||
expect(metric._url).toEqual('https://invertase.io');
|
||||
expect(metric._httpMethod).toEqual('GET');
|
||||
});
|
||||
|
||||
it('errors if url not a string', async () => {
|
||||
try {
|
||||
perf().newHttpMetric(1337, 7331);
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual("firebase.perf().newHttpMetric(*, _) 'url' must be a string.");
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
it('errors if httpMethod not a string', async () => {
|
||||
try {
|
||||
perf().newHttpMetric('https://invertase.io', 1337);
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(
|
||||
"firebase.perf().newHttpMetric(_, *) 'httpMethod' must be one of CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, TRACE.",
|
||||
);
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
it('errors if httpMethod not a valid type', async () => {
|
||||
try {
|
||||
perf().newHttpMetric('https://invertase.io', 'FIRE');
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(
|
||||
"firebase.perf().newHttpMetric(_, *) 'httpMethod' must be one of CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, TRACE.",
|
||||
);
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('setPerformanceCollectionEnabled()', () => {
|
||||
it('errors if not boolean', async () => {
|
||||
try {
|
||||
firebase.perf().setPerformanceCollectionEnabled();
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(
|
||||
"firebase.perf().setPerformanceCollectionEnabled(*) 'enabled' must be a boolean.",
|
||||
);
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,14 +16,6 @@
|
||||
*/
|
||||
|
||||
android.describe('perf()', () => {
|
||||
describe('namespace', () => {
|
||||
it('accessible from firebase.app()', () => {
|
||||
const app = firebase.app();
|
||||
should.exist(app.perf);
|
||||
app.perf().app.should.equal(app);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setPerformanceCollectionEnabled()', () => {
|
||||
// TODO sometimes android launches with isPerformanceCollectionEnabled = false
|
||||
xit('true', async () => {
|
||||
@@ -42,44 +34,6 @@ android.describe('perf()', () => {
|
||||
should.equal(firebase.perf().isPerformanceCollectionEnabled, true);
|
||||
await Utils.sleep(1500);
|
||||
});
|
||||
|
||||
it('errors if not boolean', async () => {
|
||||
try {
|
||||
firebase.perf().setPerformanceCollectionEnabled();
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
e.message.should.containEql('must be a boolean');
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('newTrace()', () => {
|
||||
it('returns an instance of Trace', async () => {
|
||||
const trace = firebase.perf().newTrace('invertase');
|
||||
trace.constructor.name.should.be.equal('Trace');
|
||||
trace._identifier.should.equal('invertase');
|
||||
});
|
||||
|
||||
it('errors if identifier not a string', async () => {
|
||||
try {
|
||||
firebase.perf().newTrace(1337);
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
e.message.should.containEql('must be a string');
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
it('errors if identifier length > 100', async () => {
|
||||
try {
|
||||
firebase.perf().newTrace(new Array(101).fill('i').join(''));
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
e.message.should.containEql('with a maximum length of 100 characters');
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('startTrace()', () => {
|
||||
@@ -91,43 +45,4 @@ android.describe('perf()', () => {
|
||||
await trace.stop();
|
||||
});
|
||||
});
|
||||
|
||||
describe('newHttpMetric()', () => {
|
||||
it('returns an instance of HttpMetric', async () => {
|
||||
const metric = firebase.perf().newHttpMetric('https://invertase.io', 'GET');
|
||||
metric.constructor.name.should.be.equal('HttpMetric');
|
||||
metric._url.should.equal('https://invertase.io');
|
||||
metric._httpMethod.should.equal('GET');
|
||||
});
|
||||
|
||||
it('errors if url not a string', async () => {
|
||||
try {
|
||||
firebase.perf().newHttpMetric(1337, 7331);
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
e.message.should.containEql('must be a string');
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
it('errors if httpMethod not a string', async () => {
|
||||
try {
|
||||
firebase.perf().newHttpMetric('https://invertase.io', 1337);
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
e.message.should.containEql('must be one of');
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
it('errors if httpMethod not a valid type', async () => {
|
||||
try {
|
||||
firebase.perf().newHttpMetric('https://invertase.io', 'FIRE');
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (e) {
|
||||
e.message.should.containEql('must be one of');
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user