Skip to content

Commit 5788a7e

Browse files
committed
test: mocking
1 parent d38017e commit 5788a7e

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

package-lock.json

Lines changed: 25 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
"proxyquire": "^2.1.3",
227227
"read-pkg-up": "^7.0.1",
228228
"recursive-copy": "^2.0.14",
229-
"redis": "^5.0.0",
229+
"redis": "^5.0.1",
230230
"redis-v3": "npm:redis@^3.1.2",
231231
"redis-v4": "npm:redis@^4.7.0",
232232
"restify": "^11.1.0",

packages/collector/test/tracing/database/redis/mockVersion.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66

77
const mock = require('@instana/core/test/test_util/mockRequire');
8+
const hook = require('../../../../../core/src/util/hook');
89

910
const REDIS_PKG = process.env.REDIS_PKG;
1011
const REDIS_VERSION = process.env.REDIS_VERSION;
@@ -23,3 +24,24 @@ if (REDIS_PKG === 'redis') {
2324
if (mockedModuleName !== REDIS_PKG) {
2425
mock(REDIS_PKG, mockedModuleName);
2526
}
27+
28+
const originalOnFileLoad = hook.onFileLoad;
29+
30+
hook.onFileLoad = function onFileLoad() {
31+
const source = arguments[0]?.source;
32+
33+
if (
34+
mockedModuleName.startsWith('@redis/client') &&
35+
(source === '\\/@redis\\/client\\/dist\\/lib\\/commands\\/index.js' ||
36+
source === '\\/@redis\\/client\\/dist\\/lib\\/cluster\\/commands.js')
37+
) {
38+
const updatedSource = source.replace('@redis\\/client', mockedModuleName);
39+
40+
const regex = new RegExp(updatedSource);
41+
arguments[0] = regex;
42+
43+
return originalOnFileLoad.apply(this, arguments);
44+
}
45+
46+
return originalOnFileLoad.apply(this, arguments);
47+
};

0 commit comments

Comments
 (0)