All Projects → bearror → oletus

bearror / oletus

Licence: MIT license
Minimal ECMAScript Module test runner

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to oletus

Ava
Node.js test runner that lets you develop with confidence 🚀
Stars: ✭ 19,458 (+45151.16%)
Mutual labels:  unit-testing, tdd, test-runner, test-framework
Testfx
MSTest V2 framework and adapter
Stars: ✭ 391 (+809.3%)
Mutual labels:  tdd, test-runner, test-framework
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (-4.65%)
Mutual labels:  unit-testing, test-runner, test-framework
tropic
🍍 Test Runner Library
Stars: ✭ 29 (-32.56%)
Mutual labels:  unit-testing, test-runner, test-framework
Dredd
Language-agnostic HTTP API Testing Tool
Stars: ✭ 3,770 (+8667.44%)
Mutual labels:  unit-testing, test-runner, test-framework
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (+746.51%)
Mutual labels:  tdd, test-runner, test-framework
Bash unit
bash unit testing enterprise edition framework for professionals
Stars: ✭ 419 (+874.42%)
Mutual labels:  unit-testing, tdd, test-framework
Zunit
A powerful testing framework for ZSH projects
Stars: ✭ 140 (+225.58%)
Mutual labels:  unit-testing, test-runner, test-framework
Quiz App
A repository reflecting the progress made on the "How to Build iOS Apps with Swift, TDD & Clean Architecture" YouTube series, by Caio & Mike.
Stars: ✭ 230 (+434.88%)
Mutual labels:  unit-testing, tdd
Alsatian
TypeScript testing framework with test cases
Stars: ✭ 244 (+467.44%)
Mutual labels:  unit-testing, tdd
tape-es
ESM-compatible Tape.js test runner
Stars: ✭ 24 (-44.19%)
Mutual labels:  esmodules, esm
book-fullstack-react-with-typescript
Working through the code samples from Fullstack React with Typescript by Maksim Ivanov and Alex Bespoyasov
Stars: ✭ 52 (+20.93%)
Mutual labels:  unit-testing, tdd
Transport Eta
Twitch streamed 🎥playground repo, README speaks to you.
Stars: ✭ 223 (+418.6%)
Mutual labels:  unit-testing, tdd
tau
A Micro (1k lines of code) Unit Test Framework for C/C++
Stars: ✭ 121 (+181.4%)
Mutual labels:  unit-testing, test-framework
Truth
Fluent assertions for Java and Android
Stars: ✭ 2,359 (+5386.05%)
Mutual labels:  unit-testing, test-framework
Fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, .NET Core 2.1 and 3.0, as well as .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
Stars: ✭ 2,449 (+5595.35%)
Mutual labels:  unit-testing, tdd
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-23.26%)
Mutual labels:  unit-testing, tdd
testza
Full-featured test framework for Go! Assertions, fuzzing, input testing, output capturing, and much more! 🍕
Stars: ✭ 409 (+851.16%)
Mutual labels:  unit-testing, test-framework
babel-plugin-rewire-exports
Babel plugin for stubbing [ES6, ES2015] module exports
Stars: ✭ 62 (+44.19%)
Mutual labels:  unit-testing, esm
PixelTest
Fast, modern, simple iOS snapshot testing written purely in Swift.
Stars: ✭ 56 (+30.23%)
Mutual labels:  tdd, test-framework

oletus

Build Status

A zero configuration, zero dependency test runner for ECMAScript Modules—made specifically for getting started quick. Painless migration to the bigger guns if you end up needing them.

Features

  • Native ECMAScript Modules support.
  • Simple: No configuration. No test timeouts. No global scope pollution. No runner hooks. No compilation step. No source maps.
  • Super fast: Asynchronous tests run concurrently, individual modules run concurrently using multiple CPUs, no overhead from compilation.

Usage

Test Syntax

import test from 'oletus'

// this should look pretty familiar
test('arrays are equal', t => {
  t.deepEqual([1, 2], [1, 2])
})

