feat: add mocks for isolated-vm and whois-json modules in Jest configuration

This commit is contained in:
Nawaz Dhandala
2026-02-18 15:37:53 +00:00
parent a5e3e05f86
commit 7d6e81cb8b
3 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
// Mock for isolated-vm native module (not loadable in Jest)
export class Isolate {
public isDisposed: boolean = false;
public async createContext(): Promise<Context> {
return new Context();
}
public dispose(): void {
this.isDisposed = true;
}
}
export class Context {
public global: Reference = new Reference();
public async eval(_code: string, _options?: unknown): Promise<unknown> {
return undefined;
}
}
export class Reference {
public async set(_key: string, _value: unknown): Promise<void> {
return;
}
public derefInto(): unknown {
return {};
}
public applySync(
_receiver: unknown,
_args: unknown[],
): unknown {
return undefined;
}
public applySyncPromise(
_receiver: unknown,
_args: unknown[],
): Promise<unknown> {
return Promise.resolve(undefined);
}
}
export class Callback {
constructor(_fn: (...args: unknown[]) => void) {}
}
export class ExternalCopy {
constructor(_value: unknown) {}
public copyInto(): unknown {
return {};
}
}
export default {
Isolate,
Context,
Reference,
Callback,
ExternalCopy,
};

View File

@@ -0,0 +1,6 @@
// Mock for whois-json ESM module (not parseable by Jest)
const whoisJson = async (_domain: string): Promise<Record<string, unknown>> => {
return {};
};
export default whoisJson;

View File

@@ -12,6 +12,10 @@
"babelConfig": false
}
},
"moduleNameMapper": {
"isolated-vm": "<rootDir>/Tests/__mocks__/isolated-vm.ts",
"whois-json": "<rootDir>/Tests/__mocks__/whois-json.ts"
},
"moduleFileExtensions": ["ts", "js", "json"],
"transform": {
".(ts|tsx)": "ts-jest"