From 425bfd8f508d1049150681b1ae009940b58a9963 Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Sat, 27 Apr 2024 19:03:06 +0100 Subject: [PATCH] chore(annotation): ignore properties already defined --- package-lock.json | 4 ++-- package.json | 2 +- src/annotations/AfterAll.ts | 4 +++- src/annotations/AfterEach.ts | 4 +++- src/annotations/BeforeAll.ts | 4 +++- src/annotations/BeforeEach.ts | 4 +++- src/converters/TestConverter.ts | 8 ++++---- src/mocks/MockBuilder.ts | 12 ------------ tests/unit/decorators/AfterAllDecoratorTest.ts | 2 +- tests/unit/decorators/AfterEachDecoratorTest.ts | 2 +- tests/unit/decorators/BeforeAllDecoratorTest.ts | 2 +- tests/unit/decorators/BeforeEachDecoratorTest.ts | 2 +- 12 files changed, 23 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index cbfa1bc..99180d4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/test", - "version": "4.21.0", + "version": "4.23.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/test", - "version": "4.21.0", + "version": "4.23.0", "license": "MIT", "dependencies": { "@japa/assert": "^2.1.0", diff --git a/package.json b/package.json index 9c49500..7e8343d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/test", - "version": "4.22.0", + "version": "4.23.0", "description": "The Athenna test runner. Built on top of Japa.", "license": "MIT", "author": "João Lenon ", diff --git a/src/annotations/AfterAll.ts b/src/annotations/AfterAll.ts index de76737..ce49e17 100644 --- a/src/annotations/AfterAll.ts +++ b/src/annotations/AfterAll.ts @@ -22,7 +22,9 @@ export function AfterAll(): MethodDecorator { const afterAllHooks = Reflect.getMetadata('hooks:afterAll', Target) - afterAllHooks.push({ method: property }) + if (!afterAllHooks.includes(property)) { + afterAllHooks.push(property) + } Reflect.defineMetadata('hooks:afterAll', afterAllHooks, Target) } diff --git a/src/annotations/AfterEach.ts b/src/annotations/AfterEach.ts index 74dfe87..4fd34a2 100644 --- a/src/annotations/AfterEach.ts +++ b/src/annotations/AfterEach.ts @@ -22,7 +22,9 @@ export function AfterEach(): MethodDecorator { const afterEachHooks = Reflect.getMetadata('hooks:afterEach', Target) - afterEachHooks.push({ method: property }) + if (!afterEachHooks.includes(property)) { + afterEachHooks.push(property) + } Reflect.defineMetadata('hooks:afterEach', afterEachHooks, Target) } diff --git a/src/annotations/BeforeAll.ts b/src/annotations/BeforeAll.ts index f339d1f..daffe96 100644 --- a/src/annotations/BeforeAll.ts +++ b/src/annotations/BeforeAll.ts @@ -22,7 +22,9 @@ export function BeforeAll(): MethodDecorator { const beforeAllHooks = Reflect.getMetadata('hooks:beforeAll', Target) - beforeAllHooks.push({ method: property }) + if (!beforeAllHooks.includes(property)) { + beforeAllHooks.push(property) + } Reflect.defineMetadata('hooks:beforeAll', beforeAllHooks, Target) } diff --git a/src/annotations/BeforeEach.ts b/src/annotations/BeforeEach.ts index edcab90..c5fad50 100644 --- a/src/annotations/BeforeEach.ts +++ b/src/annotations/BeforeEach.ts @@ -22,7 +22,9 @@ export function BeforeEach(): MethodDecorator { const beforeEachHooks = Reflect.getMetadata('hooks:beforeEach', Target) - beforeEachHooks.push({ method: property }) + if (!beforeEachHooks.includes(property)) { + beforeEachHooks.push(property) + } Reflect.defineMetadata('hooks:beforeEach', beforeEachHooks, Target) } diff --git a/src/converters/TestConverter.ts b/src/converters/TestConverter.ts index 7bf8d16..25e2e24 100644 --- a/src/converters/TestConverter.ts +++ b/src/converters/TestConverter.ts @@ -101,7 +101,7 @@ export class TestConverter { public beforeAll(group: Group) { const hooks = Reflect.getMetadata('hooks:beforeAll', this.TestClass) || [] - hooks.forEach(({ method }) => { + hooks.forEach(method => { const closure = Options.bind(this.testClass, method) if (!closure) { @@ -126,7 +126,7 @@ export class TestConverter { public beforeEach(group: Group) { const hooks = Reflect.getMetadata('hooks:beforeEach', this.TestClass) || [] - hooks.forEach(({ method }) => { + hooks.forEach(method => { const closure = Options.bind(this.testClass, method) if (!closure) { @@ -151,7 +151,7 @@ export class TestConverter { public afterAll(group: Group) { const hooks = Reflect.getMetadata('hooks:afterAll', this.TestClass) || [] - hooks.forEach(({ method }) => { + hooks.forEach(method => { const closure = Options.bind(this.testClass, method) if (!closure) { @@ -176,7 +176,7 @@ export class TestConverter { public afterEach(group: Group) { const hooks = Reflect.getMetadata('hooks:afterEach', this.TestClass) || [] - hooks.forEach(({ method }) => { + hooks.forEach(method => { const closure = Options.bind(this.testClass, method) if (!closure) { diff --git a/src/mocks/MockBuilder.ts b/src/mocks/MockBuilder.ts index 341238e..3da7b72 100644 --- a/src/mocks/MockBuilder.ts +++ b/src/mocks/MockBuilder.ts @@ -22,16 +22,6 @@ export class MockBuilder { */ private sandbox: SinonSandbox - /** - * Holds the instance of the stubbed object. - */ - private object: any - - /** - * Holds the method of the stubbed object - */ - private method: any - public constructor( sandbox: SinonSandbox, object: any, @@ -45,8 +35,6 @@ export class MockBuilder { } this.sandbox = sandbox - this.object = object - this.method = method this.stub = this.sandbox.stub(object, method).callsFake((...args) => { return this.stub.wrappedMethod.bind(object)(...args) diff --git a/tests/unit/decorators/AfterAllDecoratorTest.ts b/tests/unit/decorators/AfterAllDecoratorTest.ts index 7a59e31..b503012 100644 --- a/tests/unit/decorators/AfterAllDecoratorTest.ts +++ b/tests/unit/decorators/AfterAllDecoratorTest.ts @@ -19,7 +19,7 @@ test.group('AfterAllAnnotationTest', () => { const afterAllHooks = Reflect.getMetadata('hooks:afterAll', MyClass) - assert.deepEqual(afterAllHooks, [{ method: 'afterAll' }]) + assert.deepEqual(afterAllHooks, ['afterAll']) }) test('should register tests and hooks metadata default array value if not defined', async ({ assert }) => { diff --git a/tests/unit/decorators/AfterEachDecoratorTest.ts b/tests/unit/decorators/AfterEachDecoratorTest.ts index faa6511..c37ad75 100644 --- a/tests/unit/decorators/AfterEachDecoratorTest.ts +++ b/tests/unit/decorators/AfterEachDecoratorTest.ts @@ -19,7 +19,7 @@ test.group('AfterEachAnnotationTest', () => { const afterEachHooks = Reflect.getMetadata('hooks:afterEach', MyClass) - assert.deepEqual(afterEachHooks, [{ method: 'afterEach' }]) + assert.deepEqual(afterEachHooks, ['afterEach']) }) test('should register tests and hooks metadata default array value if not defined', async ({ assert }) => { diff --git a/tests/unit/decorators/BeforeAllDecoratorTest.ts b/tests/unit/decorators/BeforeAllDecoratorTest.ts index 1f94e2f..1f642e2 100644 --- a/tests/unit/decorators/BeforeAllDecoratorTest.ts +++ b/tests/unit/decorators/BeforeAllDecoratorTest.ts @@ -19,7 +19,7 @@ test.group('BeforeAllAnnotationTest', () => { const beforeAllHooks = Reflect.getMetadata('hooks:beforeAll', MyClass) - assert.deepEqual(beforeAllHooks, [{ method: 'beforeAll' }]) + assert.deepEqual(beforeAllHooks, ['beforeAll']) }) test('should register tests and hooks metadata default array value if not defined', async ({ assert }) => { diff --git a/tests/unit/decorators/BeforeEachDecoratorTest.ts b/tests/unit/decorators/BeforeEachDecoratorTest.ts index 8b5006d..7a4b324 100644 --- a/tests/unit/decorators/BeforeEachDecoratorTest.ts +++ b/tests/unit/decorators/BeforeEachDecoratorTest.ts @@ -19,7 +19,7 @@ test.group('BeforeEachAnnotationTest', () => { const beforeEachHooks = Reflect.getMetadata('hooks:beforeEach', MyClass) - assert.deepEqual(beforeEachHooks, [{ method: 'beforeEach' }]) + assert.deepEqual(beforeEachHooks, ['beforeEach']) }) test('should register tests and hooks metadata default array value if not defined', async ({ assert }) => {