From 99d7a0655deb0b0c25d2b19be981c3ee681cef37 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Sun, 27 Mar 2022 16:02:53 +0000 Subject: [PATCH] lib: Now generates a valid config and enforces provider on lib to be static --- core/lib.mjs | 11 ++++++++++- package.json | 2 +- test/lib.test.mjs | 6 ++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/lib.mjs b/core/lib.mjs index 5625af3..38bd080 100644 --- a/core/lib.mjs +++ b/core/lib.mjs @@ -15,7 +15,10 @@ export default class ServiceCore { this.dbfilename = dbfilename this.log = getLog(name) this.name = name - this.config = {} + this.config = { + name: name, + title: 'Development Version of ' + name, + } this.db = null this.core = null this.app = null @@ -26,6 +29,9 @@ export default class ServiceCore { } setConfig(config) { + if (!config.provider) { + config.provider = 'static' + } this.config[this.name] = config } @@ -41,6 +47,9 @@ export default class ServiceCore { core: this.core, }, provider, this.name) this.app.registerModule(module) + + this.core.applications.push(this.app) + this.core.applicationMap.set(this.name, this.app) } run() { diff --git a/package.json b/package.json index 7a444ff..dd208fa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "service-core", - "version": "3.0.0-beta.10", + "version": "3.0.0-beta.11", "description": "Core boiler plate code to install node server as windows service", "main": "index.mjs", "scripts": { diff --git a/test/lib.test.mjs b/test/lib.test.mjs index b97a7d5..8d177af 100644 --- a/test/lib.test.mjs +++ b/test/lib.test.mjs @@ -26,6 +26,10 @@ t.describe('', function() { let core = new sc.ServiceCore(assertAppName, import.meta.url) await core.init(module) + assert.strictEqual(core.core.applications.length, 1) + assert.strictEqual(core.core.applications[0], core.app) + assert.strictEqual(core.core.applicationMap.size, 1) + assert.strictEqual(core.core.applicationMap.get(assertAppName), core.app) assert.strictEqual(core.app.name, assertAppName) assert.strictEqual(core.app.module, module) }) @@ -73,6 +77,8 @@ t.describe('', function() { let err = await assert.isRejected(core.run()) assert.strictEqual(err, assertError) + assert.strictEqual(core.config['testapp'].port, assertPort) + assert.strictEqual(core.config['testapp'].provider, 'static') 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)