Skip to content

Commit

Permalink
Merge pull request #185 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Add base test classes
  • Loading branch information
jlenon7 authored Sep 5, 2023
2 parents 4e7b3eb + 11c1527 commit 8745d0e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -105,6 +107,7 @@
],
"exclude": [
"src/types/*",
"src/testing/*.ts",
"src/commands/*.ts",
"src/applications/Repl.ts"
],
Expand Down
40 changes: 40 additions & 0 deletions src/testing/BaseCliTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @athenna/core
*
* (c) João Lenon <[email protected]>
*
* 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'],
})
}
}
47 changes: 47 additions & 0 deletions src/testing/BaseRestTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @athenna/core
*
* (c) João Lenon <[email protected]>
*
* 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'],
})
}
}

0 comments on commit 8745d0e

Please sign in to comment.