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 3a5f242 commit 4746bf0
Show file tree
Hide file tree
Showing 26 changed files with 4,305 additions and 44 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
111 changes: 74 additions & 37 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/**
21 changes: 21 additions & 0 deletions extensions/applicationinsights-perfmarkmeasure-js/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
Loading

0 comments on commit 4746bf0

Please sign in to comment.