Skip to content

Commit

Permalink
Merge pull request #78 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Add tests using inheritance and fix bug under it
  • Loading branch information
jlenon7 authored Mar 14, 2023
2 parents b11e901 + d7d99ff commit 06cf6ca
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ process.env.IS_TS = 'true'
configure({
...processCliArgs(process.argv.slice(2)),
...{
files: ['tests/**/*Test.ts'],
files: ['tests/Unit/**/*Test.ts'],
plugins: [assert()],
reporters: [specReporter()],
importer: Importer.import,
Expand Down
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/test",
"version": "3.2.0",
"version": "3.2.1",
"description": "The Athenna test runner. Built on top of Japa.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
4 changes: 4 additions & 0 deletions src/Converters/TestConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class TestConverter {
* Convert test options of decorators to Japa test options.
*/
public static async convert(closure: any, options: TestOptions) {
if (!closure) {
return
}

const test = japaTest(options.title)

this.whenDefined(options.pin, () => test.pin())
Expand Down
10 changes: 9 additions & 1 deletion src/Helpers/Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ export class Importer {
}

const test = new Test()
const bind = (method: string) => test[method].bind(test)
const bind = (method: string) => {
const closure = test[method]

if (!closure) {
return null
}

return closure.bind(test)
}

const {
tests,
Expand Down
Empty file removed tests/Stubs/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions tests/Stubs/BaseTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @athenna/test
*
* (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 { BeforeEach } from '#src'

export class BaseTest {
public BEFORE_EACH_EXECUTED = false

@BeforeEach()
public async beforeEach() {
this.BEFORE_EACH_EXECUTED = true
}
}
18 changes: 18 additions & 0 deletions tests/Unit/InheritanceOneTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @athenna/test
*
* (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 { Test, TestContext } from '#src'
import { BaseTest } from '#tests/Stubs/BaseTest'

export default class InheritanceOneTest extends BaseTest {
@Test()
public async shouldBeAbleToUseInheritanceInTestInheritanceOneTestClass({ assert }: TestContext) {
assert.equal(this.BEFORE_EACH_EXECUTED, true)
}
}
18 changes: 18 additions & 0 deletions tests/Unit/InheritanceTwoTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @athenna/test
*
* (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 { Test, TestContext } from '#src'
import { BaseTest } from '#tests/Stubs/BaseTest'

export default class InheritanceTwoTest extends BaseTest {
@Test()
public async shouldBeAbleToUseInheritanceInTestInheritanceTwoTestClass({ assert }: TestContext) {
assert.equal(this.BEFORE_EACH_EXECUTED, true)
}
}

0 comments on commit 06cf6ca

Please sign in to comment.