Giter Club home page Giter Club logo

assert-raisins's Introduction

Assert-raisins

Minimalistic, debugger friendly test runner for Node.

Inspired by baretest

Features

  • fast
  • parallel
  • run test for a line number
  • no nesting
  • better test cleanup (than after hooks)
  • esm
  • typescript types included

Usage

Install:

npm i --save-dev assert-raisins

Write a test test/firstTest.js:

import { test } from 'assert-raisins'
import assert from 'node:assert'

test('first passing test', () => {
  assert.ok(true)
})

test('first failing test', async () => {
  assert.equal(1, 2)
})

Run all tests:

./node_modules/.bin/ars test/**/*Test.js

Run individual test:

# by line number
./node_modules/.bin/ars test/someTest.js:123

Other things available:

  • it which is an alias for test
  • beforeEach() to run some code before each test in a file
  • beforeAll() to run some code before all tests in a file

Test cleanup

Use cleanup function to register some cleanup hook. If it happens to be called within beforeAll, it will be executed "after all". If it's called within beforeEach, it'll be run "after each", and if it's called within a test, it will be executed after that test. cleanup can be invoked multiple times.

In this example, the server will be stopped after each test:

import { cleanup } from 'assert-raisins'

class Server {
  start() {
    ...
    cleanup(() => this.stop())
  }
}

beforeEach(async () => {
  const server = new Server()
  await server.start()
})

Parallel tests

When running multiple test files, the load is distributed between concurrent workers (limited by the number of CPU cores). Each worker is passed TEST_WORKER_ID environment variable (so you can, for instance, create that many test databases).

typescript, jsx, sourcemaps, code coverage

Use NODE_OPTIONS environment variable for any of that. For example, for typescript:

NODE_OPTIONS="--enable-source-maps --loader ts-node/esm" ./node_modules/.bin/ars test/*.test.ts

assert-raisins's People

Contributors

artemave avatar joshski avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

joshski

assert-raisins's Issues

TypeScript example

Can you show me how you would use this with TypeScript?

I created a project here:

https://github.com/joshski/ars-test

Following the example mentioned in the readme, I get:

โžœ  ars-test git:(main) NODE_OPTIONS="--enable-source-maps --loader ts-node/esm"  ./node_modules/.bin/ars ./exploratory.test.ts
(node:27800) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
(Use `node --trace-warnings ...` to show where the warning was created)
(node:27800) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/Users/josh/ars-test/exploratory.test.ts:1
import { test } from 'assert-raisins'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1290:20)
    at Module._compile (node:internal/modules/cjs/loader:1342:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32)
    at Module._load (node:internal/modules/cjs/loader:1028:12)
    at cjsLoader (node:internal/modules/esm/translators:359:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:308:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)

Node.js v21.6.0

What else do I need to do to get this working with TypeScript?

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.