From 95d72fc4047fcdb73cddfa4ba9474286e1242076 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Sun, 27 Mar 2022 15:12:04 +0000 Subject: [PATCH] Application: Expose some helper classes to application through ctx.sc --- appveyor.yml | 2 -- core/application.mjs | 12 ++++++++++++ package.json | 2 +- test/application.test.mjs | 10 ++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 8f6cbe7..617a5df 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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: | diff --git a/core/application.mjs b/core/application.mjs index 153ee34..0dd797c 100644 --- a/core/application.mjs +++ b/core/application.mjs @@ -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 diff --git a/package.json b/package.json index 7d3ce02..7a444ff 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/application.test.mjs b/test/application.test.mjs index cb2ebac..14180fe 100644 --- a/test/application.test.mjs +++ b/test/application.test.mjs @@ -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)