// you can use async functions or otherwise return Promises
test('bar', async t => {
  const bar = Promise.resolve('bar')
  t.equal(await bar, 'bar')
})

Add oletus to your project

Install it with npm:

npm install --save-dev oletus

Modify the test script in your package.json:

{
  "test": "oletus"
}

Older versions of Node

On Node 12 you need to pass --experimental-modules:

{
  "test": "node --experimental-modules --no-warnings -- ./node_modules/.bin/oletus"
}

For even older Node versions, use esm:

{
  "test": "node -r esm -- ./node_modules/.bin/oletus"
}

Test locations

By default, Oletus runs all files that exist in your /test directory. Alternatively, you can specify a list of files to run. Note that the glob pattern in the example below is handled by your shell, not by Oletus.

{
  "test": "oletus test.js src/**/*.test.mjs"
}

Reporters

Oletus has a concise reporter on local runs and a verbose reporter on CI environments.

API

test :: (String, StrictAssertModule -> Promise?) -> Promise TestResult

The test function, which is the default export from Oletus, takes the following arguments:

  • title: A String describing the test case.
  • implementation: A function that runs your assertions. The implementation has a single parameter (t, for example) that gets passed the strict node assertion module. If this function returns a Promise, Oletus awaits the result to know if your test passes. Otherwise the test is assumed to pass if it doesn't throw.

The return value from test function is a Promise of an object with the following shape { didPass, title, location, message }. Note that for most cases, you don't actually need to do anything with the returned Promise, but for reference, this is what its resolution value looks like:

  • didPass: A boolean to indicate whether the test has passed.
  • title: The title of the test.
  • location: The stack trace for the failure reason, or an empty string if didPass was true.
  • message The failure reason, or an empty string if didPass was true.

Examples

Code coverage

Oletus works great together with c8. C8 is a tool for running code coverage natively using the V8 built-in code coverage functionality. The reason this pairs well with Oletus is because with Oletus, you tend to run your ESM code natively, and no other coverage tools can deal with that. Set it up like this:

{
  "test": "c8 oletus test.js src/**/*.test.mjs"
}

Using Oletus for testing CommonJS modules

Your codebase doesn't need to be written as EcmaScript 6 modules to use Oletus. The only part of your code that really needs to contain es6 modules is your tests themselves. But you're free to import CommonJS modules via CommonJS Interoperability:

import test from 'oletus'
import myCJSModule from '../src/index.js'

test ('my export', t => {
  t.equals (myCJSModule.myExportedAnswer, 42)
})

Running tests in sequence instead of parallely

Because the test function returns a Promise, all you need to do is add await statements in front of your tests to run them in sequence. Note that your runtime needs to support top-level-await. Otherwise you can wrap your tests in an async function and call it at the end of your file.

await test('foo', async t => {
  const foo = Promise.resolve('foo')
  t.equal(await foo, 'foo')
})

await test('bar', async t => {
  const bar = Promise.resolve('bar')
  t.equal(await bar, 'bar')
})

Completely custom test run order

Because the test function returns a Promise, you can manipulate the run order of your tests in any way you see fit. For example, you could execute your tests in batches of 2 by awaiting Promise.all calls.

await Promise.all([
  test('first', () => {}),
  test('second', () => {}),
])

await Promise.all([
  test('third', () => {}),
  test('fourth', () => {}),
])

Setup and teardown

Because the test function returns a Promise, it's quite straight-forward to wrap a test in setup and teardown logic:

const testWithDatabase = async (title, implementation) => {
  const database = await setupDatabase()
  await test (title, t => implementation(t, database))
  await teardownDatabase()
}

testWithDatabase ('has users', async (t, database) => {
  const users = await database.queryUsers()
  t.equals (users, [{ name: 'bob' }])
})

Programmatic use

Besides the CLI, there's also an interface for programmatic use:

import run from 'oletus/runner.mjs'
import concise from 'oletus/report-concise.mjs'

const { passed, failed, crashed } = await run(['test/index.mjs'], concise)

console.log (
  '%s tests passed, %s tests failed, and %s files crashed',
  passed, failed, crashed
)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].