diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index f2975fd..d25902d 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -7,7 +7,7 @@ on: jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4ade78e..b66e480 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,11 @@ jobs: - name: Run tests run: npm run test:coverage + env: + SLACK_URL: ${{ secrets.SLACK_URL }} + DISCORD_URL: ${{ secrets.DISCORD_URL }} + TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} - name: Test code transpilation run: npm run build diff --git a/bin/build.ts b/bin/build.ts index 703d43e..2a664c8 100644 --- a/bin/build.ts +++ b/bin/build.ts @@ -27,9 +27,7 @@ const path = Path.nodeModules('@athenna/tsconfig.build.json') | Create the tsconfig file for building the project. */ -const tsconfig = JSON.parse( - new File('../tsconfig.json').getContentSync().toString(), -) +const tsconfig = await new File('../tsconfig.json').getContentAsJson() delete tsconfig['ts-node'] @@ -39,8 +37,6 @@ tsconfig.compilerOptions.outDir = '../../build' tsconfig.include = ['../../src'] tsconfig.exclude = ['../../bin', '../../node_modules', '../../tests'] -const tsconfigBuild = JSON.stringify(tsconfig) - /* |-------------------------------------------------------------------------- | Compilation @@ -50,12 +46,7 @@ const tsconfigBuild = JSON.stringify(tsconfig) | compilation and deleting the tsconfig file generated. */ -const file = new File(path, Buffer.from(tsconfigBuild)) - -if (file.fileExists) { - await file.remove() -} - -await file.load() +const file = new File(path, '') +await file.setContent(JSON.stringify(tsconfig)) await Exec.command(`rimraf ../build && tsc --project ${path}`) await file.remove() diff --git a/bin/test.ts b/bin/test.ts index 71d1bdb..d61972e 100644 --- a/bin/test.ts +++ b/bin/test.ts @@ -9,42 +9,11 @@ import { assert } from '@japa/assert' import { Path } from '@athenna/common' -import { pathToFileURL } from 'node:url' +import { Importer } from '@athenna/test' import { EnvHelper } from '@athenna/config' import { specReporter } from '@japa/spec-reporter' import { configure, processCliArgs, run } from '@japa/runner' -/* -|-------------------------------------------------------------------------- -| Japa types -|-------------------------------------------------------------------------- -| -| Declare customized japa types. -*/ - -declare module '@japa/assert' { - export interface Assert { - throws(fn: () => any, errType: any, message?: string): void - doesNotThrows(fn: () => any, errType: any, message?: string): void - rejects( - fn: () => any | Promise, - errType: any, - message?: string, - ): Promise - doesNotRejects( - fn: () => any | Promise, - errType: any, - message?: string, - ): Promise - } -} - -declare module '@japa/runner' { - interface TestContext { - assert: import('@japa/assert').Assert - } -} - /* |-------------------------------------------------------------------------- | Set IS_TS env. @@ -86,7 +55,7 @@ configure({ files: ['tests/**/*Test.ts'], plugins: [assert()], reporters: [specReporter()], - importer: filePath => import(pathToFileURL(filePath).href), + importer: Importer.import, timeout: 5000, }, }) diff --git a/package-lock.json b/package-lock.json index 29444bb..1708539 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,21 @@ { "name": "@athenna/logger", - "version": "3.1.4", + "version": "3.1.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/logger", - "version": "3.1.4", + "version": "3.1.5", "license": "MIT", "dependencies": { "telegraf": "^4.11.2" }, "devDependencies": { - "@athenna/common": "^3.0.0", - "@athenna/config": "^3.0.0", - "@athenna/ioc": "^3.0.0", + "@athenna/common": "^3.3.1", + "@athenna/config": "^3.2.0", + "@athenna/ioc": "^3.1.5", + "@athenna/test": "^3.1.1", "@japa/assert": "^1.3.6", "@japa/run-failed-tests": "^1.1.0", "@japa/runner": "^2.2.2", @@ -80,9 +81,9 @@ "dev": true }, "node_modules/@athenna/common": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/@athenna/common/-/common-3.2.7.tgz", - "integrity": "sha512-ARKGjw0hafEpAuqmkkDwbmlwVTOFm7i3GYidcdgbTWUM0PiFyTIqbx6JmS9V9ONWk64wo2fK6XwcH6vOhIiukw==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@athenna/common/-/common-3.3.1.tgz", + "integrity": "sha512-yo3nCxFiISK5OjNk7M/9/ZV8VasU9MQqDE2xO941BO2mRUBuGR3V9am1grNwdDHEe/AYcaaC16LKtV5nmp8gtQ==", "dev": true, "dependencies": { "@fastify/formbody": "^7.4.0", @@ -92,7 +93,7 @@ "change-case": "^4.1.2", "collect.js": "^4.34.3", "debug": "^4.3.4", - "fastify": "^4.11.0", + "fastify": "^4.13.0", "got": "^12.5.3", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", @@ -106,38 +107,35 @@ "prepend-file": "^2.0.1", "uuid": "^8.3.2", "validator-brazil": "^1.2.2", - "youch": "^3.2.2", - "youch-terminal": "^2.1.5" + "youch": "^3.2.3", + "youch-terminal": "^2.2.0" } }, "node_modules/@athenna/config": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/@athenna/config/-/config-3.1.2.tgz", - "integrity": "sha512-k79OiYoj1p3jK2dnk40lbBhXRJF12nwH0bprSWJIPVtgqz86U0RYqvoomTnlBd1o0a5xb01evLKyCzxTBlxfBA==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@athenna/config/-/config-3.2.0.tgz", + "integrity": "sha512-XRKXk1lD/FykOg5VRqOslqNq2n+AnIogXy7OnnY+xoa8Cy57DdMaqXK1+xOV75OeIhGZRbKMOqy2eQHqdr20nw==", "dev": true, "dependencies": { - "dotenv": "^16.0.0", + "dotenv": "^16.0.3", "syntax-error": "^1.4.0" } }, - "node_modules/@athenna/config/node_modules/dotenv": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", - "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==", - "dev": true, - "engines": { - "node": ">=12" - } - }, "node_modules/@athenna/ioc": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-3.1.3.tgz", - "integrity": "sha512-7Xb6YLGt3Np3UF/pL5959AWumC1+KqY3d6c+wmX1kdkWPkEMHkLbdmSUXc61ZlSWQg7FDANpyRieUknvZd2jIA==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-3.1.5.tgz", + "integrity": "sha512-nb6OcsKfruJxTdkrhwTZXLMRWSrbJqNMJgsk3xgsajo5dQ/w0H4O/VNb9D5Xv2SE8HEsQISDcmX/IvmvXoQdGA==", "dev": true, "dependencies": { "awilix": "^7.0.3" } }, + "node_modules/@athenna/test": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@athenna/test/-/test-3.1.1.tgz", + "integrity": "sha512-rWkhSL1mDSO3sp5b1bkhUSmoEjdq55Ojv4MLZPbmoza8C/PUKA/wOwIM3LgJjdL0dENITer1gODWJv4T4apd8w==", + "dev": true + }, "node_modules/@babel/code-frame": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz", @@ -1989,9 +1987,9 @@ } }, "node_modules/avvio": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/avvio/-/avvio-8.2.0.tgz", - "integrity": "sha512-bbCQdg7bpEv6kGH41RO/3B2/GMMmJSo2iBK+X8AWN9mujtfUipMDfIjsgHCfpnKqoGEQrrmCDKSa5OQ19+fDmg==", + "version": "8.2.1", + "resolved": "https://registry.npmjs.org/avvio/-/avvio-8.2.1.tgz", + "integrity": "sha512-TAlMYvOuwGyLK3PfBb5WKBXZmXz2fVCgv23d6zZFdle/q3gPjmxBaeuC0pY0Dzs5PWMSgfqqEZkrye19GlDTgw==", "dev": true, "dependencies": { "archy": "^1.0.0", @@ -3108,6 +3106,15 @@ "tslib": "^2.0.3" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "dev": true, + "engines": { + "node": ">=12" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -3987,9 +3994,9 @@ "dev": true }, "node_modules/fast-json-stringify": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.5.0.tgz", - "integrity": "sha512-rmw2Z8/mLkND8zI+3KTYIkNPEoF5v6GqDP/o+g7H3vjdWjBwuKpgAYFHIzL6ORRB+iqDjjtJnLIW9Mzxn5szOA==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.6.2.tgz", + "integrity": "sha512-F6xkRrXvtGbAiDSEI5Rk7qk2P63Y9kc8bO6Dnsd3Rt6sBNr2QxNFWs0JbKftgiyOfGxnJaRoHe4SizCTqeAyrA==", "dev": true, "dependencies": { "@fastify/deepmerge": "^1.0.0", @@ -4053,12 +4060,12 @@ "dev": true }, "node_modules/fastify": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.12.0.tgz", - "integrity": "sha512-Hh2GCsOCqnOuewWSvqXlpq5V/9VA+/JkVoooQWUhrU6gryO9+/UGOoF/dprGcKSDxkM/9TkMXSffYp8eA/YhYQ==", + "version": "4.14.0", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.14.0.tgz", + "integrity": "sha512-oJSHlM/XbGdJpe2MKMJBsrvrkPDrHDZlAB9qzuUJIpnBtpDE394bzdFsH4KnsUI1e8zxzFl+GNBEXC64N/IPuw==", "dev": true, "dependencies": { - "@fastify/ajv-compiler": "^3.3.1", + "@fastify/ajv-compiler": "^3.5.0", "@fastify/error": "^3.0.0", "@fastify/fast-json-stringify-compiler": "^4.1.0", "abstract-logging": "^2.0.1", @@ -4171,9 +4178,9 @@ } }, "node_modules/find-my-way": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-7.4.0.tgz", - "integrity": "sha512-JFT7eURLU5FumlZ3VBGnveId82cZz7UR7OUu+THQJOwdQXxmS/g8v0KLoFhv97HreycOrmAbqjXD/4VG2j0uMQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-7.5.0.tgz", + "integrity": "sha512-3ehydSBhGcS0TtMA/BYEyMAKi9Sv0MqF8aqiMO5oGBXyCcSlyEJyfGWsbNxAx7BekTNWUwD1ttLJLURni2vmJg==", "dev": true, "dependencies": { "fast-deep-equal": "^3.1.3", @@ -5858,9 +5865,9 @@ } }, "node_modules/light-my-request": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-5.8.0.tgz", - "integrity": "sha512-4BtD5C+VmyTpzlDPCZbsatZMJVgUIciSOwYhJDCbLffPZ35KoDkDj4zubLeHDEb35b4kkPeEv5imbh+RJxK/Pg==", + "version": "5.9.1", + "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-5.9.1.tgz", + "integrity": "sha512-UT7pUk8jNCR1wR7w3iWfIjx32DiB2f3hFdQSOwy3/EPQ3n3VocyipUxcyRZR0ahoev+fky69uA+GejPa9KuHKg==", "dev": true, "dependencies": { "cookie": "^0.5.0", @@ -7067,9 +7074,9 @@ } }, "node_modules/pino": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/pino/-/pino-8.8.0.tgz", - "integrity": "sha512-cF8iGYeu2ODg2gIwgAHcPrtR63ILJz3f7gkogaHC/TXVVXxZgInmNYiIpDYEwgEkxZti2Se6P2W2DxlBIZe6eQ==", + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/pino/-/pino-8.11.0.tgz", + "integrity": "sha512-Z2eKSvlrl2rH8p5eveNUnTdd4AjJk8tAsLkHYZQKGHP4WTh2Gi1cOSOs3eWPqaj+niS3gj4UkoreoaWgF3ZWYg==", "dev": true, "dependencies": { "atomic-sleep": "^1.0.0", @@ -8734,6 +8741,12 @@ "node": ">=0.10.0" } }, + "node_modules/wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==", + "dev": true + }, "node_modules/wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -8836,9 +8849,9 @@ } }, "node_modules/youch": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/youch/-/youch-3.2.2.tgz", - "integrity": "sha512-+xhTK8sY9qV3nLbWVaOUFZPdlQ3wrMKiu3dKqKkAkLaYzzkYmpWY+v+eQIAfbPu7TZhS1G5FhEV++sl8fhuT4w==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/youch/-/youch-3.2.3.tgz", + "integrity": "sha512-ZBcWz/uzZaQVdCvfV4uk616Bbpf2ee+F/AvuKDR5EwX/Y4v06xWdtMluqTD7+KlZdM93lLm9gMZYo0sKBS0pgw==", "dev": true, "dependencies": { "cookie": "^0.5.0", @@ -8847,12 +8860,14 @@ } }, "node_modules/youch-terminal": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/youch-terminal/-/youch-terminal-2.1.5.tgz", - "integrity": "sha512-ObQ2GeG0LnIGiOAq0rLaEdCC8Z+fHlMFcJqsQcLBWo36zlj2GViS7pOKjRGdJ4pJl4ofZmU77O7gwd6lId67PA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/youch-terminal/-/youch-terminal-2.2.0.tgz", + "integrity": "sha512-LLYtvG/4XoRO/vhf2eBkzT6dI1hWliLSp7NuXRKsvBAITuIxODS61X7AQOHl5Aaf8oquS9JlHSpjTFjX140XKA==", "dev": true, "dependencies": { - "kleur": "^4.1.5" + "kleur": "^4.1.5", + "string-width": "^4.2.3", + "wordwrap": "^1.0.0" } }, "node_modules/z-schema": { @@ -8909,9 +8924,9 @@ "dev": true }, "@athenna/common": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/@athenna/common/-/common-3.2.7.tgz", - "integrity": "sha512-ARKGjw0hafEpAuqmkkDwbmlwVTOFm7i3GYidcdgbTWUM0PiFyTIqbx6JmS9V9ONWk64wo2fK6XwcH6vOhIiukw==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@athenna/common/-/common-3.3.1.tgz", + "integrity": "sha512-yo3nCxFiISK5OjNk7M/9/ZV8VasU9MQqDE2xO941BO2mRUBuGR3V9am1grNwdDHEe/AYcaaC16LKtV5nmp8gtQ==", "dev": true, "requires": { "@fastify/formbody": "^7.4.0", @@ -8921,7 +8936,7 @@ "change-case": "^4.1.2", "collect.js": "^4.34.3", "debug": "^4.3.4", - "fastify": "^4.11.0", + "fastify": "^4.13.0", "got": "^12.5.3", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", @@ -8935,37 +8950,35 @@ "prepend-file": "^2.0.1", "uuid": "^8.3.2", "validator-brazil": "^1.2.2", - "youch": "^3.2.2", - "youch-terminal": "^2.1.5" + "youch": "^3.2.3", + "youch-terminal": "^2.2.0" } }, "@athenna/config": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/@athenna/config/-/config-3.1.2.tgz", - "integrity": "sha512-k79OiYoj1p3jK2dnk40lbBhXRJF12nwH0bprSWJIPVtgqz86U0RYqvoomTnlBd1o0a5xb01evLKyCzxTBlxfBA==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@athenna/config/-/config-3.2.0.tgz", + "integrity": "sha512-XRKXk1lD/FykOg5VRqOslqNq2n+AnIogXy7OnnY+xoa8Cy57DdMaqXK1+xOV75OeIhGZRbKMOqy2eQHqdr20nw==", "dev": true, "requires": { - "dotenv": "^16.0.0", + "dotenv": "^16.0.3", "syntax-error": "^1.4.0" - }, - "dependencies": { - "dotenv": { - "version": "16.0.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", - "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==", - "dev": true - } } }, "@athenna/ioc": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-3.1.3.tgz", - "integrity": "sha512-7Xb6YLGt3Np3UF/pL5959AWumC1+KqY3d6c+wmX1kdkWPkEMHkLbdmSUXc61ZlSWQg7FDANpyRieUknvZd2jIA==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/@athenna/ioc/-/ioc-3.1.5.tgz", + "integrity": "sha512-nb6OcsKfruJxTdkrhwTZXLMRWSrbJqNMJgsk3xgsajo5dQ/w0H4O/VNb9D5Xv2SE8HEsQISDcmX/IvmvXoQdGA==", "dev": true, "requires": { "awilix": "^7.0.3" } }, + "@athenna/test": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@athenna/test/-/test-3.1.1.tgz", + "integrity": "sha512-rWkhSL1mDSO3sp5b1bkhUSmoEjdq55Ojv4MLZPbmoza8C/PUKA/wOwIM3LgJjdL0dENITer1gODWJv4T4apd8w==", + "dev": true + }, "@babel/code-frame": { "version": "7.16.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz", @@ -10358,9 +10371,9 @@ "dev": true }, "avvio": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/avvio/-/avvio-8.2.0.tgz", - "integrity": "sha512-bbCQdg7bpEv6kGH41RO/3B2/GMMmJSo2iBK+X8AWN9mujtfUipMDfIjsgHCfpnKqoGEQrrmCDKSa5OQ19+fDmg==", + "version": "8.2.1", + "resolved": "https://registry.npmjs.org/avvio/-/avvio-8.2.1.tgz", + "integrity": "sha512-TAlMYvOuwGyLK3PfBb5WKBXZmXz2fVCgv23d6zZFdle/q3gPjmxBaeuC0pY0Dzs5PWMSgfqqEZkrye19GlDTgw==", "dev": true, "requires": { "archy": "^1.0.0", @@ -11207,6 +11220,12 @@ "tslib": "^2.0.3" } }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "dev": true + }, "eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -11868,9 +11887,9 @@ "dev": true }, "fast-json-stringify": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.5.0.tgz", - "integrity": "sha512-rmw2Z8/mLkND8zI+3KTYIkNPEoF5v6GqDP/o+g7H3vjdWjBwuKpgAYFHIzL6ORRB+iqDjjtJnLIW9Mzxn5szOA==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.6.2.tgz", + "integrity": "sha512-F6xkRrXvtGbAiDSEI5Rk7qk2P63Y9kc8bO6Dnsd3Rt6sBNr2QxNFWs0JbKftgiyOfGxnJaRoHe4SizCTqeAyrA==", "dev": true, "requires": { "@fastify/deepmerge": "^1.0.0", @@ -11929,12 +11948,12 @@ "dev": true }, "fastify": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.12.0.tgz", - "integrity": "sha512-Hh2GCsOCqnOuewWSvqXlpq5V/9VA+/JkVoooQWUhrU6gryO9+/UGOoF/dprGcKSDxkM/9TkMXSffYp8eA/YhYQ==", + "version": "4.14.0", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.14.0.tgz", + "integrity": "sha512-oJSHlM/XbGdJpe2MKMJBsrvrkPDrHDZlAB9qzuUJIpnBtpDE394bzdFsH4KnsUI1e8zxzFl+GNBEXC64N/IPuw==", "dev": true, "requires": { - "@fastify/ajv-compiler": "^3.3.1", + "@fastify/ajv-compiler": "^3.5.0", "@fastify/error": "^3.0.0", "@fastify/fast-json-stringify-compiler": "^4.1.0", "abstract-logging": "^2.0.1", @@ -12024,9 +12043,9 @@ } }, "find-my-way": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-7.4.0.tgz", - "integrity": "sha512-JFT7eURLU5FumlZ3VBGnveId82cZz7UR7OUu+THQJOwdQXxmS/g8v0KLoFhv97HreycOrmAbqjXD/4VG2j0uMQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-7.5.0.tgz", + "integrity": "sha512-3ehydSBhGcS0TtMA/BYEyMAKi9Sv0MqF8aqiMO5oGBXyCcSlyEJyfGWsbNxAx7BekTNWUwD1ttLJLURni2vmJg==", "dev": true, "requires": { "fast-deep-equal": "^3.1.3", @@ -13280,9 +13299,9 @@ } }, "light-my-request": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-5.8.0.tgz", - "integrity": "sha512-4BtD5C+VmyTpzlDPCZbsatZMJVgUIciSOwYhJDCbLffPZ35KoDkDj4zubLeHDEb35b4kkPeEv5imbh+RJxK/Pg==", + "version": "5.9.1", + "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-5.9.1.tgz", + "integrity": "sha512-UT7pUk8jNCR1wR7w3iWfIjx32DiB2f3hFdQSOwy3/EPQ3n3VocyipUxcyRZR0ahoev+fky69uA+GejPa9KuHKg==", "dev": true, "requires": { "cookie": "^0.5.0", @@ -14171,9 +14190,9 @@ "dev": true }, "pino": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/pino/-/pino-8.8.0.tgz", - "integrity": "sha512-cF8iGYeu2ODg2gIwgAHcPrtR63ILJz3f7gkogaHC/TXVVXxZgInmNYiIpDYEwgEkxZti2Se6P2W2DxlBIZe6eQ==", + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/pino/-/pino-8.11.0.tgz", + "integrity": "sha512-Z2eKSvlrl2rH8p5eveNUnTdd4AjJk8tAsLkHYZQKGHP4WTh2Gi1cOSOs3eWPqaj+niS3gj4UkoreoaWgF3ZWYg==", "dev": true, "requires": { "atomic-sleep": "^1.0.0", @@ -15433,6 +15452,12 @@ "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "dev": true }, + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==", + "dev": true + }, "wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", @@ -15507,9 +15532,9 @@ "dev": true }, "youch": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/youch/-/youch-3.2.2.tgz", - "integrity": "sha512-+xhTK8sY9qV3nLbWVaOUFZPdlQ3wrMKiu3dKqKkAkLaYzzkYmpWY+v+eQIAfbPu7TZhS1G5FhEV++sl8fhuT4w==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/youch/-/youch-3.2.3.tgz", + "integrity": "sha512-ZBcWz/uzZaQVdCvfV4uk616Bbpf2ee+F/AvuKDR5EwX/Y4v06xWdtMluqTD7+KlZdM93lLm9gMZYo0sKBS0pgw==", "dev": true, "requires": { "cookie": "^0.5.0", @@ -15518,12 +15543,14 @@ } }, "youch-terminal": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/youch-terminal/-/youch-terminal-2.1.5.tgz", - "integrity": "sha512-ObQ2GeG0LnIGiOAq0rLaEdCC8Z+fHlMFcJqsQcLBWo36zlj2GViS7pOKjRGdJ4pJl4ofZmU77O7gwd6lId67PA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/youch-terminal/-/youch-terminal-2.2.0.tgz", + "integrity": "sha512-LLYtvG/4XoRO/vhf2eBkzT6dI1hWliLSp7NuXRKsvBAITuIxODS61X7AQOHl5Aaf8oquS9JlHSpjTFjX140XKA==", "dev": true, "requires": { - "kleur": "^4.1.5" + "kleur": "^4.1.5", + "string-width": "^4.2.3", + "wordwrap": "^1.0.0" } }, "z-schema": { diff --git a/package.json b/package.json index 426e4cb..cb942bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/logger", - "version": "3.1.4", + "version": "3.1.5", "description": "The Athenna logging solution. Log in stdout, files and buckets.", "license": "MIT", "author": "João Lenon ", @@ -21,10 +21,11 @@ "esm" ], "scripts": { - "build": "ts-node bin/build.ts", + "node": "cross-env NODE_OPTIONS=\"--experimental-import-meta-resolve\" ts-node", + "build": "npm run node --silent -- bin/build.ts", "lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix", - "test": "npm run --silent lint:fix && ts-node bin/test.ts", - "test:debug": "cross-env DEBUG=api:* ts-node bin/test.ts --inspect", + "test": "npm run --silent lint:fix && npm run node --silent -- bin/test.ts", + "test:debug": "cross-env DEBUG=api:* npm run node --silent -- bin/test.ts --inspect", "test:coverage": "c8 npm run --silent test" }, "files": [ @@ -51,9 +52,10 @@ "telegraf": "^4.11.2" }, "devDependencies": { - "@athenna/common": "^3.0.0", - "@athenna/config": "^3.0.0", - "@athenna/ioc": "^3.0.0", + "@athenna/common": "^3.3.1", + "@athenna/config": "^3.2.0", + "@athenna/ioc": "^3.1.5", + "@athenna/test": "^3.1.1", "@japa/assert": "^1.3.6", "@japa/run-failed-tests": "^1.1.0", "@japa/runner": "^2.2.2", diff --git a/tests/Unit/Drivers/ConsoleDriverTest.ts b/tests/Unit/Drivers/ConsoleDriverTest.ts index 3bfc955..eaf2a15 100644 --- a/tests/Unit/Drivers/ConsoleDriverTest.ts +++ b/tests/Unit/Drivers/ConsoleDriverTest.ts @@ -7,11 +7,12 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Path, Exec } from '@athenna/common' +import { Test, TestContext } from '@athenna/test' -test.group('ConsoleDriverTest', () => { - test('should be able to log in console', async ({ assert }) => { +export default class ConsoleDriverTest { + @Test() + public async shouldBeAbleToLogInConsole({ assert }: TestContext) { const { stdout, stderr } = await Exec.command(`ts-node --esm ${Path.stubs('transporters/console.ts')}`) const logs = [...stdout.split('\n').filter(l => l !== ''), ...stderr.split('\n').filter(l => l !== '')] @@ -20,5 +21,5 @@ test.group('ConsoleDriverTest', () => { assert.isFalse(log.includes('TRACE')) assert.isTrue(log.includes('hello')) }) - }) -}) + } +} diff --git a/tests/Unit/Drivers/DiscordDriverTest.ts b/tests/Unit/Drivers/DiscordDriverTest.ts index 0ef3e38..21ac0ca 100644 --- a/tests/Unit/Drivers/DiscordDriverTest.ts +++ b/tests/Unit/Drivers/DiscordDriverTest.ts @@ -7,25 +7,28 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Config } from '@athenna/config' import { Log, LoggerProvider } from '#src' import { Folder, Path } from '@athenna/common' +import { Test, AfterEach, BeforeEach, TestContext } from '@athenna/test' -test.group('DiscordDriverTest', group => { - group.each.setup(async () => { +export default class DiscordDriverTest { + @BeforeEach() + public async beforeEach() { await new Folder(Path.stubs('config')).copy(Path.config()) await Config.safeLoad(Path.config('logging.ts')) new LoggerProvider().register() - }) + } - group.each.teardown(async () => { + @AfterEach() + public async afterEach() { await Folder.safeRemove(Path.config()) await Folder.safeRemove(Path.storage()) - }) + } - test('should be able to log in discord', async ({ assert }) => { + @Test() + public async shouldBeAbleToLogInDiscord({ assert }: TestContext) { const log = Log.config({ level: 'error' }).channel('discord') const message = 'hello' @@ -46,5 +49,5 @@ test.group('DiscordDriverTest', group => { assert.equal(errorRes.statusCode, 204) assert.equal(fatalRes.statusCode, 204) - }).timeout(10000) -}) + } +} diff --git a/tests/Unit/Drivers/FileDriverTest.ts b/tests/Unit/Drivers/FileDriverTest.ts index e393180..45bbae3 100644 --- a/tests/Unit/Drivers/FileDriverTest.ts +++ b/tests/Unit/Drivers/FileDriverTest.ts @@ -7,25 +7,28 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Config } from '@athenna/config' import { Log, LoggerProvider } from '#src' import { File, Folder, Path } from '@athenna/common' +import { Test, AfterEach, BeforeEach, TestContext } from '@athenna/test' -test.group('FileDriverTest', group => { - group.each.setup(async () => { +export default class FileDriverTest { + @BeforeEach() + public async beforeEach() { await new Folder(Path.stubs('config')).copy(Path.config()) await Config.safeLoad(Path.config('logging.ts')) new LoggerProvider().register() - }) + } - group.each.teardown(async () => { + @AfterEach() + public async afterEach() { await Folder.safeRemove(Path.config()) await Folder.safeRemove(Path.storage()) - }) + } - test('should be able to log in files', async ({ assert }) => { + @Test() + public async shouldBeAbleToLogInFiles({ assert }: TestContext) { const filePath = Path.storage('athenna.log') const log = Log.config({ level: 'success', filePath, formatter: 'json' }).channel('file') @@ -39,7 +42,7 @@ test.group('FileDriverTest', group => { await log.error({ hello: 'world!' }) await log.fatal(message) - const fileContent = (await new File(filePath).load()).getContentSync().toString() + const fileContent = await new File(filePath).getContentAsString() const logs = fileContent.split('\n') logs @@ -50,9 +53,10 @@ test.group('FileDriverTest', group => { if (log.msg) assert.equal(log.msg, 'hello') else assert.equal(log.hello, 'world!') }) - }) + } - test('should be able to use the log engine with new lines', async ({ assert }) => { + @Test() + public async shouldBeAbleToUseTheLogEngineWithNewLines({ assert }: TestContext) { const filePath = Path.storage('athenna.log') const log = Log.config({ level: 'success', filePath, formatter: 'cli' }).channel('file') @@ -63,9 +67,9 @@ test.group('FileDriverTest', group => { await log.success('hello ({yellow, bold} world!)') await log.success(`hello ({yellow, bold} ${objectString})`) - const fileContent = (await new File(filePath).load()).getContentSync().toString() + const fileContent = await new File(filePath).getContentAsString() const logs = fileContent.split('\n').filter(log => log !== '') assert.lengthOf(logs, 4) - }) -}) + } +} diff --git a/tests/Unit/Drivers/SlackDriverTest.ts b/tests/Unit/Drivers/SlackDriverTest.ts index 834f9be..d0582a5 100644 --- a/tests/Unit/Drivers/SlackDriverTest.ts +++ b/tests/Unit/Drivers/SlackDriverTest.ts @@ -7,25 +7,29 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Config } from '@athenna/config' import { Log, LoggerProvider } from '#src' import { Folder, Path } from '@athenna/common' +import { AfterEach, BeforeEach, Test, Timeout, TestContext } from '@athenna/test' -test.group('SlackDriverTest', group => { - group.each.setup(async () => { +export default class SlackDriverTest { + @BeforeEach() + public async beforeEach() { await new Folder(Path.stubs('config')).copy(Path.config()) await Config.safeLoad(Path.config('logging.ts')) new LoggerProvider().register() - }) + } - group.each.teardown(async () => { + @AfterEach() + public async afterEach() { await Folder.safeRemove(Path.config()) await Folder.safeRemove(Path.storage()) - }) + } - test('should be able to log in slack', async ({ assert }) => { + @Test() + @Timeout(10000) + public async shouldBeAbleToLogInSlack({ assert }: TestContext) { const log = Log.config({ level: 'success' }).channel('slack') const message = 'hello' @@ -46,5 +50,5 @@ test.group('SlackDriverTest', group => { assert.equal(warnRes.statusCode, 200) assert.equal(errorRes.statusCode, 200) assert.equal(fatalRes.statusCode, 200) - }).timeout(10000) -}) + } +} diff --git a/tests/Unit/Drivers/StackDriverTest.ts b/tests/Unit/Drivers/StackDriverTest.ts index 72df6af..f798808 100644 --- a/tests/Unit/Drivers/StackDriverTest.ts +++ b/tests/Unit/Drivers/StackDriverTest.ts @@ -7,28 +7,32 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Config } from '@athenna/config' import { Log, LoggerProvider } from '#src' import { Folder, Path } from '@athenna/common' +import { AfterEach, BeforeEach, Test, Timeout } from '@athenna/test' -test.group('StackDriverTest', group => { - group.each.setup(async () => { +export default class StackDriverTest { + @BeforeEach() + public async beforeEach() { await new Folder(Path.stubs('config')).copy(Path.config()) await Config.safeLoad(Path.config('logging.ts')) new LoggerProvider().register() - }) + } - group.each.teardown(async () => { + @AfterEach() + public async afterEach() { await Folder.safeRemove(Path.config()) await Folder.safeRemove(Path.storage()) - }) + } - test('should be able to log multiples channels at one time', async ({ assert }) => { + @Test() + @Timeout(10000) + public async shouldBeAbleToLogMultiplesChannelsAtOneTime({ assert }) { const [[slackReq, discordReq]] = await Log.channel('stack').fatal('hello') assert.equal(slackReq.statusCode, 200) assert.equal(discordReq.statusCode, 204) - }).timeout(10000) -}) + } +} diff --git a/tests/Unit/Drivers/TelegramDriverTest.ts b/tests/Unit/Drivers/TelegramDriverTest.ts index 40e6176..c402fec 100644 --- a/tests/Unit/Drivers/TelegramDriverTest.ts +++ b/tests/Unit/Drivers/TelegramDriverTest.ts @@ -7,25 +7,29 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Config } from '@athenna/config' import { Log, LoggerProvider } from '#src' import { Folder, Path } from '@athenna/common' +import { AfterEach, BeforeEach, Test, Timeout } from '@athenna/test' -test.group('TelegramDriverTest', group => { - group.each.setup(async () => { +export default class TelegramDriverTest { + @BeforeEach() + public async beforeEach() { await new Folder(Path.stubs('config')).copy(Path.config()) await Config.safeLoad(Path.config('logging.ts')) new LoggerProvider().register() - }) + } - group.each.teardown(async () => { + @AfterEach() + public async afterEach() { await Folder.safeRemove(Path.config()) await Folder.safeRemove(Path.storage()) - }) + } - test('should be able to log in telegram', async ({ assert }) => { + @Test() + @Timeout(10000) + public async shouldBeAbleToLogInTelegram({ assert }) { const log = Log.config({ level: 'success' }).channel('telegram') const message = 'hello' @@ -46,5 +50,5 @@ test.group('TelegramDriverTest', group => { assert.equal(warnRes.from.first_name, 'Athenna') assert.equal(errorRes.from.first_name, 'Athenna') assert.equal(fatalRes.from.first_name, 'Athenna') - }).timeout(10000) -}) + } +} diff --git a/tests/Unit/Factories/DriverFactoryTest.ts b/tests/Unit/Factories/DriverFactoryTest.ts index 7f05ac9..234d53f 100644 --- a/tests/Unit/Factories/DriverFactoryTest.ts +++ b/tests/Unit/Factories/DriverFactoryTest.ts @@ -7,11 +7,11 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Config } from '@athenna/config' import { Folder, ObjectBuilder, Path } from '@athenna/common' import { Driver, DriverFactory } from '#src' +import { AfterEach, BeforeEach, Test, TestContext } from '@athenna/test' import { DriverExistException } from '#src/Exceptions/DriverExistException' import { NotFoundDriverException } from '#src/Exceptions/NotFoundDriverException' import { NotImplementedConfigException } from '#src/Exceptions/NotImplementedConfigException' @@ -22,40 +22,47 @@ class CustomDriver extends Driver { } } -test.group('DriverFactoryTest', group => { - group.each.setup(async () => { +export default class DriverFactoryTest { + @BeforeEach() + public async beforeEach() { await new Folder(Path.stubs('config')).copy(Path.config()) await Config.safeLoad(Path.config('logging.ts')) - }) + } - group.each.teardown(async () => { + @AfterEach() + public async afterEach() { await Folder.safeRemove(Path.config()) - }) + } - test('should be able to list all available drivers', async ({ assert }) => { + @Test() + public async shouldBeAbleToListAllAvailableDrivers({ assert }: TestContext) { const drivers = DriverFactory.availableDrivers() assert.deepEqual(drivers, ['file', 'null', 'slack', 'stack', 'console', 'discord', 'telegram']) - }) + } - test('should throw not implemented config exception when trying to fabricate driver without loading config file', async ({ + @Test() + public async shouldThrowNotImplementedConfigExceptionWhenTryingToFabricateDriverWithoutLoadingConfigFile({ assert, - }) => { + }: TestContext) { Config.configs = new ObjectBuilder() assert.throws(() => DriverFactory.fabricate('not-found'), NotImplementedConfigException) - }) + } - test('should throw not implemented config exception when trying to fabricate driver when trying to load channel that does not exist', async ({ + @Test() + public async shouldThrowNotImplementedConfigExceptionWhenTryingToFabricateDriverWhenTryingToLoadChannelThatDoesNotExist({ assert, - }) => { + }: TestContext) { assert.throws(() => DriverFactory.fabricate('not-found'), NotImplementedConfigException) - }) + } - test('should throw not found driver exception when trying to fabricate driver', async ({ assert }) => { + @Test() + public async shouldThrowNotFoundDriverExceptionWhenTryingToFabricateDriver({ assert }: TestContext) { assert.throws(() => DriverFactory.fabricate('notFound'), NotFoundDriverException) - }) + } - test('should be able to create custom driver', async ({ assert }) => { + @Test() + public async shouldBeAbleToCreateCustomerDriver({ assert }: TestContext) { DriverFactory.createDriver('custom', CustomDriver) const driver = DriverFactory.fabricate('custom') @@ -63,9 +70,10 @@ test.group('DriverFactoryTest', group => { const message = driver.transport('info', 'hello') assert.equal(message, 'LOG: info:hello') - }) + } - test('should throw driver exist exception when trying to create driver', async ({ assert }) => { + @Test() + public async shouldThrowDriverExistExceptionWhenTryingToCreateDriver({ assert }: TestContext) { assert.throws(() => DriverFactory.createDriver('file', CustomDriver), DriverExistException) - }) -}) + } +} diff --git a/tests/Unit/Factories/FormatterFactoryTest.ts b/tests/Unit/Factories/FormatterFactoryTest.ts index 01d273f..272da82 100644 --- a/tests/Unit/Factories/FormatterFactoryTest.ts +++ b/tests/Unit/Factories/FormatterFactoryTest.ts @@ -7,7 +7,7 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' +import { Test, TestContext } from '@athenna/test' import { Formatter, FormatterFactory } from '#src' import { FormatterExistException } from '#src/Exceptions/FormatterExistException' import { NotFoundFormatterException } from '#src/Exceptions/NotFoundFormatterException' @@ -18,18 +18,21 @@ class CustomFormatter extends Formatter { } } -test.group('FormatterFactoryTest', () => { - test('should be able to list all available formatters', async ({ assert }) => { +export default class FormatterFactoryTest { + @Test() + public async shouldBeAbleToListAllAvailableFormatters({ assert }: TestContext) { const formatters = FormatterFactory.availableFormatters() assert.deepEqual(formatters, ['cli', 'json', 'none', 'simple', 'message', 'request']) - }) + } - test('should throw not found formatter exception when trying to fabricate formatter', async ({ assert }) => { + @Test() + public async shouldThrowNotFoundFormatterExceptionWhenTryingToFabricateFormatter({ assert }: TestContext) { assert.throws(() => FormatterFactory.fabricate('not-found'), NotFoundFormatterException) - }) + } - test('should be able to create custom formatter', async ({ assert }) => { + @Test() + public async shouldBeAbleToCreateCustomFormatter({ assert }: TestContext) { FormatterFactory.createFormatter('custom', CustomFormatter) const formatter = FormatterFactory.fabricate('custom') @@ -37,9 +40,10 @@ test.group('FormatterFactoryTest', () => { const message = formatter.format('hello') assert.equal(message, 'FORMATTED: hello') - }) + } - test('should throw formatter exist exception when trying to create formatter', async ({ assert }) => { + @Test() + public async shouldThrowFormatterExistExceptionWhenTryingToCreateFormatter({ assert }: TestContext) { assert.throws(() => FormatterFactory.createFormatter('cli', CustomFormatter), FormatterExistException) - }) -}) + } +} diff --git a/tests/Unit/Formatters/CliFormatterTest.ts b/tests/Unit/Formatters/CliFormatterTest.ts index 10c8016..d0dc90b 100644 --- a/tests/Unit/Formatters/CliFormatterTest.ts +++ b/tests/Unit/Formatters/CliFormatterTest.ts @@ -7,16 +7,17 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' +import { Test, TestContext } from '@athenna/test' import { CliFormatter } from '#src/Formatters/CliFormatter' -test.group('CliFormatterTest', () => { - test('should be able to format logs to cli format', async ({ assert }) => { +export default class CliFormatterTest { + @Test() + public shouldBeAbleToFormatLogsToCliFormat({ assert }: TestContext) { const formatter = new CliFormatter().config({ level: 'info' }) const message = formatter.format('hello') assert.isTrue(message.includes('info')) assert.isTrue(message.includes('hello')) - }) -}) + } +} diff --git a/tests/Unit/Formatters/JsonFormatterTest.ts b/tests/Unit/Formatters/JsonFormatterTest.ts index 3a59234..b593125 100644 --- a/tests/Unit/Formatters/JsonFormatterTest.ts +++ b/tests/Unit/Formatters/JsonFormatterTest.ts @@ -7,13 +7,14 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Is } from '@athenna/common' import { runWithId } from 'cls-rtracer' +import { Test, TestContext } from '@athenna/test' import { JsonFormatter } from '#src/Formatters/JsonFormatter' -test.group('JsonFormatterTest', () => { - test('should be able to format logs to json format', async ({ assert }) => { +export default class JsonFormatterTest { + @Test() + public async shouldBeAbleToFormatLogsToJsonFormat({ assert }: TestContext) { const formatter = new JsonFormatter().config({ level: 'info' }) const message = JSON.parse(formatter.format('hello')) @@ -22,9 +23,10 @@ test.group('JsonFormatterTest', () => { assert.equal(message.level, 'info') assert.equal(message.pid, process.pid) assert.equal(message.traceId, null) - }) + } - test('should be able to format logs to json format with the traceId', async ({ assert }) => { + @Test() + public async shouldBeAbleToFormatLogsToJsonFormatWithTheTraceId({ assert }: TestContext) { const formatter = new JsonFormatter().config({ level: 'info' }) runWithId(() => { @@ -35,5 +37,5 @@ test.group('JsonFormatterTest', () => { assert.equal(message.pid, process.pid) assert.isTrue(Is.Uuid(message.traceId)) }) - }) -}) + } +} diff --git a/tests/Unit/Formatters/MessageFormatterTest.ts b/tests/Unit/Formatters/MessageFormatterTest.ts index 333dbfb..7364db6 100644 --- a/tests/Unit/Formatters/MessageFormatterTest.ts +++ b/tests/Unit/Formatters/MessageFormatterTest.ts @@ -8,11 +8,12 @@ */ import { hostname } from 'node:os' -import { test } from '@japa/runner' +import { Test, TestContext } from '@athenna/test' import { MessageFormatter } from '#src/Formatters/MessageFormatter' -test.group('MessageFormatterTest', () => { - test('should be able to format logs to message format', async ({ assert }) => { +export default class MessageFormatterTest { + @Test() + public async shouldBeAbleToFormatLogsToMessageFormat({ assert }: TestContext) { const formatter = new MessageFormatter().config({ level: 'info' }) const message = formatter.format('hello') @@ -21,5 +22,5 @@ test.group('MessageFormatterTest', () => { assert.isTrue(message.includes(`(${hostname()})`)) assert.isTrue(message.includes(`(${process.pid})`)) assert.isTrue(message.includes(formatter.getEmojiByLevel('info'))) - }) -}) + } +} diff --git a/tests/Unit/Formatters/NoneFormatterTest.ts b/tests/Unit/Formatters/NoneFormatterTest.ts index c223593..55b6de0 100644 --- a/tests/Unit/Formatters/NoneFormatterTest.ts +++ b/tests/Unit/Formatters/NoneFormatterTest.ts @@ -7,63 +7,68 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' -import { NoneFormatter } from '#src/Formatters/NoneFormatter' import { Color } from '@athenna/common' +import { Test, TestContext } from '@athenna/test' +import { NoneFormatter } from '#src/Formatters/NoneFormatter' -test.group('NoneFormatterTest', () => { - test('should be able to format logs to none format', async ({ assert }) => { +export default class NoneFormatterTest { + @Test() + public async shouldBeAbleToFormatLogsToNoneFormat({ assert }: TestContext) { const formatter = new NoneFormatter().config({ level: 'info' }) const message = formatter.format('hello') assert.equal(message, 'hello') - }) + } - test('should be able to apply chalk colors in message', async ({ assert }) => { + @Test() + public async shouldBeAbleToApplyChalkColorsInMessage({ assert }: TestContext) { const formatter = new NoneFormatter().config({ level: 'info', clean: false, chalk: Color.gray }) const message = formatter.format('hello') assert.equal(message, Color.gray('hello')) - }) + } - test('should return the cli level without any color if the level does not exist', async ({ assert }) => { + @Test() + public async shouldReturnTheCliLevelWithoutAnyColorIfTheLevelDoesNotExist({ assert }: TestContext) { const formatter = new NoneFormatter().config({ level: 'not-found' }) const level = formatter.cliLevel() assert.equal(level, Color.bold('[ not-found ]')) - }) + } - test('should return the simple level without any color if the level does not exist', async ({ assert }) => { + @Test() + public async shouldReturnTheSimpleLevelWithoutAnyColorIfTheLevelDoesNotExist({ assert }: TestContext) { const formatter = new NoneFormatter().config({ level: 'not-found' }) const level = formatter.simpleLevel() assert.equal(level, Color.bold('[NOT-FOUND]')) - }) + } - test('should return the custom emoji if it exists', async ({ assert }) => { + @Test() + public async shouldReturnTheCustomEmojiIfItExists({ assert }: TestContext) { const formatter = new NoneFormatter().config({ level: 'info' }) const emoji = formatter.getEmojiByLevel('info', '\u{1F43E}') assert.equal(emoji, '\u{1F43E}') - }) + } - test('should return an empty string if the level does not exist in the dictionary', async ({ assert }) => { + @Test() + public async shouldReturnAnEmptyStringIfTheLevelDoesNotExistInTheDictionary({ assert }: TestContext) { const formatter = new NoneFormatter().config({ level: 'info' }) const emoji = formatter.getEmojiByLevel('not-found') assert.equal(emoji, '') - }) + } - test('should return the message without any color if the level does not exist in the dictionary', async ({ - assert, - }) => { + @Test() + public async shouldReturnTheMessageWithoutAnyColorIfTheLevelDoesNotExistInTheDictionary({ assert }: TestContext) { const formatter = new NoneFormatter().config({ level: 'info' }) const message = formatter.paintMessageByLevel('not-found', 'hello') assert.equal(message, 'hello') - }) -}) + } +} diff --git a/tests/Unit/Formatters/RequestFormatterTest.ts b/tests/Unit/Formatters/RequestFormatterTest.ts index 9b3c967..9783512 100644 --- a/tests/Unit/Formatters/RequestFormatterTest.ts +++ b/tests/Unit/Formatters/RequestFormatterTest.ts @@ -7,11 +7,12 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' +import { Test, TestContext } from '@athenna/test' import { RequestFormatter } from '#src/Formatters/RequestFormatter' -test.group('RequestFormatterTest', () => { - test('should be able to format logs to request format', async ({ assert }) => { +export default class RequestFormatterTest { + @Test() + public async shouldBeAbleToFormatLogsToRequestFormat({ assert }: TestContext) { const formatter = new RequestFormatter().config({ level: 'info' }) const ctx = { @@ -44,9 +45,10 @@ test.group('RequestFormatterTest', () => { assert.isTrue(message.includes('[GET::200]')) assert.isTrue(message.includes('http://localhost:1335/:id')) assert.isTrue(message.includes('ms')) - }) + } - test('should be able to format logs to request format as json', async ({ assert }) => { + @Test() + public async shouldBeAbleToFormatLogsToRequestFormatAsJson({ assert }: TestContext) { const formatter = new RequestFormatter().config({ level: 'info', asJson: true }) const ctx = { @@ -82,13 +84,14 @@ test.group('RequestFormatterTest', () => { assert.equal(message.metadata.url, ctx.request.hostUrl) assert.equal(message.metadata.path, ctx.request.baseUrl) assert.isDefined(message.metadata.createdAt) - }) + } - test('should be able to set a string as ctx and dont get errors', async ({ assert }) => { + @Test() + public async shouldBeAbleToSetAStringAsCtxAndDontGetErrors({ assert }: TestContext) { const formatter = new RequestFormatter().config({ level: 'info', asJson: true }) const ctx = 'hello' assert.equal(formatter.format(ctx), 'hello') - }) -}) + } +} diff --git a/tests/Unit/Formatters/SimpleFormatterTest.ts b/tests/Unit/Formatters/SimpleFormatterTest.ts index 874d5cc..81f2179 100644 --- a/tests/Unit/Formatters/SimpleFormatterTest.ts +++ b/tests/Unit/Formatters/SimpleFormatterTest.ts @@ -7,11 +7,12 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' +import { Test, TestContext } from '@athenna/test' import { SimpleFormatter } from '#src/Formatters/SimpleFormatter' -test.group('SimpleFormatterTest', () => { - test('should be able to format logs to simple format', async ({ assert }) => { +export default class SimpleFormatterTest { + @Test() + public async shouldBeAbleToFormatLogsToSimpleFormat({ assert }: TestContext) { const formatter = new SimpleFormatter().config({ level: 'info' }) const message = formatter.format('hello') @@ -19,12 +20,13 @@ test.group('SimpleFormatterTest', () => { assert.isTrue(message.includes('[INFO]')) assert.isTrue(message.includes('hello')) assert.isTrue(message.includes(`(${process.pid})`)) - }) + } - test('should be able to format logs to simple format and force to clean the logs', async ({ assert }) => { + @Test() + public async shouldBeAbleToFormatLogsToSimpleFormatAndForceToCleanTheLogs({ assert }: TestContext) { const formatter = new SimpleFormatter().config({ level: 'info' }) const message = formatter.clean(formatter.format('hello'), true) assert.isFalse(message.includes('\x1B[38;5;51m\x1B[1m')) - }) -}) + } +} diff --git a/tests/Unit/Logger/VanillaLoggerTest.ts b/tests/Unit/Logger/VanillaLoggerTest.ts index ed0a233..7deac40 100644 --- a/tests/Unit/Logger/VanillaLoggerTest.ts +++ b/tests/Unit/Logger/VanillaLoggerTest.ts @@ -7,11 +7,12 @@ * file that was distributed with this source code. */ -import { test } from '@japa/runner' import { Exec, Path } from '@athenna/common' +import { Test, TestContext } from '@athenna/test' -test.group('VanillaLoggerTest', () => { - test('should be able to log in console using vanilla logger', async ({ assert }) => { +export default class VanillaLoggerTest { + @Test() + public async shouldBeAbleToLogInConsoleUsingVanillaLogger({ assert }: TestContext) { const { stdout, stderr } = await Exec.command(`ts-node --esm ${Path.stubs('transporters/vanillaLogger.ts')}`) const logs = [...stdout.split('\n').filter(l => l !== ''), ...stderr.split('\n').filter(l => l !== '')] @@ -20,5 +21,5 @@ test.group('VanillaLoggerTest', () => { assert.isFalse(log.includes('TRACE')) assert.isTrue(log.includes('hello')) }) - }) -}) + } +}