From a3dac50337bbd9fbaa761e8dd2e13b0b4d9a9bb6 Mon Sep 17 00:00:00 2001 From: matthyk <53833818+matthyk@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:18:13 +0100 Subject: [PATCH] add and update tests --- test/decorator.test.js | 25 ++++++++++++++++--------- test/fixture/app-no-source.json | 11 +++++++---- test/fixture/app-source.json | 5 ++++- test/fixture/autoload.json | 11 ++++++++++- test/index.test.js | 16 ++++++++-------- 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/test/decorator.test.js b/test/decorator.test.js index 1df9c55..bb92b1b 100644 --- a/test/decorator.test.js +++ b/test/decorator.test.js @@ -13,8 +13,14 @@ test('decorator', async t => { app.decorateRequest('root-req-two', function () {}) app.decorateReply('root-reply', function () {}) + app.decorate('root-symbol', Symbol('testSymbol')) + app.decorateReply('root-reply-array', []) + app.decorateRequest('root-req-boolean', true) + app.register(function register1 (instance, opts, next) { instance.decorateRequest('child-1', 42) + instance.decorate('child-1-bigint', BigInt(1)) + instance.decorate('child-1-undefined') instance.register(function register2 (sub, opts, next) { sub.decorateReply('sub', 42) next() @@ -22,6 +28,7 @@ test('decorator', async t => { instance.register(function register3 (sub, opts, next) { sub.decorate('sub-instance', 50) sub.decorateReply('sub', 50) + sub.decorateRequest('sub-object', {}) next() }) next() @@ -36,23 +43,23 @@ test('decorator', async t => { t.equal(root.children.length, 2) t.equal(root.children[0].name, 'register1') t.equal(root.children[1].name, 'sibling') - t.same(root.decorators.decorate, [{ name: 'root-func' }]) - t.same(root.decorators.decorateRequest, [{ name: 'root-req' }, { name: 'root-req-two' }]) - t.same(root.decorators.decorateReply, [{ name: 'root-reply' }]) + t.same(root.decorators.decorate, [{ name: 'root-func', type: 'function' }, { name: 'root-symbol', type: 'symbol' }]) + t.same(root.decorators.decorateRequest, [{ name: 'root-req', type: 'function' }, { name: 'root-req-two', type: 'function' }, { name: 'root-req-boolean', type: 'boolean' }]) + t.same(root.decorators.decorateReply, [{ name: 'root-reply', type: 'function' }, { name: 'root-reply-array', type: 'array' }]) const reg1 = root.children[0] - t.same(reg1.decorators.decorate, []) - t.same(reg1.decorators.decorateRequest, [{ name: 'child-1' }]) + t.same(reg1.decorators.decorate, [{ name: 'child-1-bigint', type: 'bigint' }, { name: 'child-1-undefined', type: 'undefined' }]) + t.same(reg1.decorators.decorateRequest, [{ name: 'child-1', type: 'number' }]) t.same(reg1.decorators.decorateReply, []) t.equal(reg1.children.length, 2) const reg2 = reg1.children[0] t.same(reg2.decorators.decorate, []) t.same(reg2.decorators.decorateRequest, []) - t.same(reg2.decorators.decorateReply, [{ name: 'sub' }]) + t.same(reg2.decorators.decorateReply, [{ name: 'sub', type: 'number' }]) const reg3 = reg1.children[1] - t.same(reg3.decorators.decorate, [{ name: 'sub-instance' }]) - t.same(reg3.decorators.decorateRequest, []) - t.same(reg3.decorators.decorateReply, [{ name: 'sub' }]) + t.same(reg3.decorators.decorate, [{ name: 'sub-instance', type: 'number' }]) + t.same(reg3.decorators.decorateRequest, [{ name: 'sub-object', type: 'object' }]) + t.same(reg3.decorators.decorateReply, [{ name: 'sub', type: 'number' }]) }) diff --git a/test/fixture/app-no-source.json b/test/fixture/app-no-source.json index dd264f2..d50f3c0 100644 --- a/test/fixture/app-no-source.json +++ b/test/fixture/app-no-source.json @@ -288,17 +288,20 @@ "decorators": { "decorate": [ { - "name": "decorApp" + "name": "decorApp", + "type": "string" } ], "decorateRequest": [ { - "name": "decorApp" + "name": "decorApp", + "type": "string" } ], "decorateReply": [ { - "name": "decorApp" + "name": "decorApp", + "type": "string" } ] }, @@ -325,4 +328,4 @@ "onRoute": [], "onRegister": [] } -} \ No newline at end of file +} diff --git a/test/fixture/app-source.json b/test/fixture/app-source.json index 514f36c..86b2cf5 100644 --- a/test/fixture/app-source.json +++ b/test/fixture/app-source.json @@ -459,6 +459,7 @@ "decorate": [ { "name": "decorApp", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/app.js", @@ -474,6 +475,7 @@ "decorateRequest": [ { "name": "decorApp", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/app.js", @@ -489,6 +491,7 @@ "decorateReply": [ { "name": "decorApp", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/app.js", @@ -535,4 +538,4 @@ "onRoute": [], "onRegister": [] } -} \ No newline at end of file +} diff --git a/test/fixture/autoload.json b/test/fixture/autoload.json index db489f0..c2a6950 100644 --- a/test/fixture/autoload.json +++ b/test/fixture/autoload.json @@ -73,6 +73,7 @@ "decorate": [ { "name": "fileTwo", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/file-two.js", @@ -88,6 +89,7 @@ "decorateRequest": [ { "name": "fileTwo", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/file-two.js", @@ -103,6 +105,7 @@ "decorateReply": [ { "name": "fileTwo", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/file-two.js", @@ -224,6 +227,7 @@ "decorate": [ { "name": "fileOne", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/autoload/file-one.js", @@ -239,6 +243,7 @@ "decorateRequest": [ { "name": "fileOne", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/autoload/file-one.js", @@ -254,6 +259,7 @@ "decorateReply": [ { "name": "fileOne", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/autoload/file-one.js", @@ -969,6 +975,7 @@ "decorate": [ { "name": "decorApp", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/autoload.js", @@ -984,6 +991,7 @@ "decorateRequest": [ { "name": "decorApp", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/autoload.js", @@ -999,6 +1007,7 @@ "decorateReply": [ { "name": "decorApp", + "type": "string", "source": { "stackIndex": 0, "fileName": "test/sources/autoload.js", @@ -1045,4 +1054,4 @@ "onRoute": [], "onRegister": [] } -} \ No newline at end of file +} diff --git a/test/index.test.js b/test/index.test.js index ac8a541..d94ef19 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -43,9 +43,9 @@ test('basic test', async t => { t.type(structure.id, 'number') t.equal(structure.children.length, 3) t.same(structure.decorators.decorate, [ - { name: 'test' }, - { name: 'testObject' }, - { name: 'testArray' } + { name: 'test', type: 'function' }, + { name: 'testObject', type: 'object' }, + { name: 'testArray', type: 'array' } ]) t.same(structure.hooks, require('./fixture/index.00.json')) }) @@ -76,7 +76,7 @@ test('register', async t => { t.equal(root.children.length, 1) t.equal(root.children[0].name, 'register1') - t.same(root.decorators.decorate, [{ name: 'foo-bar' }]) + t.same(root.decorators.decorate, [{ name: 'foo-bar', type: 'function' }]) t.equal(root.hooks.onRequest.length, 0) t.equal(root.hooks.preParsing.length, 0) t.equal(root.hooks.preValidation.length, 0) @@ -121,11 +121,11 @@ test('hide empty', async t => { t.strictSame(structure.decorators, { decorate: [ - { name: 'emptyObject' }, - { name: 'emptyArray' } + { name: 'emptyObject', type: 'object' }, + { name: 'emptyArray', type: 'array' } ], decorateRequest: [ - { name: 'oneReqDecor' } + { name: 'oneReqDecor', type: 'array' } ] }) @@ -145,7 +145,7 @@ test('hide empty', async t => { t.strictSame(structure.children[1].children[0].decorators, { decorateReply: [ - { name: 'oneRep' } + { name: 'oneRep', type: 'object' } ] }) })