Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base test classes #185

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <lenon@athenna.io>",
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 <lenon@athenna.io>
*
* 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 <lenon@athenna.io>
*
* 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'],
})
}
}
Loading