Bas. Client side integration testing made much less painful.
Behaviour Assertion Sheets are a new way to assert to a test library how the front-end aspects of your website are intended to fit together. The syntax is familiar to anybody who has ever used CSS - simple, declarative, no cruft.
It's much less painful. It might even be fun.
Bas (pronounced ‘base’) is written in JavaScript, and runs in the server atop Node.js. I’m hoping that other people contribute new, better implementations for different stacks - and help specify Bas as a defacto standard.
@page (domain ="cgiffard.github.io" ) (path ="/Behaviour-Assertion-Sheets/" ) {status-code : 200;.intro h1 {/* Don't want to experience any pain here! */ ; } text :contains ("less painful" )section p.intro:nth-child(1) {; text :contains ("simple" ),/declarative/i ; } } attribute(pain-level) :lt (99999 )
What can I use Bas for?
Integration Testing
Plug Bas into your CI system to so you immediately know when you've introduced a bug or broken the build.
Availability Monitoring
Move beyond if (503)
- and keep tabs on when your site
or app is up, and serving content in the way you'd expect.
Accessibility Compliance
Automatically test for common accessibility pitfalls, or poor code.
Reporting
Track out how your site or application is structured. Find and analyse failures and quirks.
Getting started with Bas in your own projects
Installing
Until somebody builds an additional Bas implementation, it runs exclusively inside of node.js, so you'll need to have both it and npm installed and available.
(Fortunately, there's a lot of guides for that, so I doubt you'll get stuck - if you're not already well on top of it!)
Then just do an npm install -g bas
in your terminal.
A new bas
command should be available to use anywhere!
I hope to have a screencast ready showing the basics soon.
Writing & running tests
Before you can run tests, you'll need some tests to run!
If you'd like to dive straight into writing tests, there's some examples in the repo you can work from. Alternately the documentation offers a detailed guide to the grammar.
Then use the bas
CLI to run them. The (general) syntax is:
bas --sheet (your BAS sheet filename) [http://urltotest/ ... ]
You can also commence a crawl using the --crawl
option, or provide a list of URLS to be sequentially tested
instead. For a full list of options, run bas -h
.
Try this for size
Still TL;DR? OK, try this.
echo " @all (content-type = /^text\/html/) { status-code: 200; img { attribute(alt): required; } } " | bas -v -n 10 --crawl http://example.com/
Integration with Travis & Jenkins
It is relatively easy to integrate Bas with Jenkins/Travis - just
plug a bas
invocation into your Jenkins job/Travis test
scripts like you'd call out to anything else.
If you're writing a node project, and you have an existing test suite, you're in luck. You don't have to shell out to nothin'! Use the ultra-straightforward Node API to run Bas tests inside your existing test framework (like mocha.)
Get in touch, or contribute!
I'm Christopher Giffard.
You can find me on Twitter and ADN. I'm also readily contactable via email at [firstname] DOT [lastname] AT cgiffard.com.
At the moment, I'm just one guy writing the best code I think I can. It would be wonderful if you'd like to contribute to the project - or especially write a Bas implementation for another language!
The Todo List (MVC and or otherwise)
There's a few things that Bas really needs right now, if you'd like to take a stab at them:
- More tests in the test suite!
- Alternate implementations
- More assertion tests
- Documentation clean-up and friendly-ification
- It'd be cool if somebody wrote a cross-compiler for selenium
Send me a pull request!