Skip to content

Commit

Permalink
feat: add support for matching all the tags
Browse files Browse the repository at this point in the history
Closes: #60
  • Loading branch information
thetutlage committed Jun 22, 2023
1 parent e6636a6 commit 37295f5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/refiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import type { FilteringOptions } from './types.js'
* refiner.allows('tags', ['@regression']) // true
*/
export class Refiner {
/**
* Controls if test tags should match all the defined
* tags or not.
*
* Defaults to false
*/
#shouldMatchAllTags: boolean = false

/**
* A set of pinned tests
*/
Expand Down Expand Up @@ -129,6 +137,9 @@ export class Refiner {
/**
* Find one or more matching tags
*/
if (this.#shouldMatchAllTags) {
return this.#filters.tags.every((tag) => test.options.tags.includes(tag))
}
return this.#filters.tags.some((tag) => test.options.tags.includes(tag))
}

Expand All @@ -155,6 +166,18 @@ export class Refiner {
return this.#pinnedTests.has(test)
}

/**
* Enable/disable matching of all tags when filtering tests.
* If "matchAll" is enabled, the test tags should match
* all the user defined tags.
*
* Otherwise, any one match will pass the filter
*/
matchAllTags(state: boolean): this {
this.#shouldMatchAllTags = state
return this
}

/**
* Pin a test to be executed.
*/
Expand Down
18 changes: 18 additions & 0 deletions test/test/execute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,24 @@ test.describe('execute | refiner', () => {
assert.deepEqual(stack, ['executed'])
})

test('do not run test when all tags are not matched', async () => {
const stack: string[] = []
const emitter = new Emitter()
const refiner = new Refiner({})

refiner.add('tags', ['@slow', '@regression'])
refiner.matchAllTags(true)

const testInstance = new Test('2 + 2 = 4', new TestContext(), emitter, refiner)
testInstance.tags(['@regression'])
testInstance.run(async () => {
stack.push('executed')
})

const [, event] = await Promise.all([testInstance.exec(), pEvent(emitter, 'test:end', 8000)])
assert.isNull(event)
})

test('do not run test when there are pinned tests and the current one is not pinned', async () => {
const stack: string[] = []
const emitter = new Emitter()
Expand Down

0 comments on commit 37295f5

Please sign in to comment.