Skip to content

Latest commit

 

History

History
148 lines (95 loc) · 4.82 KB

README.md

File metadata and controls

148 lines (95 loc) · 4.82 KB

testease

A simplified/toy Mocha-inspired test framework.

Generic badge

Codacy Badge codecov

GitHub License

Single file, without minifying, and no dependencies in production.

Testease size Testease size


Table of Contents


Installation

Download testease.js and drop it somewhere accessible to your project.


Usage

  'use strict'

  import { describe, it, reporter } from './testease.js'

  async function selfExam () {
    describe('Testease Framework')

    await it('is simple and familiar enough', async function () {
      return true
    }, 6900)

    const results = await reporter()

    return results
  }

  selfExam().then((result) => {
    console.log(result)
  })

For more see the source code in testease.js, and related tests in self-exam.js.


Documentation

function describe (label, testFunc[, timeout = -1])

Describe what is going to be tested. For creating blocks.

  • label - required; Shown in test results.

async function it (label, testFunc[, timeout = -1])

A single test. The testFunc function must return true to pass.

  • label - required; Shown in test results.
  • testFunc - required; A single test as a func; must return true to pass.
  • timeout - optional; Millisecond timeout of async testFunc. Default = -1, disabled.

async function it.fails (label, testFunc[, timeout = -1])

A single test. The testFunc function must return false to pass.

  • label - required; Shown in test results.
  • testFunc - required; A single test as a func; must return false to pass.
  • timeout - optional; ms timeout of async testFunc. Default = -1, disabled.

async function reporter

Test results are built up by running tests. This adds on the time taken from tests starting to reporter being called, and calculates the percentage passed for "N% passed (N passed/N total)".

  • no args

Returns the results as a string.


Why?

A few years ago while using Mocha I got frustrated and annoyed by it repeatedly. So, I wanted to see if I could make something with no dependencies that is lighter, faster, and easier to use. The original testease was faster and lighter even with the overhead of instrumenting the code. It was also hard to maintain or debug. In the years since I've built a few more basic test frameworks, first in Bash and later in JS, which slowly circled back to this again.


License

MIT License

Copyright (c) 2024 Tom Shaver

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.