This repository was archived by the owner on Apr 3, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -69,3 +69,10 @@ function mergeConfigs<T>(options: T & {debug?: T}): T {
6969 delete result . debug ;
7070 return Object . assign ( result , options . debug ) ;
7171}
72+
73+ /* Used to access the agent if it has been started. Returns the agent
74+ * if the agent has been started. Otherwise, `undefined` is returned.
75+ */
76+ export function get ( ) : Debuglet | undefined {
77+ return debuglet ;
78+ }
Original file line number Diff line number Diff line change 1515 */
1616
1717import * as assert from 'assert' ;
18- const m : NodeModule & { start : Function } = require ( '../..' ) ;
18+ const m : NodeModule & {
19+ start : Function ;
20+ get : ( ) => Debuglet | undefined ;
21+ } = require ( '../..' ) ;
1922import * as nock from 'nock' ;
2023import * as nocks from './nocks' ;
24+ import { Debuglet } from '../src/agent/debuglet' ;
2125
2226nock . disableNetConnect ( ) ;
2327
@@ -39,4 +43,26 @@ describe('Debug module', () => {
3943 m . start ( ) ;
4044 } ) ;
4145 } ) ;
46+
47+ it ( 'should return the agent via the get() method' , ( ) => {
48+ const agent = m . get ( ) ;
49+ assert ( agent , 'Expected to get the started agent' ) ;
50+ assert . strictEqual ( agent ! . config . projectId , '0' ) ;
51+ } ) ;
52+ } ) ;
53+
54+ describe ( 'Debug module without start() called' , ( ) => {
55+ it ( 'get() should return `undefined`' , ( ) => {
56+ delete require . cache [ require . resolve ( '../..' ) ] ;
57+ const m : NodeModule & {
58+ start : Function ;
59+ get : ( ) => Debuglet | undefined ;
60+ } = require ( '../..' ) ;
61+ const agent = m . get ( ) ;
62+ assert . strictEqual (
63+ agent ,
64+ undefined ,
65+ 'Expected `undefined` since the agent was not started'
66+ ) ;
67+ } ) ;
4268} ) ;
You can’t perform that action at this time.
0 commit comments