lib: Now generates a valid config and enforces provider on lib to be static
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded

This commit is contained in:
Jonatan Nilsson 2022-03-27 16:02:53 +00:00
parent 95d72fc404
commit 99d7a0655d
3 changed files with 17 additions and 2 deletions

View file

@ -15,7 +15,10 @@ export default class ServiceCore {
this.dbfilename = dbfilename this.dbfilename = dbfilename
this.log = getLog(name) this.log = getLog(name)
this.name = name this.name = name
this.config = {} this.config = {
name: name,
title: 'Development Version of ' + name,
}
this.db = null this.db = null
this.core = null this.core = null
this.app = null this.app = null
@ -26,6 +29,9 @@ export default class ServiceCore {
} }
setConfig(config) { setConfig(config) {
if (!config.provider) {
config.provider = 'static'
}
this.config[this.name] = config this.config[this.name] = config
} }
@ -41,6 +47,9 @@ export default class ServiceCore {
core: this.core, core: this.core,
}, provider, this.name) }, provider, this.name)
this.app.registerModule(module) this.app.registerModule(module)
this.core.applications.push(this.app)
this.core.applicationMap.set(this.name, this.app)
} }
run() { run() {

View file

@ -1,6 +1,6 @@
{ {
"name": "service-core", "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", "description": "Core boiler plate code to install node server as windows service",
"main": "index.mjs", "main": "index.mjs",
"scripts": { "scripts": {

View file

@ -26,6 +26,10 @@ t.describe('', function() {
let core = new sc.ServiceCore(assertAppName, import.meta.url) let core = new sc.ServiceCore(assertAppName, import.meta.url)
await core.init(module) 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.name, assertAppName)
assert.strictEqual(core.app.module, module) assert.strictEqual(core.app.module, module)
}) })
@ -73,6 +77,8 @@ t.describe('', function() {
let err = await assert.isRejected(core.run()) let err = await assert.isRejected(core.run())
assert.strictEqual(err, assertError) 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[0], core.app.http)
assert.strictEqual(module.start.firstCall[1], assertPort) assert.strictEqual(module.start.firstCall[1], assertPort)
assert.strictEqual(module.start.firstCall[2], core.app.ctx) assert.strictEqual(module.start.firstCall[2], core.app.ctx)