Application: Expose some helper classes to application through ctx.sc
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded

This commit is contained in:
Jonatan Nilsson 2022-03-27 15:12:04 +00:00
parent 2edcedb1b7
commit 95d72fc404
4 changed files with 23 additions and 3 deletions

View file

@ -19,9 +19,7 @@ clone_depth: 1
build_cloud: Docker
environment:
APPVEYOR_SSH_KEY: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBRMxhawMlUlQ8l4pOaeHsZl8XDO54WQngkYM1U/XB4m samsyn\jonatan@JonatanAMD
docker_image: node:16-alpine
npm_config_cache: /appveyor/projects/cache
test_script:
- sh: |

View file

@ -6,6 +6,11 @@ import { request } from './client.mjs'
import HttpServer from './http.mjs'
import { defaults } from './defaults.mjs'
import Util from './util.mjs'
import bunyan from 'bunyan-lite'
import getLog from './log.mjs'
export default class Application extends EventEmitter {
constructor(ctx, provider, name, opts = {}) {
super()
@ -15,6 +20,13 @@ export default class Application extends EventEmitter {
log: ctx.log,
core: ctx.core,
app: this,
sc: {
Util: Util,
bunyan: bunyan,
getLog: getLog,
HttpServer: HttpServer,
request: request,
}
}
this.config = defaults({}, this.ctx.db.config[name])
this.provider = provider

View file

@ -1,6 +1,6 @@
{
"name": "service-core",
"version": "3.0.0-beta.9",
"version": "3.0.0-beta.10",
"description": "Core boiler plate code to install node server as windows service",
"main": "index.mjs",
"scripts": {

View file

@ -6,6 +6,11 @@ import Util from '../core/util.mjs'
import StaticProvider from '../core/providers/static.mjs'
import { createFakeContext } from './helpers.mjs'
import bunyan from 'bunyan-lite'
import HttpServer from '../core/http.mjs'
import { request } from '../core/client.mjs'
import getLog from '../core/log.mjs'
const util = new Util(import.meta.url)
const logger = {
@ -62,6 +67,11 @@ t.describe('constructor()', function() {
assert.strictEqual(app.ctx.db, ctx.db)
assert.strictEqual(app.ctx.app, app)
assert.strictEqual(app.ctx.util, ctx.util)
assert.strictEqual(app.ctx.sc.Util, Util)
assert.strictEqual(app.ctx.sc.bunyan, bunyan)
assert.strictEqual(app.ctx.sc.HttpServer, HttpServer)
assert.strictEqual(app.ctx.sc.request, request)
assert.strictEqual(app.ctx.sc.getLog, getLog)
assert.strictEqual(app.name, assertName)
assert.strictEqual(app.fresh, true)
assert.strictEqual(app.running, false)