Skip to content

Commit

Permalink
fix: make skip and only also a suite
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Nov 17, 2023
1 parent 31d3ce2 commit d7a5c41
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
26 changes: 26 additions & 0 deletions mocks/tops/test3.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { suite, assert, test as _test } from '../../src/taps/index.js'
import delay from 'delay'

let test = suite('test3').skip

test.before(() => {
console.log('before')
})

test('test assert', () => {
assert.match('foo', /foo/)
assert.doesNotMatch('fiii', /foo/)
assert.equal(3, 32)

assert.type('ssss', 'string')
assert.instance(new Date(), Date)
})

test(
'test timeout',
async () => {
await delay(200)
assert.type(() => {}, 'function')
},
{ timeout: 100 }
)
24 changes: 20 additions & 4 deletions src/taps/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function log(ctx, fail, time) {
const symbol = fail
? kleur.red('✘')
: ctx.skip
? kleur.yellow('-')
: kleur.green('✔')
? kleur.yellow('-')
: kleur.green('✔')
const _time = kleur.gray(`(${time})`)
const _msg = `${ctx.suite ? ctx.suite + ' > ' : ''}${ctx.name}`

Expand Down Expand Up @@ -231,7 +231,7 @@ export function suite(name = '') {
}

/**
* @type {import('./types.js').TestMethod}
* @type {import('./types.js').Suite}
*/
test.skip = function (name, fn, options = defaultOptions) {
ctx.tests.push({
Expand All @@ -242,7 +242,7 @@ export function suite(name = '') {
}

/**
* @type {import('./types.js').TestMethod}
* @type {import('./types.js').Suite}
*/
test.only = function (name, fn, options = defaultOptions) {
globalThis.TAPS_ONLY = true
Expand All @@ -253,6 +253,22 @@ export function suite(name = '') {
})
}

test.only.test = test.only
test.only.skip = test.skip
test.only.only = test.only
test.only.after = test.after
test.only.before = test.before
test.only.beforeEach = test.beforeEach
test.only.afterEach = test.afterEach

test.skip.test = test.skip
test.skip.skip = test.skip
test.skip.only = test.only
test.skip.after = () => {}
test.skip.before = () => {}
test.skip.beforeEach = () => {}
test.skip.afterEach = () => {}

TAPS_QUEUE.push(runner.bind(0, ctx))

return test
Expand Down
4 changes: 2 additions & 2 deletions src/taps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export interface SuiteContext {
export interface Suite {
(name: string, fn: Fn, options?: Test['options']): void
test: TestMethod
only: TestMethod
skip: TestMethod
only: Suite
skip: Suite
before: HookMethod
after: HookMethod
beforeEach: HookMethod
Expand Down
3 changes: 1 addition & 2 deletions src/taps/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export function stack(err) {
.replaceAll('file://', '')
.split('\n')

// remove one line from the stack trace from "p-timeout"
for (let i = 0; i < arr.length - 1; i++) {
for (let i = 0; i < arr.length; i++) {
const line = arr[i].trim()
if (line.length > 0 && !IGNORE.test(line)) {
out += '\n ' + line
Expand Down

0 comments on commit d7a5c41

Please sign in to comment.