Giter Site home page Giter Site logo

baretest's Introduction

Baretest is an extremely simple JavaScript test runner. It has a tiny footprint, near-instant performance, and a brainless API. It makes testing tolerable.

How Baretest fits on the testing landscape

Install

npm install --save-dev baretest

With pnpm

pnpm install --save-dev baretest

Links

Documentation

... Getting started

... API reference

... FAQ

Why Baretest?

We constantly hit CMD + B on Sublime Text to test a function we are actively working on. We do this all the time, sometimes hundreds of times a day. With Jest, each of these runs would take seconds, but Baretest runs under 100ms.

A typical setup in Sublime Text

Comparing Jest vs Baretest

Another reason for building Baretest was to have an extremely simple API. Typically we only use test() and the Node's built-in assert.equals() methods to run our tests. We've never needed automatic re-ordering, file watchers, "mocking" or "snapshotting".

const test = require('baretest')('My app'),
  assert = require('assert'),
  app = require('my-app')

test('add user', async function() {
  const user = await app.addUser('[email protected]')
  assert.equals(user.name, 'Test')
})

test('reject duplicate emails', async function() {
  await assert.rejects(async function() {
    await app.addUser('[email protected]')
  })
})

// ...

!(async function() {
  await test.run()
})()

We think a good test runner stays out of your way. We want to focus on the task at hand and not deal with the complexities of testing. We don't want to commit to a massive framework that dictates our work.

License

Copyright 2020 OpenJS Foundation and contributors. Licensed under MIT.

baretest's People

Contributors

roryokane avatar tipiirai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

baretest's Issues

Support TypeScript

Description

I really love the simplicity of baretest but it would be great if a typing file could be provided for TypeScript users like myself. Perhaps a TypeScript support has already been in your roadmap.

Browser support

Given I have some code that creates a DOM Node like this

const button = () => {
  const btn = document.createElement('button')
  btn.addEventListener('click', e => { console.log(e) })
  btn.innerHTML = 'CLICK ME PLZ'

  return btn
}

what do I need to include with baretest in order to have a browser environment and not receive DOM-related not-defined/reference errors when testing?

Would you recommend pulling in jsdom or something? Are there any baretest examples of working with the DOM?

Add afterEach and beforeEach

I love the main goal which is simplicity, but I think an afterEach and beforeEach methods will not clutter the code and can make a big difference.

Remove the two trailing line breaks from the console output

Why did you add the two trailing line breaks? They add an unnecessary white space to the log from a complete build & test phases. For example:

$ node test
test • • ✓ 2


$

If you have multiple test suites, it gets worse:

$ node test
test1 • • ✓ 2


test2 • • ✓ 2


$

How about removing the two line breaks to achieve the following output?

$ node test
test • • ✓ 2
$

$ node test
test1 • • ✓ 2
test2 • • ✓ 2
$

can you help understand this code example from the docs

The documentation includes a code example like this:

const test = require('baretest')('My app'),
  assert = require('assert'),
  app = require('my-app')

require('./test/users')(test, assert, app)
require('./test/teams')(test, assert, app)

// ...

!(async function() {
  await test.run()
})()

What do the test files in ./test/users look like to make this work? do they just default export a function like function(test, assert, app) ?

Verify performance claims

Hey,

Im going through examples in readme and in https://volument.com/baretest but as far as i can tell, just copy pasting them throws errors.

It would be nice to have a repo to clone to:

  1. see how to set it up. currently i dont understand what this supposed to be const test = require('.')('sum'), in docs. And its not lack of my js knowledge that bothers me.
  2. verify the performance claims

Examples in README and documentation use wrong API

First of all thanks for baretest! I'm a long time mocha user, super frustrated with the perf of jest and really happy to see this minimal test runner coming by!

I found two errors in the documentation.

Example #1 (both README and docs):

const test = require('baretest'),
  assert = require('assert'),
  app = require('my-app')

test('add user', async function() {
...

The example should call require('basetest')('Test descr') before adding tests.

Example #2 (docs):

const assert = require('assert'),
  test = require('baretest'),
  app = require('my-app')

require('./test/users')(test, assert, app)
require('./test/teams')(test, assert, app)
require('./test/sharing')(test, assert, app)
require('./test/commenting')(test, assert, app)
require('./test/billing')(test, assert, app)
// require('./test/mailer')(test, assert, app)
// require('./test/management')(test, assert, app)

!(async function() {
  await test.run()
})()

There is no toplevel test.run()! Actually, it would be convenient to have it, but then you'd have to keep state in your module, and we'd need a test.reset() or so too. I just now used baretest but by wrapping the mocha describe/it-API, so could keep track of different suites over different files myself, but how would you otherwise do it without the toplevel .run?

add snapshot support

Hey, I really love the project but snapshot support would be a huge plus, or maybe at least provide something 3rd party?

And specifically, one of the greatest things about jest is toMatchInlineSnapshot

Input test name when calling function

This would be useful for snapshot testing, so you don't need to explicitly re-type the snapshot name.

This is what code would look like:

test('add user', async function({ testName }) {
  await assertSnapshot(testName, 'this should be same as last time')
})

Tests exit with error code 0

I just converted from nodeunit to baretest and here's my feedback:

Failing tests still exit with error code 0

const test = require('baretest')('Sum tests'),
  assert = require('assert');

test('1 + 2', function() {
  assert.equal(1 + 2, 12);
});

test.run();

node test will report that the test fails and highlight it in red, but the exit code is 0, so any CI will mark the build as success and carry on as if nothing happens.

Try this node test && echo "SUCCESS!!!".

Annoying to split tests in multiple files

The example about organizing multiple tests is a bit too minimal.
First of all, you'll have to remember to add your new test file inside that test index, so you risk forgetting adding one.
Second, all tests are called My App which doesn't help that much when you're trying to fix a broken test.

We think a good test runner stays out of your way.

I think it should also prevent people from making mistakes. It's a test tool after all.

I think it would be nice to have a baretest-cli or something else to better manage tests split in multiple files.

Here's what I ended up using:

test/
 |- index.js
 |- test1.test.js
 |- test2.test.js
 |- ...test.js

And inside test/index.js

const fs = require("fs");
const baretest = require("baretest");

fs.readdir(__dirname, async (err, files) => {
  if (err) throw err;
  for (let fileName of files.filter((_) => _.endsWith(".test.js"))) {
    const test = baretest(fileName);
    require(`./${fileName}`)(test);
    const success = await test.run();
    if (success === false) {
      process.exit(1);
    }
  }
});

So any file that ends with .test.js is automatically included and gets a different test name. Also checks the return value of test.run().

I dont get what should be in a distributed test

Hi, I just get how to make your single test file example to work. Thanks for that,

What I don't get is what should be in the files required that make this example to work.

Can you please share a sample file so I can replicate this pattern:

const test = require('baretest')('My app'),
  assert = require('assert'),
  app = require('my-app')

require('./test/users')(test, assert, app)
require('./test/teams')(test, assert, app)
require('./test/sharing')(test, assert, app)
require('./test/commenting')(test, assert, app)
require('./test/billing')(test, assert, app)
// require('./test/mailer')(test, assert, app)
// require('./test/management')(test, assert, app)

!(async function() {
  await test.run()
})()

Thank you.

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.