From feba3dd2d236087e0badf84018055f25c533bcb9 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Tue, 13 Oct 2020 14:21:19 +0530 Subject: [PATCH] test: cover repl binding and health check registration cases --- npm-audit.html | 2 +- package-lock.json | 101 ++++++++++++++++++++++++++++++++++++ package.json | 1 + providers/RedisProvider.ts | 5 +- src/Bindings/Repl.ts | 5 +- test/redis-provider.spec.ts | 45 +++++++++++++--- tsconfig.json | 6 +-- 7 files changed, 149 insertions(+), 16 deletions(-) diff --git a/npm-audit.html b/npm-audit.html index 05f5f70..8b54da7 100644 --- a/npm-audit.html +++ b/npm-audit.html @@ -55,7 +55,7 @@
- October 13th 2020, 8:41:38 am + October 13th 2020, 8:51:20 am

Last updated

diff --git a/package-lock.json b/package-lock.json index c9b4924..c8399b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -201,6 +201,18 @@ "jest-worker": "^26.5.0" } }, + "@adonisjs/repl": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@adonisjs/repl/-/repl-1.1.2.tgz", + "integrity": "sha512-W47cEhC/yB3W3+RHLrmV8DPMTGVGHvb1IR1jU2mxZNYibmFimbPkNn8T3a9+AkQPBKlaqUPenp97J2ErrCetog==", + "dev": true, + "requires": { + "@poppinss/colors": "^2.0.3", + "node-repl-await": "^0.1.1", + "parse-imports": "0.0.4", + "string-width": "^4.2.0" + } + }, "@adonisjs/require-ts": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@adonisjs/require-ts/-/require-ts-1.0.4.tgz", @@ -880,12 +892,57 @@ "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "dev": true }, + "acorn-class-fields": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/acorn-class-fields/-/acorn-class-fields-0.3.7.tgz", + "integrity": "sha512-jdUWSFce0fuADUljmExz4TWpPkxmRW/ZCPRqeeUzbGf0vFUcpQYbyq52l75qGd0oSwwtAepeL6hgb/naRgvcKQ==", + "dev": true, + "requires": { + "acorn-private-class-elements": "^0.2.7" + } + }, "acorn-jsx": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", "dev": true }, + "acorn-numeric-separator": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/acorn-numeric-separator/-/acorn-numeric-separator-0.3.6.tgz", + "integrity": "sha512-jUr5esgChu4k7VzesH/Nww3EysuyGJJcTEEiXqILUFKpO96PNyEXmK21M6nE0TSqGA1PeEg1MzgqJaoFsn9JMw==", + "dev": true + }, + "acorn-private-class-elements": { + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/acorn-private-class-elements/-/acorn-private-class-elements-0.2.7.tgz", + "integrity": "sha512-+GZH2wOKNZOBI4OOPmzpo4cs6mW297sn6fgIk1dUI08jGjhAaEwvC39mN2gJAg2lmAQJ1rBkFqKWonL3Zz6PVA==", + "dev": true + }, + "acorn-private-methods": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/acorn-private-methods/-/acorn-private-methods-0.3.3.tgz", + "integrity": "sha512-46oeEol3YFvLSah5m9hGMlNpxDBCEkdceJgf01AjqKYTK9r6HexKs2rgSbLK81pYjZZMonhftuUReGMlbbv05w==", + "dev": true, + "requires": { + "acorn-private-class-elements": "^0.2.7" + } + }, + "acorn-static-class-features": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/acorn-static-class-features/-/acorn-static-class-features-0.2.4.tgz", + "integrity": "sha512-5X4mpYq5J3pdndLmIB0+WtFd/mKWnNYpuTlTzj32wUu/PMmEGOiayQ5UrqgwdBNiaZBtDDh5kddpP7Yg2QaQYA==", + "dev": true, + "requires": { + "acorn-private-class-elements": "^0.2.7" + } + }, + "acorn-walk": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-6.2.0.tgz", + "integrity": "sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==", + "dev": true + }, "aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", @@ -2529,6 +2586,12 @@ "is-arrayish": "^0.2.1" } }, + "es-module-lexer": { + "version": "0.3.20", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-0.3.20.tgz", + "integrity": "sha512-kfB4R9F6FJ5Bgvxyk6W/u/a9cncXEGRyaD2UxyBhrF3+ty4qLzptgStLfe0J90o/qkSiiY0+yyzMcIIPvAOjIw==", + "dev": true + }, "escape-goat": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", @@ -5699,6 +5762,28 @@ "integrity": "sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA=", "dev": true }, + "node-repl-await": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/node-repl-await/-/node-repl-await-0.1.1.tgz", + "integrity": "sha512-ZtYMsRzhmWURZfjSrlhQcSz0+tLIiiz16SNzxm2e1ZuDRfM7vB9h8PPM5YcX/2sQAQpttp0vAIm8jTYNSfXhKA==", + "dev": true, + "requires": { + "acorn": "^6.3.0", + "acorn-class-fields": "^0.3.1", + "acorn-numeric-separator": "^0.3.0", + "acorn-private-methods": "^0.3.0", + "acorn-static-class-features": "^0.2.0", + "acorn-walk": "^6.2.0" + }, + "dependencies": { + "acorn": { + "version": "6.4.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.2.tgz", + "integrity": "sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ==", + "dev": true + } + } + }, "node.extend": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/node.extend/-/node.extend-2.0.2.tgz", @@ -6506,6 +6591,16 @@ "integrity": "sha512-kgBf6avCbO3Cn6+RnzRGLkUsv4ZVqv/VfAYkRsyBcgkshNvVBkRn1FEZcW0Jb+npXQWm2vHPnnOqFteZxRRGNw==", "dev": true }, + "parse-imports": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/parse-imports/-/parse-imports-0.0.4.tgz", + "integrity": "sha512-OtnpkarQMGlMEJ5Q4GZMlMwTGNddzjdU90rmBRSz0bckoS/KQe4/kbvkr9+p0CyoEbqv1znU208uOHJKJxJRLw==", + "dev": true, + "requires": { + "es-module-lexer": "0.3.20", + "slashes": "2.0.2" + } + }, "parse-json": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.1.0.tgz", @@ -7437,6 +7532,12 @@ "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true }, + "slashes": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/slashes/-/slashes-2.0.2.tgz", + "integrity": "sha512-68p+QkFAQQRetIUzNXAdktNJr8AYLxJukjBegYQz8F7VATsBJG621UYtY/vS2j9jerxdJ1k6Tc25K4DXEw1d5w==", + "dev": true + }, "slice-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", diff --git a/package.json b/package.json index 570e88f..2546540 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "devDependencies": { "@adonisjs/core": "^5.0.2-beta-rc-6", "@adonisjs/mrm-preset": "^2.4.0", + "@adonisjs/repl": "^1.1.2", "@adonisjs/require-ts": "^1.0.4", "@poppinss/dev-utils": "^1.0.11", "@types/node": "^14.11.8", diff --git a/providers/RedisProvider.ts b/providers/RedisProvider.ts index 6048126..1433637 100644 --- a/providers/RedisProvider.ts +++ b/providers/RedisProvider.ts @@ -50,7 +50,10 @@ export default class RedisProvider { return } - require('../src/Bindings/Repl')(this.app) + this.app.container.with(['Adonis/Addons/Repl'], (Repl) => { + const { defineReplBindings } = require('../src/Bindings/Repl') + defineReplBindings(this.app, Repl) + }) } /** diff --git a/src/Bindings/Repl.ts b/src/Bindings/Repl.ts index 243edd8..13cedf5 100644 --- a/src/Bindings/Repl.ts +++ b/src/Bindings/Repl.ts @@ -7,15 +7,14 @@ * file that was distributed with this source code. */ +import { ReplContract } from '@ioc:Adonis/Addons/Repl' import { ApplicationContract } from '@ioc:Adonis/Core/Application' /** * Defune repl bindings. The method must be invoked when application environment * is set to repl. */ -export default function defineReplBindings(application: ApplicationContract) { - const Repl = application.container.use('Adonis/Addons/Repl') - +export function defineReplBindings(application: ApplicationContract, Repl: ReplContract) { Repl.addMethod( 'loadRedis', (repl) => { diff --git a/test/redis-provider.spec.ts b/test/redis-provider.spec.ts index fdf111a..b69e0ad 100644 --- a/test/redis-provider.spec.ts +++ b/test/redis-provider.spec.ts @@ -16,7 +16,7 @@ import { RedisManager } from '../src/RedisManager' const fs = new Filesystem(join(__dirname, 'app')) -async function setup(redisConfig: any) { +async function setup(environment: 'web' | 'repl', redisConfig: any) { await fs.add('.env', '') await fs.add( 'config/app.ts', @@ -37,8 +37,8 @@ async function setup(redisConfig: any) { ` ) - const app = new Application(fs.basePath, 'web', { - providers: ['@adonisjs/core', '../../providers/RedisProvider'], + const app = new Application(fs.basePath, environment, { + providers: ['@adonisjs/core', '@adonisjs/repl', '../../providers/RedisProvider'], }) app.setup() @@ -54,7 +54,7 @@ test.group('Redis Provider', (group) => { }) test('register redis provider', async (assert) => { - const app = await setup({ + const app = await setup('web', { connection: 'local', connections: { local: {}, @@ -72,7 +72,7 @@ test.group('Redis Provider', (group) => { assert.plan(1) try { - await setup({}) + await setup('web', {}) } catch (error) { assert.equal( error.message, @@ -85,7 +85,7 @@ test.group('Redis Provider', (group) => { assert.plan(1) try { - await setup({}) + await setup('web', {}) } catch (error) { assert.equal( error.message, @@ -98,7 +98,7 @@ test.group('Redis Provider', (group) => { assert.plan(1) try { - await setup({ + await setup('web', { connection: 'local', }) } catch (error) { @@ -113,7 +113,7 @@ test.group('Redis Provider', (group) => { assert.plan(1) try { - await setup({ + await setup('web', { connection: 'local', connections: {}, }) @@ -124,4 +124,33 @@ test.group('Redis Provider', (group) => { ) } }) + + test('define repl bindings', async (assert) => { + const app = await setup('repl', { + connection: 'local', + connections: { + local: {}, + }, + }) + + assert.property(app.container.use('Adonis/Addons/Repl')['customMethods'], 'loadRedis') + assert.isFunction(app.container.use('Adonis/Addons/Repl')['customMethods']['loadRedis'].handler) + }) + + test('define health checks', async (assert) => { + const app = await setup('web', { + connection: 'local', + connections: { + local: { + healthCheck: true, + }, + }, + }) + + assert.property(app.container.use('Adonis/Core/HealthCheck')['healthCheckers'], 'redis') + assert.equal( + app.container.use('Adonis/Core/HealthCheck')['healthCheckers'].redis, + 'Adonis/Addons/Redis' + ) + }) }) diff --git a/tsconfig.json b/tsconfig.json index 188db21..aa93a1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "extends": "./node_modules/@adonisjs/mrm-preset/_tsconfig", "compilerOptions": { "esModuleInterop": true, - "skipLibCheck": true - }, - "files": ["./node_modules/@adonisjs/core/build/adonis-typings/index.d.ts"] + "skipLibCheck": true, + "types": ["@adonisjs/core", "@adonisjs/repl", "@types/node"] + } }