- 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.jsimport {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.skipworkssuite.onlyworks
- 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=1orexport SCIENCE_THEME=seasidein their terminal before starting a science watch routine
redgreen(default) errors are red, happy tests are greenseasidebetter for color blindness, errors are red, happy tests are blueplainno colors, no emojis
see all the expectations in expectations.ts
const x = 2 + 2
expect(x).is(4)
// custom fail note
expect(x, "universe is broken").is(2)
// custom fail note (alt syntax)
expect(x)
.note("universe is broken")
.is(2)
expect(x).isnt(4)
expect(x).gt(3)
expect(x).lt(5)
expect(x).gte(4)
expect(x).lte(4)
expect(x).happy() // not undefined or null
expect(x).sad() // undefined or null
expect(() => {throw "lol"}).throws()
await expect(async() => {throw "lol"}).throwsAsync()
// you can ".not" anything
expect(x).not.is(5)
expect(x).not.isnt(4) // lol
expect(() => {throw "lol"}).not.throws()build with us at https://e280.org/ but only if you're cool




