Skip to content

Commit

Permalink
chore(annotation): ignore properties already defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Apr 27, 2024
1 parent 0836217 commit 425bfd8
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 27 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/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 <lenon@athenna.io>",
Expand Down
4 changes: 3 additions & 1 deletion src/annotations/AfterAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion src/annotations/AfterEach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion src/annotations/BeforeAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion src/annotations/BeforeEach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions src/converters/TestConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
12 changes: 0 additions & 12 deletions src/mocks/MockBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/decorators/AfterAllDecoratorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/decorators/AfterEachDecoratorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/decorators/BeforeAllDecoratorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/decorators/BeforeEachDecoratorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 425bfd8

Please sign in to comment.