Skip to content

Commit

Permalink
Merge branch 'master' into metrics-host
Browse files Browse the repository at this point in the history
  • Loading branch information
obecny authored Dec 10, 2020
2 parents 33329e1 + 4ed223b commit fe6bfc4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DocumentLoad extends BasePlugin<unknown> {
* @param rootSpan
*/
private _addResourcesSpans(rootSpan: Span): void {
const resources: PerformanceResourceTiming[] = otperformance.getEntriesByType(
const resources: PerformanceResourceTiming[] = otperformance.getEntriesByType?.(
'resource'
) as PerformanceResourceTiming[];
if (resources) {
Expand Down Expand Up @@ -163,7 +163,7 @@ export class DocumentLoad extends BasePlugin<unknown> {
*/
private _getEntries() {
const entries: PerformanceEntries = {};
const performanceNavigationTiming = (otperformance.getEntriesByType(
const performanceNavigationTiming = (otperformance.getEntriesByType?.(
'navigation'
)[0] as unknown) as PerformanceEntries;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,21 +511,7 @@ describe('DocumentLoad Plugin', () => {
});
});

describe('when navigation entries types are NOT available then fallback to "performance.timing"', () => {
let spyEntries: any;
beforeEach(() => {
spyEntries = sinon.stub(window.performance, 'getEntriesByType');
spyEntries.withArgs('navigation').returns([]);
spyEntries.withArgs('resource').returns([]);
Object.defineProperty(window.performance, 'timing', {
writable: true,
value: entriesFallback,
});
});
afterEach(() => {
spyEntries.restore();
});

function shouldExportCorrectSpan() {
it('should export correct span with events', done => {
const spyOnEnd = sinon.spy(dummyExporter, 'export');
plugin.enable(moduleExports, provider, logger, config);
Expand Down Expand Up @@ -557,6 +543,41 @@ describe('DocumentLoad Plugin', () => {
done();
});
});
}

describe('when navigation entries types are NOT available then fallback to "performance.timing"', () => {
let spyEntries: any;
beforeEach(() => {
spyEntries = sinon.stub(window.performance, 'getEntriesByType');
spyEntries.withArgs('navigation').returns([]);
spyEntries.withArgs('resource').returns([]);

Object.defineProperty(window.performance, 'timing', {
writable: true,
value: entriesFallback,
});
});
afterEach(() => {
spyEntries.restore();
});

shouldExportCorrectSpan();
});

describe('when getEntriesByType is not defined then fallback to "performance.timing"', () => {
beforeEach(() => {
Object.defineProperty(window.performance, 'getEntriesByType', {
writable: true,
value: undefined,
});

Object.defineProperty(window.performance, 'timing', {
writable: true,
value: entriesFallback,
});
});

shouldExportCorrectSpan();
});

describe('when navigation entries types and "performance.timing" are NOT available', () => {
Expand Down

0 comments on commit fe6bfc4

Please sign in to comment.