From c29e1288147aa73f068047e863632e65a0f2be88 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Sat, 5 Feb 2022 09:26:15 +0000 Subject: [PATCH] Core development --- core/application.mjs | 12 +++++------- test/application.run.test.mjs | 24 ++---------------------- test/core.test.mjs | 8 ++++++++ 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/core/application.mjs b/core/application.mjs index e1c85ec..8c4648d 100644 --- a/core/application.mjs +++ b/core/application.mjs @@ -289,15 +289,13 @@ export default class Application extends EventEmitter { if (version !== 'static') { let indexPath = this.ctx.util.getPathFromRoot(`./${this.name}/${version}/index.mjs`) await this.fs.stat(indexPath).catch((err) => { - return Promise.reject(new Error(`Application ${this.name} version ${version} was missing index.mjs: ${err.message}`)) - }) - let module = await import(this.ctx.util.getUrlFromRoot(`./${this.name}/${version}/index.mjs`)).catch((err) => { - return Promise.reject(new Error(`Application ${this.name} version ${version} failed to load index.mjs: ${err.message}`)) + return Promise.reject(new Error(`Version was missing index.mjs: ${err.message}`)) }) + let module = await import(this.ctx.util.getUrlFromRoot(`./${this.name}/${version}/index.mjs`)) this.registerModule(module, version) } - let errTimeout = new Error(`Application ${this.name} version ${version} timed out (took over ${this.config.startWaitUntilFail}ms) while running start()`) + let errTimeout = new Error(`Version timed out (took over ${this.config.startWaitUntilFail}ms) while running start()`) await new Promise((res, rej) => { setTimeout(() => { @@ -312,7 +310,7 @@ export default class Application extends EventEmitter { }) if (!this.http.active) { - return Promise.reject(new Error(`Application ${this.name} version ${version} did not call http.createServer()`)) + return Promise.reject(new Error(`Version did not call http.createServer()`)) } let lastErr = null @@ -326,7 +324,7 @@ export default class Application extends EventEmitter { } } - return Promise.reject(new Error(`Application ${this.name} version ${version} failed to start properly: ${lastErr.message}`)) + return Promise.reject(new Error(`Version failed to start properly: ${lastErr.message}`)) } closeServer() { diff --git a/test/application.run.test.mjs b/test/application.run.test.mjs index 96e4233..8d7c68c 100644 --- a/test/application.run.test.mjs +++ b/test/application.run.test.mjs @@ -60,8 +60,6 @@ t.describe('#runVersion("static")', function() { assert.match(err.message, /http/i) assert.match(err.message, /createServer/i) - assert.match(err.message, /static/) - assert.match(err.message, new RegExp(app.name)) assert.match(err.message, /call/i) assert.strictEqual(ctx.db.data.core.testapp.active, 'static') }) @@ -74,9 +72,7 @@ t.describe('#runVersion("static")', function() { assert.match(err.message, /time/i) assert.match(err.message, /out/i) - assert.match(err.message, /static/) assert.match(err.message, /50ms/) - assert.match(err.message, new RegExp(app.name)) assert.strictEqual(ctx.db.data.core.testapp.active, 'static') }) @@ -107,10 +103,7 @@ t.describe('#runVersion("static")', function() { app.registerModule(defaultHandler(handler)) let err = await assert.isRejected(app.runVersion('static')) - assert.match(err.message, /app/i) assert.match(err.message, /failed/i) - assert.match(err.message, /static/i) - assert.match(err.message, /testapp/i) assert.match(err.message, /400/i) assert.strictEqual(called, 3) assert.strictEqual(ctx.db.data.core.testapp.active, 'static') @@ -128,10 +121,7 @@ t.describe('#runVersion("static")', function() { let start = performance.now() let err = await assert.isRejected(app.runVersion('static')) let end = performance.now() - assert.match(err.message, /app/i) assert.match(err.message, /failed/i) - assert.match(err.message, /static/i) - assert.match(err.message, /testapp/i) assert.match(err.message, /time/i) assert.match(err.message, /out/i) assert.match(err.message, /30ms/i) @@ -154,10 +144,7 @@ t.describe('#runVersion("static")', function() { app.registerModule(defaultHandler(handler)) let err = await assert.isRejected(app.runVersion('static')) - assert.match(err.message, /app/i) assert.match(err.message, /failed/i) - assert.match(err.message, /static/i) - assert.match(err.message, /testapp/i) assert.match(err.message, /400/i) await app.http.closeServer() @@ -170,7 +157,7 @@ t.describe('#runVersion("static")', function() { }) }) -t.skip().describe('#runVersion("version")', function() { +t.describe('#runVersion("version")', function() { const assertConfig = util.getPathFromRoot('./db_test_applicationrun.json') const assertPort = 22345 let ctx @@ -220,8 +207,6 @@ t.skip().describe('#runVersion("version")', function() { assert.notStrictEqual(err, assertNotError) assert.match(err.message, new RegExp(assertNotError.message)) assert.match(err.message, /index\.mjs/i) - assert.match(err.message, /testnoexisting/i) - assert.match(err.message, /v100/i) assert.match(err.message, /missing/i) assert.strictEqual(stubFsStat.firstCall[0], assertTarget) @@ -237,10 +222,7 @@ t.skip().describe('#runVersion("version")', function() { let err = await assert.isRejected(app.runVersion('v99')) assert.notStrictEqual(err, assertError) - assert.match(err.message, new RegExp(assertError.message)) - assert.match(err.message, /testnoexisting/i) - assert.match(err.message, /v99/i) - assert.match(err.message, /index\.mjs/i) + assert.strictEqual(err.message, assertError.message) assert.strictEqual(app.ctx.db.data.core.testnoexisting.active, 'v99') let checkDb = await lowdb({}, ctx.log, assertConfig) @@ -252,8 +234,6 @@ t.skip().describe('#runVersion("version")', function() { await fs.writeFile(util.getPathFromRoot('./testnoexisting/v98/index.mjs'), ``) let err = await assert.isRejected(app.runVersion('v98')) - assert.match(err.message, /testnoexisting/i) - assert.match(err.message, /v98/i) assert.match(err.message, /start/i) assert.strictEqual(app.ctx.db.data.core.testnoexisting.active, 'v98') diff --git a/test/core.test.mjs b/test/core.test.mjs index 57a548b..1d4d111 100644 --- a/test/core.test.mjs +++ b/test/core.test.mjs @@ -363,3 +363,11 @@ t.describe('#init()', function() { assert.ok(application.provider instanceof FakeProvider) }) }) + +t.describe('#runApplication()', function() { + let core + + t.beforeEach(function() { + core = new Core(db, util, createFakeLog(), function() {}) + }) +})