volument / baretest Goto Github PK
View Code? Open in Web Editor NEWAn extremely fast and simple JavaScript test runner.
License: MIT License
An extremely fast and simple JavaScript test runner.
License: MIT License
Extremely similar:
https://gist.github.com/earonesty/2a8ac3a03e88ac90292cc28c823eb80b
Added:
I just converted from nodeunit to baretest and here's my feedback:
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!!!"
.
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()
.
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?
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.
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')
})
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
?
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
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)
?
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:
const test = require('.')('sum'),
in docs. And its not lack of my js knowledge that bothers me.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
$
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.