Coder Social home page Coder Social logo

mvasilkov / smol Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 0.0 19 KB

A JavaScript test runner. Like Mocha but smol.

Home Page: https://www.npmjs.com/package/smoltest

License: MIT License

JavaScript 100.00%
javascript test mocha smol no-dependencies

smol's Introduction

smol

A JavaScript test runner. Like Mocha but smol.

Ok so basically I'm very smol

npm no dependencies


Why smol

  • No global variables
  • No dependencies
  • Basically it's very smol

Installation

npm add smoltest

Synopsis

smol <DIR>

Usage

Put the following code in a file:

const assert = require('assert').strict
const { describe, it } = require('smoltest')(exports)

describe('String', () => {
    it('#concat()', () => {
        assert.strictEqual('a'.concat('b'), 'ab')
    })

    it('#repeat()', () => {
        assert.strictEqual('a'.repeat(2), 'aa')
    })
})

File: string.test.js

Run the tests:

npx smol .

Test files are those

  • Starting with test and ending with .js
  • Ending with .test.js
  • Ending with .spec.js

Syntax

Smol supports the following Mocha syntax:

Mocha "BDD" ๐Ÿ”— Mocha "TDD" ๐Ÿ”—
describe suite
it test
before suiteSetup
after suiteTeardown
beforeEach setup
afterEach teardown
context
specify
xdescribe
xit

Unlike Mocha, these functions aren't global. They can be imported as follows:

const { describe, it, beforeEach, afterEach } = require('smoltest')(exports)

You can also write test functions without any special syntax whatsoever, similar to pytest. Make sure to export any functions that are meant to be test cases with names starting with test.

For example:

const assert = require('assert').strict

exports['test Array#concat()'] = () => {
    assert.deepStrictEqual(['a'].concat(['b']), ['a', 'b'])
}

exports['test Array#fill()'] = () => {
    assert.deepStrictEqual(Array(2).fill('a'), ['a', 'a'])
}

File: array.test.js

License

MIT

smol's People

Contributors

mvasilkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.