Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AISKULight/Tests/Unit/src/AISKULightSize.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { AITestClass, Assert } from "@microsoft/ai-test-framework";
import * as pako from "pako";

export class AISKULightSizeCheck extends AITestClass {
private readonly MAX_RAW_SIZE = 89;
private readonly MAX_BUNDLE_SIZE = 89;
private readonly MAX_RAW_SIZE = 90;
private readonly MAX_BUNDLE_SIZE = 90;
private readonly MAX_RAW_DEFLATE_SIZE = 37;
private readonly MAX_BUNDLE_DEFLATE_SIZE = 37;
private readonly rawFilePath = "../dist/es5/applicationinsights-web-basic.min.js";
Expand Down
75 changes: 72 additions & 3 deletions AISKULight/Tests/Unit/src/config.tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AITestClass, Assert } from "@microsoft/ai-test-framework";
import { newId } from "@microsoft/applicationinsights-core-js";
import { AITestClass, Assert, PollingAssert } from "@microsoft/ai-test-framework";
import { ITelemetryItem, newId } from "@microsoft/applicationinsights-core-js";
import { ApplicationInsights} from "../../../src/index";
import { BreezeChannelIdentifier, utlRemoveSessionStorage } from "@microsoft/applicationinsights-common";
import { BreezeChannelIdentifier, ContextTagKeys, utlRemoveSessionStorage } from "@microsoft/applicationinsights-common";
import { Sender } from "@microsoft/applicationinsights-channel-js";

export class ApplicationInsightsConfigTests extends AITestClass {
Expand All @@ -11,6 +11,20 @@ export class ApplicationInsightsConfigTests extends AITestClass {
private readonly _iKey = "testKey";
private _sessionPrefix: string = newId();
static registerTests: any;
private static readonly _expectedTrackMethods = [
"flush",
"pollInternalLogs",
"stopPollingInternalLogs",
"unload",
"getPlugin",
"addPlugin",
"evtNamespace",
"addUnloadCb",
"onCfgChange",
"getTraceCtx",
"updateCfg",
"addTelemetryInitializer"
];

constructor(testName?: string) {
super(testName || "ApplicationInsightsAISKULightTests");
Expand Down Expand Up @@ -186,6 +200,23 @@ export class ApplicationInsightsConfigTests extends AITestClass {
}
});


this.testCase({
name: 'Proxy function exist',
test: () => {
this.onDone(() =>{
ai.unload(false);
});
let _config = this._getTestConfig(this._sessionPrefix, true, false);
let ai = new ApplicationInsights(_config);
ApplicationInsightsConfigTests._expectedTrackMethods.forEach(method => {
Assert.ok(ai[method], `${method} exists`);
Assert.equal('function', typeof ai[method], `${method} is a function`);
});
}
});


this.testCase({
name: "TrackTests: BaseData and baseType should exist",
test: () => {
Expand Down Expand Up @@ -231,6 +262,44 @@ export class ApplicationInsightsConfigTests extends AITestClass {

}
});

this.testCase({
name: 'Proxy function exist',
test: () => {
this.onDone(() =>{
ai.unload(false);
});
let _config = this._getTestConfig(this._sessionPrefix, true, false);
let ai = new ApplicationInsights(_config);
ApplicationInsightsConfigTests._expectedTrackMethods.forEach(method => {
Assert.ok(ai[method], `${method} exists`);
Assert.equal('function', typeof ai[method], `${method} is a function`);
});
}
});

this.testCase({
name: 'test proxy function (telemetry initializer) works',
useFakeTimers: true,
test: () => {
this.onDone(() =>{
ai.unload(false);
});
let _config = this._getTestConfig(this._sessionPrefix, true, false);
let ai = new ApplicationInsights(_config);
const telemetryInitializer = {
initializer: (envelope) => { }
}
const spy = this.sandbox.spy(telemetryInitializer, "initializer");
// act
ai.addTelemetryInitializer(telemetryInitializer.initializer);
ai.track({name: 'test event'});
this.clock.tick(1);

// verify
Assert.ok(spy.calledOnce, 'telemetryInitializer was called');
}
});
}

}
33 changes: 30 additions & 3 deletions AISKULight/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import dynamicProto from "@microsoft/dynamicproto-js";
import { Sender } from "@microsoft/applicationinsights-channel-js";
import { DEFAULT_BREEZE_PATH, IConfig, parseConnectionString } from "@microsoft/applicationinsights-common";
import {
AppInsightsCore, IConfigDefaults, IConfiguration, IDynamicConfigHandler, ILoadedPlugin, IPlugin, ITelemetryItem, ITelemetryPlugin,
ITelemetryUnloadState, IUnloadHook, UnloadHandler, WatcherFunction, cfgDfValidate, createDynamicConfig, onConfigChange, proxyFunctions
AppInsightsCore, IConfigDefaults, IConfiguration, IDistributedTraceContext, IDynamicConfigHandler, ILoadedPlugin, IPlugin,
ITelemetryInitializerHandler, ITelemetryItem, ITelemetryPlugin, ITelemetryUnloadState, IUnloadHook, UnloadHandler, WatcherFunction,
cfgDfValidate, createDynamicConfig, onConfigChange, proxyFunctions
} from "@microsoft/applicationinsights-core-js";
import { IPromise, createAsyncPromise, doAwaitResponse } from "@nevware21/ts-async";
import { isNullOrUndefined, isPromiseLike, isString, objDefine, throwError } from "@nevware21/ts-utils";
Expand Down Expand Up @@ -65,7 +66,10 @@ export class ApplicationInsights {
"addPlugin",
"evtNamespace",
"addUnloadCb",
"onCfgChange"
"onCfgChange",
"getTraceCtx",
"updateCfg",
"addTelemetryInitializer"
]);

function _initialize(): void {
Expand Down Expand Up @@ -226,6 +230,29 @@ export class ApplicationInsights {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
}

/**
* Gets the current distributed trace context for this instance if available
*/
public getTraceCtx(): IDistributedTraceContext | null | undefined {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
return null;
}

public addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): ITelemetryInitializerHandler {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
return null;
}

/**
* Update the configuration used and broadcast the changes to all loaded plugins
* @param newConfig - The new configuration is apply
* @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to merge.
*/
public updateCfg<T extends IConfiguration = IConfiguration>(newConfig: T, mergeExisting?: boolean): void {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
}


/**
* Watches and tracks changes for accesses to the current config, and if the accessed config changes the
* handler will be recalled.
Expand Down