mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
fix(core): Fix supportedNodes for non-lazy loaded community packages (no-changelog) (#11329)
This commit is contained in:
committed by
GitHub
parent
1c52bf9362
commit
2d36b42798
52
packages/core/test/ClassLoader.test.ts
Normal file
52
packages/core/test/ClassLoader.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import vm from 'vm';
|
||||
|
||||
import { loadClassInIsolation } from '@/ClassLoader';
|
||||
|
||||
describe('ClassLoader', () => {
|
||||
const filePath = '/path/to/TestClass.js';
|
||||
const className = 'TestClass';
|
||||
|
||||
class TestClass {
|
||||
getValue(): string {
|
||||
return 'test value';
|
||||
}
|
||||
}
|
||||
|
||||
jest.spyOn(vm, 'createContext').mockReturnValue({});
|
||||
|
||||
const runInContext = jest.fn().mockImplementation(() => new TestClass());
|
||||
const scriptSpy = jest.spyOn(vm, 'Script').mockImplementation(function (this: vm.Script) {
|
||||
this.runInContext = runInContext;
|
||||
return this;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should create script with correct require statement', () => {
|
||||
const instance = loadClassInIsolation<TestClass>(filePath, className);
|
||||
|
||||
expect(scriptSpy).toHaveBeenCalledWith(`new (require('${filePath}').${className})()`);
|
||||
expect(instance.getValue()).toBe('test value');
|
||||
});
|
||||
|
||||
it('should handle Windows-style paths', () => {
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, 'platform', { value: 'win32' });
|
||||
|
||||
loadClassInIsolation('/path\\to\\TestClass.js', 'TestClass');
|
||||
|
||||
expect(scriptSpy).toHaveBeenCalledWith(`new (require('${filePath}').${className})()`);
|
||||
|
||||
Object.defineProperty(process, 'platform', { value: originalPlatform });
|
||||
});
|
||||
|
||||
it('should throw error when script execution fails', () => {
|
||||
runInContext.mockImplementationOnce(() => {
|
||||
throw new Error('Script execution failed');
|
||||
});
|
||||
|
||||
expect(() => loadClassInIsolation(filePath, className)).toThrow('Script execution failed');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user