Skip to content

Commit

Permalink
chore: update types tests (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhousley authored Jun 25, 2024
1 parent e6ccc1d commit c7efd9a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/loaders/agent-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class AgentBase {
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
* @param {string} name Name of the attribute. Appears as column in the PageView event. It will also appear as a column in the PageAction event if you are using it.
* @param {string|number|boolean|null} value Value of the attribute. Appears as the value in the named attribute column in the PageView event. It will appear as a column in the PageAction event if you are using it. Custom attribute values cannot be complex objects, only simple types such as Strings, Integers and Booleans. Passing a null value unsets any existing attribute of the same name.
* @param {boolean} [persist] Default false. f set to true, the name-value pair will also be set into the browser's storage API. Then on the following instrumented pages that load within the same session, the pair will be re-applied as a custom attribute.
* @param {boolean} [persist] Default false. If set to true, the name-value pair will also be set into the browser's storage API. Then on the following instrumented pages that load within the same session, the pair will be re-applied as a custom attribute.
*/
setCustomAttribute (name, value, persist) {
return this.#callMethod('setCustomAttribute', name, value, persist)
Expand Down Expand Up @@ -186,7 +186,7 @@ export class AgentBase {
* Capture a single log.
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/loginfo/}
* @param {string} message String to be captured as log message
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} options customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} [options] customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
*/
log (message, options) {
return this.#callMethod('logInfo', message, options)
Expand All @@ -195,9 +195,9 @@ export class AgentBase {
/**
* Wrap a logger function to capture a log each time the function is invoked with the message and arguments passed
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/wraplogger/}
* @param {Object} parent The parent object containing the logger method
* @param {object} parent The parent object containing the logger method
* @param {string} functionName The property name of the function in the parent object to be wrapped
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} options customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} [options] customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
*/
wrapLogger (parent, functionName, options) {
return this.#callMethod('wrapLogger', parent, functionName, options)
Expand Down
30 changes: 18 additions & 12 deletions tests/dts/api.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,31 @@ expectType<(name: string) => any>(browserAgent.setCurrentRouteName)
expectType<() => InteractionInstance>(browserAgent.interaction)

// Base Agent APIs
expectType<(name: string, attributes?: object | undefined) => any>(browserAgent.addPageAction)
expectType<(name: string, host?: string | undefined) => any>(browserAgent.setPageViewName)
expectType<(name: string, value: string | number | boolean | null, persist?: boolean | undefined) => any>(browserAgent.setCustomAttribute)
expectType<(error: Error | string, customAttributes?: object | undefined) => any>(browserAgent.noticeError)
expectType<(name: string, attributes?: object) => any>(browserAgent.addPageAction)
expectType<(name: string, host?: string) => any>(browserAgent.setPageViewName)
expectType<(name: string, value: string | number | boolean | null, persist?: boolean) => any>(browserAgent.setCustomAttribute)
expectType<(error: Error | string, customAttributes?: object) => any>(browserAgent.noticeError)
expectType<(value: string | null) => any>(browserAgent.setUserId)
expectType<(value: string | null) => any>(browserAgent.setApplicationVersion)
expectType<(callback: (error: Error | string) => boolean | { group: string; }) => any>(browserAgent.setErrorHandler)
expectType<(timeStamp?: number | undefined) => any>(browserAgent.finished)
expectType<(timeStamp?: number) => any>(browserAgent.finished)
expectType<(name: string, id: string) => any>(browserAgent.addRelease)
expectType<(featureNames?: string | string[]) => any>(browserAgent.start)
expectType<() => any>(browserAgent.recordReplay)
expectType<() => any>(browserAgent.pauseReplay)
expectType<(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => any>(browserAgent.log)
expectType<(parent: object, functionName: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => any>(browserAgent.wrapLogger)

// SPA APIs
expectType<() => InteractionInstance>(browserAgent.interaction)
expectType<(value: string) => InteractionInstance>(browserAgent.interaction().actionText)
expectType<(name: string, callback?: ((...args: any[]) => any) | undefined) => (...args: any) => any>(browserAgent.interaction().createTracer)
expectType<(name: string, callback?: ((...args: any[]) => any)) => (...args: any) => any>(browserAgent.interaction().createTracer)
expectType<() => InteractionInstance>(browserAgent.interaction().end)
expectType<getContext>(browserAgent.interaction().getContext)
expectType<() => InteractionInstance>(browserAgent.interaction().ignore)
expectType<onEnd>(browserAgent.interaction().onEnd)
expectType<(key: string, value: any) => InteractionInstance>(browserAgent.interaction().setAttribute)
expectType<(name: string, trigger?: string | undefined) => InteractionInstance>(browserAgent.interaction().setName)
expectType<(name: string, trigger?: string) => InteractionInstance>(browserAgent.interaction().setName)

// Micro Agent APIs
const microAgent = new MicroAgent({})
Expand All @@ -54,12 +59,13 @@ expectType<(name: string) => any>(microAgent.setCurrentRouteName)
expectType<() => InteractionInstance>(microAgent.interaction)

// Base Agent APIs
expectType<(name: string, attributes?: object | undefined) => any>(microAgent.addPageAction)
expectType<(name: string, host?: string | undefined) => any>(microAgent.setPageViewName)
expectType<(name: string, value: string | number | boolean | null, persist?: boolean | undefined) => any>(microAgent.setCustomAttribute)
expectType<(error: Error | string, customAttributes?: object | undefined) => any>(microAgent.noticeError)
expectType<(name: string, attributes?: object) => any>(microAgent.addPageAction)
expectType<(name: string, host?: string) => any>(microAgent.setPageViewName)
expectType<(name: string, value: string | number | boolean | null, persist?: boolean) => any>(microAgent.setCustomAttribute)
expectType<(error: Error | string, customAttributes?: object) => any>(microAgent.noticeError)
expectType<(value: string | null) => any>(microAgent.setUserId)
expectType<(value: string | null) => any>(microAgent.setApplicationVersion)
expectType<(callback: (error: Error | string) => boolean | { group: string; }) => any>(microAgent.setErrorHandler)
expectType<(timeStamp?: number | undefined) => any>(microAgent.finished)
expectType<(timeStamp?: number) => any>(microAgent.finished)
expectType<(name: string, id: string) => any>(microAgent.addRelease)
expectType<(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => any>(microAgent.log)

0 comments on commit c7efd9a

Please sign in to comment.