diff --git a/package-lock.json b/package-lock.json index 500c719..c112b09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/core", - "version": "4.4.0", + "version": "4.5.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/core", - "version": "4.4.0", + "version": "4.5.0", "license": "MIT", "dependencies": { "pretty-repl": "^3.1.2", diff --git a/package.json b/package.json index f3b779d..9742133 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/core", - "version": "4.4.0", + "version": "4.5.0", "description": "The plug and play Node.js framework.", "license": "MIT", "author": "João Lenon ", @@ -50,7 +50,9 @@ "./commands/ReplCommand": "./src/commands/ReplCommand.js", "./commands/ServeCommand": "./src/commands/ServeCommand.js", "./commands/TestCommand": "./src/commands/TestCommand.js", - "./commands/BuildCommand": "./src/commands/BuildCommand.js" + "./commands/BuildCommand": "./src/commands/BuildCommand.js", + "./testing/BaseCliTest": "./src/testing/BaseCliTest.js", + "./testing/BaseRestTest": "./src/testing/BaseRestTest.js" }, "imports": { "#bin/*": "./bin/*.js", @@ -105,6 +107,7 @@ ], "exclude": [ "src/types/*", + "src/testing/*.ts", "src/commands/*.ts", "src/applications/Repl.ts" ], diff --git a/src/testing/BaseCliTest.ts b/src/testing/BaseCliTest.ts new file mode 100644 index 0000000..04b3cba --- /dev/null +++ b/src/testing/BaseCliTest.ts @@ -0,0 +1,40 @@ +/** + * @athenna/core + * + * (c) João Lenon + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { Options } from '@athenna/common' +import { BeforeAll } from '@athenna/test' +import { Artisan } from '@athenna/artisan' +import { Ignite, type IgniteOptions } from '@athenna/core' + +export class BaseCliTest { + public ignite: Ignite + public igniteOptions: IgniteOptions = {} + + @BeforeAll() + public async baseBeforeAll() { + this.ignite = await new Ignite().load( + import.meta.url, + this.getIgniteOptions(), + ) + } + + public async execute( + command: string, + ): Promise<{ stdout: string; stderr: string }> { + return Artisan.callInChild(command, Path.bootstrap('artisan.ts')) + } + + private getIgniteOptions() { + return Options.create(this.igniteOptions, { + bootLogs: false, + loadConfigSafe: false, + environments: ['test'], + }) + } +} diff --git a/src/testing/BaseRestTest.ts b/src/testing/BaseRestTest.ts new file mode 100644 index 0000000..8966d9d --- /dev/null +++ b/src/testing/BaseRestTest.ts @@ -0,0 +1,47 @@ +/** + * @athenna/core + * + * (c) João Lenon + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { Options } from '@athenna/common' +import { ServerImpl } from '@athenna/http' +import { AfterAll, BeforeAll } from '@athenna/test' +import { Ignite, type HttpOptions, type IgniteOptions } from '@athenna/core' + +export class BaseRestTest { + public ignite: Ignite + public restServer: ServerImpl + public restOptions: HttpOptions = {} + public igniteOptions: IgniteOptions = {} + + @BeforeAll() + public async baseBeforeAll() { + this.ignite = await new Ignite().load( + import.meta.url, + this.getIgniteOptions(), + ) + + this.restServer = await this.ignite.httpServer(this.getRestOptions()) + } + + @AfterAll() + public async baseAfterAll() { + await this.restServer.close() + } + + private getRestOptions() { + return Options.create(this.restOptions, {}) + } + + private getIgniteOptions() { + return Options.create(this.igniteOptions, { + bootLogs: false, + loadConfigSafe: false, + environments: ['test'], + }) + } +}