Skip to content

Commit

Permalink
refactor: remove dead code and improve tests coverage
Browse files Browse the repository at this point in the history
Breaking change: The test.title toString no longer returns the original test title
  • Loading branch information
thetutlage committed Dec 16, 2023
1 parent a9bbd75 commit 8b98a4e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 11 deletions.
9 changes: 0 additions & 9 deletions src/test/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export class DummyRunner {
title: {
original: this.#test.options.title,
expanded: this.#test.options.title,
toString() {
return this.original
},
},
isPinned: this.#test.isPinned,
}
Expand All @@ -57,9 +54,6 @@ export class DummyRunner {
title: {
original: this.#test.options.title,
expanded: this.#test.options.title,
toString() {
return this.original
},
},
isPinned: this.#test.isPinned,
hasError: false,
Expand Down Expand Up @@ -190,9 +184,6 @@ export class TestRunner {
return {
original: title,
expanded: dataset ? interpolate(title, dataset.row, dataset.index + 1) : title,
toString() {
return this.original
},
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export type TestStartNode = Omit<TestOptions, 'title'> & {
title: {
original: string
expanded: string
toString(): string
}
isPinned: boolean
dataset?: {
Expand All @@ -167,7 +166,6 @@ export type TestEndNode = Omit<TestOptions, 'title'> & {
title: {
original: string
expanded: string
toString(): string
}
isPinned: boolean
duration: number
Expand Down
33 changes: 33 additions & 0 deletions tests/refiner/refiner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,37 @@ test.describe('Refiner', () => {
refiner.add('groups', [groupInstance.title])
assert.isFalse(refiner.allows(loneTestInstance))
})

test('add filters via constructor', () => {
const refiner = new Refiner({
groups: ['Maths'],
tags: ['@slow'],
tests: ['add two numbers'],
})

const emitter = new Emitter()

const group = new Group('Maths', emitter, refiner)

/**
* All filters pass
*/
const testInstance1 = new Test('add two numbers', {}, emitter, refiner, group)
testInstance1.tags(['@slow'])
assert.isTrue(refiner.allows(testInstance1))

/**
* Title filter fails
*/
const testInstance = new Test('2 + 2 = 4', {}, emitter, refiner, group)
testInstance.tags(['@slow'])
assert.isFalse(refiner.allows(testInstance))

/**
* Title + tag filter fails
*/
const testInstance2 = new Test('subtract two number', {}, emitter, refiner, group)
group.add(testInstance2)
assert.isFalse(refiner.allows(testInstance2))
})
})
42 changes: 42 additions & 0 deletions tests/test/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ test.describe('configure', () => {
})
})

test('define timeout using the resetTimeout method', async () => {
const testInstance = new Test('2 + 2 = 4', new TestContext(), new Emitter(), new Refiner({}))
testInstance.resetTimeout(6000)

assert.deepEqual(testInstance.options, {
tags: [],
title: '2 + 2 = 4',
timeout: 6000,
meta: {},
})
})

test('disable timeout using the resetTimeout method', async () => {
const testInstance = new Test('2 + 2 = 4', new TestContext(), new Emitter(), new Refiner({}))
testInstance.resetTimeout()

assert.deepEqual(testInstance.options, {
tags: [],
title: '2 + 2 = 4',
timeout: 0,
meta: {},
})
})

test('define test retries', async () => {
const testInstance = new Test('2 + 2 = 4', new TestContext(), new Emitter(), new Refiner({}))
testInstance.retry(4)
Expand Down Expand Up @@ -201,6 +225,24 @@ test.describe('configure', () => {
assert.deepEqual(Test2.executingCallbacks, [])
})

test('throw error when child class does not initialize callbacks properties', async () => {
class Test1 extends Test<any, any> {
static executedCallbacks = []
}
class Test2 extends Test<any, any> {
static executingCallbacks = []
}

assert.throws(
() => new Test1('2 + 2 = 4', new TestContext(), new Emitter(), new Refiner({})),
'Define static property "executingCallbacks = []" on Test1 class'
)
assert.throws(
() => new Test2('2 + 2 = 4', new TestContext(), new Emitter(), new Refiner({})),
'Define static property "executedCallbacks = []" on Test2 class'
)
})

test('inherit parent callbacks', async () => {
function disposeCallback() {}
function disposeCallback1() {}
Expand Down

0 comments on commit 8b98a4e

Please sign in to comment.