From 8cf9688c5200025aa6a1089426de72e0d03f1d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 14 Mar 2023 15:24:10 -0300 Subject: [PATCH 1/2] test(inheritance): add tests to cover inheritance scenarios --- tests/Stubs/.gitkeep | 0 tests/Stubs/BaseTest.ts | 19 +++++++++++++++++++ tests/Unit/InheritanceTest.ts | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) delete mode 100644 tests/Stubs/.gitkeep create mode 100644 tests/Stubs/BaseTest.ts create mode 100644 tests/Unit/InheritanceTest.ts diff --git a/tests/Stubs/.gitkeep b/tests/Stubs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/Stubs/BaseTest.ts b/tests/Stubs/BaseTest.ts new file mode 100644 index 0000000..94b2fcc --- /dev/null +++ b/tests/Stubs/BaseTest.ts @@ -0,0 +1,19 @@ +/** + * @athenna/test + * + * (c) João Lenon + * + * 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 + } +} diff --git a/tests/Unit/InheritanceTest.ts b/tests/Unit/InheritanceTest.ts new file mode 100644 index 0000000..6bf41c3 --- /dev/null +++ b/tests/Unit/InheritanceTest.ts @@ -0,0 +1,18 @@ +/** + * @athenna/test + * + * (c) João Lenon + * + * 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 InheritanceTest extends BaseTest { + @Test() + public async shouldBeAbleToUseInheritanceInTestClasses({ assert }: TestContext) { + assert.equal(this.BEFORE_EACH_EXECUTED, true) + } +} From d7d99ff25a1cfd0c145c3633d157eb70452c03cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 14 Mar 2023 17:46:54 -0300 Subject: [PATCH 2/2] fix(inheritance): ignore methods not found in test class --- bin/test.ts | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/Converters/TestConverter.ts | 4 ++++ src/Helpers/Importer.ts | 10 +++++++++- ...nheritanceTest.ts => InheritanceOneTest.ts} | 4 ++-- tests/Unit/InheritanceTwoTest.ts | 18 ++++++++++++++++++ 7 files changed, 37 insertions(+), 7 deletions(-) rename tests/Unit/{InheritanceTest.ts => InheritanceOneTest.ts} (69%) create mode 100644 tests/Unit/InheritanceTwoTest.ts diff --git a/bin/test.ts b/bin/test.ts index 3ad3fbc..b5d7e56 100644 --- a/bin/test.ts +++ b/bin/test.ts @@ -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, diff --git a/package-lock.json b/package-lock.json index 27082f8..b1517e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/test", - "version": "3.2.0", + "version": "3.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/test", - "version": "3.2.0", + "version": "3.2.1", "license": "MIT", "devDependencies": { "@athenna/common": "^3.3.1", diff --git a/package.json b/package.json index fcba762..8bc3388 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/Converters/TestConverter.ts b/src/Converters/TestConverter.ts index 3a42a8b..f3f9364 100644 --- a/src/Converters/TestConverter.ts +++ b/src/Converters/TestConverter.ts @@ -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()) diff --git a/src/Helpers/Importer.ts b/src/Helpers/Importer.ts index db5030a..d9cd061 100644 --- a/src/Helpers/Importer.ts +++ b/src/Helpers/Importer.ts @@ -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, diff --git a/tests/Unit/InheritanceTest.ts b/tests/Unit/InheritanceOneTest.ts similarity index 69% rename from tests/Unit/InheritanceTest.ts rename to tests/Unit/InheritanceOneTest.ts index 6bf41c3..742a56e 100644 --- a/tests/Unit/InheritanceTest.ts +++ b/tests/Unit/InheritanceOneTest.ts @@ -10,9 +10,9 @@ import { Test, TestContext } from '#src' import { BaseTest } from '#tests/Stubs/BaseTest' -export default class InheritanceTest extends BaseTest { +export default class InheritanceOneTest extends BaseTest { @Test() - public async shouldBeAbleToUseInheritanceInTestClasses({ assert }: TestContext) { + public async shouldBeAbleToUseInheritanceInTestInheritanceOneTestClass({ assert }: TestContext) { assert.equal(this.BEFORE_EACH_EXECUTED, true) } } diff --git a/tests/Unit/InheritanceTwoTest.ts b/tests/Unit/InheritanceTwoTest.ts new file mode 100644 index 0000000..02c9bfa --- /dev/null +++ b/tests/Unit/InheritanceTwoTest.ts @@ -0,0 +1,18 @@ +/** + * @athenna/test + * + * (c) João Lenon + * + * 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) + } +}