import { Eltro as t, assert, stub } from 'eltro' import * as sc from '../index.mjs' t.describe('', function() { const module = { start: stub() } t.beforeEach(function() { module.start.reset() }) t.test('should have ServiceCore defined', function() { assert.ok(sc.ServiceCore) }) t.test('constructor should work', function() { const assertAppName = 'Gondola' let core = new sc.ServiceCore(assertAppName, import.meta.url) assert.strictEqual(core.util._root_import_meta_url, import.meta.url) assert.strictEqual(core.name, assertAppName) }) t.test('should support proper init', async function() { const assertAppName = 'Hero Combat' let core = new sc.ServiceCore(assertAppName, import.meta.url) await core.init(module) assert.strictEqual(core.app.name, assertAppName) assert.strictEqual(core.app.module, module) }) t.test('should call module start', async function() { const assertError = new Error('Inbo') module.start.rejects(assertError) let core = new sc.ServiceCore('testapp', import.meta.url) await core.init(module) let err = await assert.isRejected(core.run()) assert.strictEqual(err, assertError) assert.strictEqual(module.start.firstCall[0], core.app.http) assert.strictEqual(module.start.firstCall[1], null) assert.strictEqual(module.start.firstCall[2], core.app.ctx) }) t.test('should support overwriting config', async function() { const assertError = new Error('Inbo') const assertPort = 9382 module.start.rejects(assertError) let core = new sc.ServiceCore('testapp', import.meta.url) core.setConfig({ port: assertPort }) await core.init(module) let err = await assert.isRejected(core.run()) assert.strictEqual(err, assertError) assert.strictEqual(module.start.firstCall[0], core.app.http) assert.strictEqual(module.start.firstCall[1], assertPort) assert.strictEqual(module.start.firstCall[2], core.app.ctx) }) })