@@ -23,6 +23,7 @@ const MODULE_FILE_NAME = 'test-module-file';
2323const MODULE_VERSION = '0.1.0' ;
2424const WILDCARD_VERSION = '*' ;
2525const MODULE_DIR = '/random/dir' ;
26+ const CORE_MODULE = 'random_core' ;
2627
2728class TestInstrumentation extends InstrumentationBase {
2829 constructor ( ) {
@@ -33,6 +34,61 @@ class TestInstrumentation extends InstrumentationBase {
3334}
3435
3536describe ( 'InstrumentationBase' , ( ) => {
37+ describe ( '_onRequire - core module' , ( ) => {
38+ let instrumentation : TestInstrumentation ;
39+ let modulePatchSpy : sinon . SinonSpy ;
40+ beforeEach ( ( ) => {
41+ instrumentation = new TestInstrumentation ( ) ;
42+ modulePatchSpy = sinon . spy ( ) ;
43+ } ) ;
44+
45+ describe ( 'AND module is not enabled' , ( ) => {
46+ it ( 'should not patch the module' , ( ) => {
47+ // @ts -expect-error access internal property for testing
48+ instrumentation . _enabled = false ;
49+ const moduleExports = { } ;
50+ const instrumentationModule = {
51+ name : CORE_MODULE ,
52+ patch : modulePatchSpy as unknown ,
53+ } as InstrumentationModuleDefinition < unknown > ;
54+
55+ // @ts -expect-error access internal property for testing
56+ instrumentation . _onRequire < unknown > (
57+ instrumentationModule ,
58+ moduleExports ,
59+ CORE_MODULE ,
60+ undefined
61+ ) ;
62+
63+ assert . strictEqual ( instrumentationModule . moduleExports , moduleExports ) ;
64+ sinon . assert . notCalled ( modulePatchSpy ) ;
65+ } ) ;
66+ } ) ;
67+
68+ describe ( 'AND module is enabled' , ( ) => {
69+ it ( 'should patch the module' , ( ) => {
70+ // @ts -expect-error access internal property for testing
71+ instrumentation . _enabled = true ;
72+ const moduleExports = { } ;
73+ const instrumentationModule = {
74+ name : CORE_MODULE ,
75+ patch : modulePatchSpy as unknown ,
76+ } as InstrumentationModuleDefinition < unknown > ;
77+
78+ // @ts -expect-error access internal property for testing
79+ instrumentation . _onRequire < unknown > (
80+ instrumentationModule ,
81+ moduleExports ,
82+ CORE_MODULE ,
83+ undefined
84+ ) ;
85+
86+ assert . strictEqual ( instrumentationModule . moduleExports , moduleExports ) ;
87+ sinon . assert . calledOnceWithExactly ( modulePatchSpy , moduleExports ) ;
88+ } ) ;
89+ } ) ;
90+ } ) ;
91+
3692 describe ( '_onRequire - module version is not available' , ( ) => {
3793 // For all of these cases, there is no indication of the actual module version,
3894 // so we require there to be a wildcard supported version.
0 commit comments