Skip to content

Commit

Permalink
Merge pull request #210 from AthennaIO/develop
Browse files Browse the repository at this point in the history
chore(test): clean up application state after all tests
  • Loading branch information
jlenon7 authored Jan 25, 2024
2 parents 77cb0e1 + 7407b82 commit 14b6a2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "4.24.0",
"version": "4.25.0",
"description": "The plug and play Node.js framework.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
15 changes: 13 additions & 2 deletions src/testing/BaseConsoleTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
* file that was distributed with this source code.
*/

import { Options } from '@athenna/common'
import { BeforeAll } from '@athenna/test'
import { Json, Options } from '@athenna/common'
import { AfterAll, BeforeAll } from '@athenna/test'
import { Ignite, type IgniteOptions } from '@athenna/core'
import { TestCommand } from '@athenna/artisan/testing/plugins'

export class BaseConsoleTest {
private env = Json.copy(process.env)
private config = Json.copy(Config.get())
public ignite: Ignite
public igniteOptions: IgniteOptions = {}
public artisanPath: string = Path.bootstrap(`artisan.${Path.ext()}`)
Expand All @@ -27,6 +29,15 @@ export class BaseConsoleTest {
)
}

@AfterAll()
public async baseAfterAll() {
ioc.reconstruct()
process.env = Json.copy(this.env)
Object.keys(this.config).forEach(key =>
Config.set(key, Json.copy(this.config[key]))
)
}

private getIgniteOptions() {
return Options.create(this.igniteOptions, {
bootLogs: false,
Expand Down
9 changes: 8 additions & 1 deletion src/testing/BaseHttpTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
* file that was distributed with this source code.
*/

import { Options } from '@athenna/common'
import { ServerImpl } from '@athenna/http'
import { Json, Options } from '@athenna/common'
import { AfterAll, BeforeAll } from '@athenna/test'
import { Ignite, type HttpOptions, type IgniteOptions } from '@athenna/core'

export class BaseHttpTest {
private env = Json.copy(process.env)
private config = Json.copy(Config.get())
public ignite: Ignite
public httpServer: ServerImpl
public httpOptions: HttpOptions = {}
Expand All @@ -31,6 +33,11 @@ export class BaseHttpTest {
@AfterAll()
public async baseAfterAll() {
await this.httpServer.close()
ioc.reconstruct()
process.env = Json.copy(this.env)
Object.keys(this.config).forEach(key =>
Config.set(key, Json.copy(this.config[key]))
)
}

private getHttpOptions() {
Expand Down

0 comments on commit 14b6a2f

Please sign in to comment.