Skip to content
This repository has been archived by the owner on May 23, 2021. It is now read-only.

Commit

Permalink
add top level cases support
Browse files Browse the repository at this point in the history
  • Loading branch information
v1rtl committed Mar 8, 2021
1 parent d07a3ea commit 326b249
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 9 additions & 11 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ const msg = (...x: string[]) => Deno.stdout.writeSync(new TextEncoder().encode(x
const testSuites: {
name: string
cases: { name: string; case: Fn }[]
}[] = [
{
name: '',
cases: []
}
]
}[] = []
let currSuite = 0,
totalSuites = 0,
totalCases = 0
totalSuites = 0

/**
* Run a test suite
Expand All @@ -40,8 +34,8 @@ export function describe(name: string, fn: () => void) {
* ```
*/
export function it(name: string, fn: Fn) {
if (!testSuites[currSuite]) testSuites[currSuite] = { name: '', cases: [] }
testSuites[currSuite].cases.push({ name, case: fn })
totalCases++
}

let failedCases = 0
Expand All @@ -65,10 +59,14 @@ export const run = () => {
let failedSuites = 0

testSuites.forEach((suite, i) => {
msg(`\n${suite.name} \n`)
if (suite.name !== '') msg(`\n${suite.name} \n`)

suite.cases.forEach((t, ii) => {
msg(` ${gray(t.name)}\n`)
if (suite.name === '') {
msg(`${t.name}\n`)
} else {
msg(` ${gray(t.name)}\n`)
}

Deno.test({
name: t.name,
Expand Down
4 changes: 4 additions & 0 deletions mod_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ describe('it()', () => {
})
})

it('should support top-level cases', () => {
expect(1).toBe(1)
})

run()

0 comments on commit 326b249

Please sign in to comment.