- minimalist ts/js testing framework
- deadass simple, no cli actually
- no funky instrumentation horseshit
- zero dependencies
- an https://e280.org/ project
- install science
npm install --save-dev @e280/science
- create your
tests.test.js
import {Science, suite, test, expect} from "@e280/science" await Science.run({ "addition works": test(async() => { expect(2 + 2).is(4) }), })
- run your tests in node
node tests.test.js
- watch mode (run-on-save!)
node --watch tests.test.js
- run the debugger
node inspect tests.test.js
- stick it in your package.json
"scripts": { "test": "node tests.test.js", "test-watch": "node --watch tests.test.js" },
// example test case
"addition works": test(async() => {
expect(2 + 2).is(4)
}),
// skip this test
// 👇
"addition works": test.skip(async() => {
expect(2 + 2).is(4)
}),
// only run this test
// 👇
"addition works": test.only(async() => {
expect(2 + 2).is(4)
}),
"addition works": test(async() => {
// fail by expectation
expect(2 + 2).is(5)
// fail by returning false
return false
// fail by throwing a string or error
throw "universe is broken"
}),
await Science.run({
"nesting": suite({
"deeper nesting": suite({
"addition works": test(async() => {
expect(2 + 2).is(4)
}),
}),
}),
})
suite.skip
workssuite.only
works
- the options object passed in via javascript gets top priority
await Science.run(myTestSuite, { // print all test cases verbose: true, // disable colors and emojis theme: Science.themes.plain, })
- the next fallback are cli arguments
node tests.test.js --verbose --theme=seaside
- (best practice) the next fallback are environment vars
SCIENCE_VERBOSE=1 SCIENCE_THEME=seaside node tests.test.js
- using environment variables is preferable to hard-coding anything
- this allows developers to choose their own preference
- they can simply run
export SCIENCE_VERBOSE=1
orexport SCIENCE_THEME=seaside
in their terminal before starting a science watch routine
redgreen
(default) errors are red, happy tests are greenseaside
better for color blindness, errors are red, happy tests are blueplain
no colors, no emojis
see all the expectations in expectations.ts
expect(2 + 2).is(4)
// custom fail note
expect(2 + 2, "universe is broken").is(2)
// custom fail note (alt syntax)
expect(2 + 2)
.note("universe is broken")
.is(2)
expect(2 + 2).isnt(4)
expect(2 + 2).gt(3)
expect(2 + 2).lt(5)
expect(2 + 2).gte(4)
expect(2 + 2).lte(4)
expect(() => {throw "lol"}).throws()
await expect(async() => {throw "lol"}).throwsAsync()
// you can ".not" anything
expect(2 + 2).not.is(5)
expect(2 + 2).not.isnt(4) // lol
expect(() => {throw "lol"}).not.throws()
build with us at https://e280.org/ but only if you're cool