Thanks to visit codestin.com
Credit goes to github.com

Skip to content

hazae41/phobos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

94 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Modern and minimalist testing library

npm install @hazae41/phobos
deno install jsr:@hazae41/phobos

πŸ“¦ NPM β€’ πŸ“¦ JSR

Philosophy 🧠

Phobos aims to be minimalist and to always work no matter the:

  • runtime (Node, Deno, browser)
  • module resolution (ESM, CommonJS)
  • language (TypeScript, JavaScript)
  • bundler (Rollup, Vite)

It's just a library you can import everywhere! That's it, no CLI, no configuration file, just JavaScript.

Features πŸ”₯

Current features

  • 100% TypeScript and ESM
  • No external dependency
  • Unit tested (by itself)
  • Runnable in the browser
  • Minimalist assertion helpers
  • Asynchronous fork-join parallelism
  • Function calls spying

Usage πŸš€

import { assert, test } from "@hazae41/phobos"

test("it should work", () => {
  assert(false, "oh no")
})

Concurrent tests

Test blocks are always executed concurrently, unless you await them

import { assert, test } from "@hazae41/phobos"

test("it should work", async ({ test }) => {
  
  // run in sequence
  await test("first test", async () => {
    assert(true, "should be true")
  })
  
  // or in parallel
  test("second test", async () => {
    assert(true, "should be true")
  })
})

You can also use await Promise.all(...) to forcefully join

import { assert, test } from "@hazae41/phobos"

test("it should work", async ({ test }) => {
  const tests = []
  
  tests.push(test("first test", async () => {
    assert(true, "should be true")
  }))
  
  tests.push(test("second test", async () => {
    assert(true, "should be true")
  }))

  // wait first and second tests
  await Promise.all(tests)

  tests.push(test("third test", async () => {
    assert(true, "should be true")
  }))

  // wait last test
  await Promise.all(tests)
})

Spying function calls

You can spy on function calls using spy(function)

You can then .call() it and get a list of all its .calls

import { assert, test, spy } from "@hazae41/phobos"

test("it should work", async () => {
  const f = spy((param: boolean) => !param)

  const result = f.call(true)
  assert(result === false, `result should be false`)

  assert(f.calls.length === 1, `should have been called 1 time`)
  assert(f.calls[0].params[0] === true, `should have been called with true`)
  assert(f.calls[0].result === false, `should have resulted in false`)
})

Running 🏎️

Node

node --test --test-concurrency=1 ./out/**/*.test.js

Deno

deno test ./src/**/*.test.ts

Other

await import("./mymodule.test.ts")

Sponsor this project

  •  

Packages

No packages published

Contributors 2

  •  
  •