Skip to content

Commit

Permalink
Add performance.mark and performance.measure for performance browser …
Browse files Browse the repository at this point in the history
…tool integration #617
  • Loading branch information
MSNev committed Aug 12, 2021
1 parent a610015 commit 1ccb951
Show file tree
Hide file tree
Showing 26 changed files with 4,348 additions and 49 deletions.
70 changes: 70 additions & 0 deletions common/Tests/Framework/src/AITestClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class AITestClass {
private _xhrOrgSend: any;
private _xhrRequests: FakeXMLHttpRequest[] = [];
private _orgNavigator: any;
private _orgPerformance: any;
private _beaconHooks: any[] = [];
private _dynProtoOpts: any = null;

Expand Down Expand Up @@ -516,6 +517,73 @@ export class AITestClass {
});
}

protected mockPerformance(newPerformance: any) {

try {
if (!this._orgPerformance) {
this._hookPerformance();
}

// Copy over the mocked values
for (let name in newPerformance) {
if (newPerformance.hasOwnProperty(name)) {
window.performance[name] = newPerformance[name];
}
}
} catch (e) {
console.log("Set performance failed - " + e);
QUnit.assert.ok(true, "Set performance failed - " + e);
try {
sinon.stub(window, "performance").returns(newPerformance);
} catch (ex) {
console.log("Unable to fallback to stub performance failed - " + e);
QUnit.assert.ok(true, "Unable to fallback to stub performance failed - " + e);
}
}
}

private _hookPerformance() {
if (!this._orgPerformance) {
this._orgPerformance = {};

try {
// Just Blindly copy the properties over
// tslint:disable-next-line: forin
for (let name in window.performance) {
if (window.performance.hasOwnProperty(name)) {
this._orgPerformance[name] = window.performance[name];
}
}
} catch (e) {
console.log("Saving performance values - " + e);
QUnit.assert.ok(false, "Saving performance values failed - " + e);
// throw e;
}
}
}

private _restorePerformance() {
if (this._orgPerformance) {

try {
// Just Blindly copy the properties over
// tslint:disable-next-line: forin
for (let name in this._orgPerformance) {
if (!this._orgPerformance.hasOwnProperty(name)) {
window.performance[name] = this._orgPerformance[name];
}
}
} catch (e) {
console.log("Restoring performance values - " + e);
QUnit.assert.ok(false, "Restoring performance values failed - " + e);
// throw e;
}

this._orgNavigator = null;
}
}


private _mockLocation() {
if (!this._orgLocation) {
this._orgLocation = window.location;
Expand Down Expand Up @@ -683,6 +751,8 @@ export class AITestClass {
this._orgNavigator = null;
}

this._restorePerformance();

this._beaconHooks = [];
this._cleanupAllHooks();
this._restoreEs3();
Expand Down
159 changes: 117 additions & 42 deletions common/config/rush/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions extensions/applicationinsights-perfmarkmeasure-js/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# NPM Ignore

# ignore everything
*

# ... but these files
!package.json
!tsconfig.json
!/README.md
!/LICENSE
!dist-esm/**
!dist/**
!browser/**
!types/**
!src/**
Loading

0 comments on commit 1ccb951

Please sign in to comment.