UNPKG

3.85 kBMarkdownView Raw
1# zora
2A less than 200 lines of code javascript test harness for **nodejs** and the **browser**
3
4[![CircleCI](https://circleci.com/gh/lorenzofox3/zora.svg?style=svg)](https://circleci.com/gh/lorenzofox3/zora)
5
6## features
7### Zero config
8It is just Javascript, write your program, bundle it (if needed) for the environment you want to test in and execute the script ! No whatever.conf.js
9
10### No global
11There is no global, just a function providing a two methods api.
12
13### Async testing made easy
14Your tests will run coroutines handled by [co](https://github.com/tj/co). So you can write your asynchronous test in a synchronous manner, no need for a callback or to plan ahead.
15```Javascript
16
17plan.test('my async test',function *(assert){
18 const resolvedResult = yield db.findUser('foo');
19 assert.deepEqual(resolvedResult, {name:'foo'}, 'should have fetched mister foo');
20});
21
22```
23
24
25### parallelism
26Each test run in a separate coroutine using [co](https://github.com/tj/co). It will likely be **faster** than other sequential test runners like [tape](https://github.com/substack/tape) for example.
27It therefore enforces you to write your tests in isolation which is often a good practice.
28
29### tap producer
30By default zora produces a tap report through the console, so you can pipe in with any [tap reporter](https://github.com/sindresorhus/awesome-tap#reporters).
31
32### browser friendly
33No sophisticated or platform specific (nodejs) dependency in it. Just regular es2016 Javascript.
34You bundle your test program with your favorite module bundler as you would do for you app anyway, and drop it in a browser (or use browser friendly tap reporter).
35
36## Usage
37### simple case one file
38```Javascript
39
40import zora from 'zora';
41
42// you create a test plan
43const plan = zora();
44
45plan
46 .test('a test',function * (assertion){
47 assertion.equal('foo','foo');
48 })
49 .test('another test', function *(assertion){
50 assertion.ok(true)
51 })
52 .run(); // you run it
53```
54### multiple files setup (recommended)
55You might want to split your tests in various files. The recommended way is to make each file exports its own plan... and create a plan of plans.
56The main advantages are:
57* you'll be able to run your test files separately with the command line tool
58* you'll have a single entry point which makes things easier if you want to use a module bundler for example
59```Javascript
60
61//./test/test1.js
62import zora from 'zora';
63
64const plan = zora();
65
66plan
67 .test('a test',function * (assertion){
68 assertion.equal('foo','foo');
69 })
70 .test('another test', function *(assertion){
71 assertion.ok(true)
72 })
73
74export default plan; // export the plan
75
76
77 //./test/index.js
78import zora from 'zora';
79import plan from './test1.js'; // import all your test plans
80
81// you create a test plan
82const masterPlan = zora();
83
84masterPlan
85 .test(plan)
86 .run(); // and run your plans (you can omit this line if you want use the command line tool)
87```
88
89## In the browser
90Zora itself does not depend on native nodejs modules so the code you will get is regular es2016 code. The only thing to do is probably to bundle your test script with your favourite module bundler (you might want to transpile your code as well for older browsers).
91
92### Example with rollup
93I will use [rollup](http://rollupjs.org/) for this example, but you should not have any problem with [webpack](https://webpack.github.io/) or [browserify](http://browserify.org/). The idea is simply to create a test file your testing browsers will be able to run.
94
95assuming you have your entry point as follow :
96```Javascript
97//./test/index.js
98import zora from 'zora';
99import test1 from './test1.js;
100import test2 from './test2.js;
101import test3 from './test3.js;
102
103const plan = zora()
104 .test(test1)
105 .test(test2)
106 .test(test3)
107
108plan.run();
109```
110
111
112
113
114
115
\No newline at end of file