dev(test): enable use of TestKernel in unit tests

This commit is contained in:
KernelDeimos
2025-11-24 21:46:22 -05:00
committed by Eric Dubé
parent 001e174b81
commit 8a05b65ff3
3 changed files with 56 additions and 1 deletions

View File

@@ -0,0 +1,12 @@
const BaseService = require('./BaseService');
/**
* TestService is a service for testing in the sense that it is a service
* that exists for the purpose of being testing or to be used for testing
* purposes. However, TestService is not a service that's meant to hold
* utility functions for testing.
*/
class TestService extends BaseService {
}
module.exports = { TestService };

View File

@@ -0,0 +1,37 @@
import { describe, expect, it } from 'vitest';
import { TestKernel } from '../../tools/test.js';
import { Core2Module } from '../modules/core/Core2Module.js';
import { WebModule } from '../modules/web/WebModule.js';
import { TestService } from './TestService.js';
describe('testing with TestKernel', () => {
it('can load TestService within TestKernel', () => {
const testKernel = new TestKernel();
testKernel.add_module({
install: (context) => {
const services = context.get('services');
services.registerService('test', TestService);
},
});
testKernel.boot();
const svc_test = testKernel.services?.get('test');
expect(svc_test).toBeInstanceOf(TestService);
});
it('can load CoreModule within TestKernel', async () => {
const testKernel = new TestKernel();
testKernel.add_module(new Core2Module());
testKernel.add_module(new WebModule());
testKernel.boot();
const { services } = testKernel;
await services.ready;
const svc_webServer = services?.get('web-server');
expect(svc_webServer.constructor.name).toBe('WebServerService');
});
});

View File

@@ -264,4 +264,10 @@ const main = async () => {
process.exit(total_failed ? 1 : 0);
};
main();
if ( require.main === module ) {
main();
}
module.exports = {
TestKernel,
};