From 98716396308bcddee8e82ac1b26176fb85eb5dfe Mon Sep 17 00:00:00 2001 From: Annosha Date: Wed, 16 Oct 2024 12:23:20 +0500 Subject: [PATCH] Added local test pkg --- .../node/RequireInTheMiddleSingleton.test.ts | 28 +++++++++---------- .../test-non-core-module/index.js | 4 +++ .../test-non-core-module/lib/copy-sync.js | 5 ++++ 3 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/index.js create mode 100644 experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/lib/copy-sync.js diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/RequireInTheMiddleSingleton.test.ts b/experimental/packages/opentelemetry-instrumentation/test/node/RequireInTheMiddleSingleton.test.ts index 75cd0ad6282..1f8b45ef01c 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/node/RequireInTheMiddleSingleton.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/node/RequireInTheMiddleSingleton.test.ts @@ -39,8 +39,8 @@ describe('RequireInTheMiddleSingleton', () => { const onRequireFsPromisesStub = makeOnRequiresStub('fs-promises'); const onRequireCodecovStub = makeOnRequiresStub('codecov'); const onRequireCodecovLibStub = makeOnRequiresStub('codecov-lib'); - const onRequireCpxStub = makeOnRequiresStub('cpx2'); - const onRequireCpxLibStub = makeOnRequiresStub('cpx2-lib'); + const onRequireCpxStub = makeOnRequiresStub('test-non-core-module'); + const onRequireCpxLibStub = makeOnRequiresStub('test-non-core-module-lib'); before(() => { requireInTheMiddleSingleton.register('fs', onRequireFsStub); @@ -53,9 +53,9 @@ describe('RequireInTheMiddleSingleton', () => { 'codecov/lib/codecov.js', onRequireCodecovLibStub ); - requireInTheMiddleSingleton.register('cpx2', onRequireCpxStub); + requireInTheMiddleSingleton.register('test-non-core-module', onRequireCpxStub); requireInTheMiddleSingleton.register( - 'cpx2/lib/copy-sync.js', + 'test-non-core-module/lib/copy-sync.js', onRequireCpxLibStub ); }); @@ -120,8 +120,8 @@ describe('RequireInTheMiddleSingleton', () => { describe('non-core module', () => { describe('AND module name matches', () => { - const baseDir = path.dirname(require.resolve('codecov')); - const modulePath = path.join('codecov', 'lib', 'codecov.js'); + const baseDir = path.normalize(path.dirname(require.resolve('codecov'))); + const modulePath = path.normalize(path.join('codecov', 'lib', 'codecov.js')); it('should call `onRequire`', () => { const exports = require('codecov'); assert.deepStrictEqual(exports.__ritmOnRequires, ['codecov']); @@ -149,20 +149,20 @@ describe('RequireInTheMiddleSingleton', () => { describe('non-core module with sub-path', () => { describe('AND module name matches', () => { - const baseDir = path.resolve( - path.dirname(require.resolve('cpx2')), + const baseDir = path.normalize(path.resolve( + path.dirname(require.resolve('test-non-core-module')), '..' - ); - const modulePath = path.join('cpx2', 'lib', 'copy-sync.js'); + )); + const modulePath = path.normalize(path.join('test-non-core-module', 'lib', 'copy-sync.js')); it('should call `onRequire`', () => { - const exports = require('cpx2/lib/copy-sync'); + const exports = require('test-non-core-module/lib/copy-sync'); assert.deepStrictEqual(exports.__ritmOnRequires, [ - 'cpx2', - 'cpx2-lib', + 'test-non-core-module', + 'test-non-core-module-lib', ]); sinon.assert.calledWithMatch( onRequireCpxStub, - { __ritmOnRequires: ['cpx2', 'cpx2-lib'] }, + { __ritmOnRequires: ['test-non-core-module', 'test-non-core-module-lib'] }, modulePath, baseDir ); diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/index.js b/experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/index.js new file mode 100644 index 00000000000..8fc30cc603a --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/index.js @@ -0,0 +1,4 @@ +module.exports = { + copy: require('./copy-sync') + }; + \ No newline at end of file diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/lib/copy-sync.js b/experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/lib/copy-sync.js new file mode 100644 index 00000000000..a64ae2e0d46 --- /dev/null +++ b/experimental/packages/opentelemetry-instrumentation/test/node/node_modules/test-non-core-module/lib/copy-sync.js @@ -0,0 +1,5 @@ +module.exports = function copySync() { + // No-op function simulating cpx2 behavior for tests + console.log('Mock copySync called'); + }; + \ No newline at end of file