{"name":"zora","version":"2.0.0-0","description":"tap test harness for nodejs and browsers","keywords":["tap","test","node","browsers","testing","tests","harness","tap-producer"],"main":"./dist/","module":"index.js","jsnext:main":"index.js","repository":{"type":"git","url":"git+https://github.com/lorenzofox3/zora.git"},"scripts":{"clean":"rm -rf ./dist","clean:benchmark":"rm -r ./benchmarks && mkdirp ./benchmarks/zora/test/ ./benchmarks/ava/test ./benchmarks/jest/test ./benchmarks/mocha/test ./benchmarks/tape/test","build:benchmark":"npm run clean:benchmark && node ./scripts/generate.js","bench:zora":"time (node ./benchmarks/zora/index.js)","bench:ava":"time ava ./benchmarks/ava/test/","bench:mocha":"time mocha ./benchmarks/mocha/test/","bench:tape":"time (node ./benchmarks/tape/index)","bench:jest":"time jest","build":"npm run clean && rollup -c ./rollup/build.js && rollup -c ./rollup/build-cdn.js","test:unit":"rollup -c ./rollup/test.js | node","test":"npm run test:unit && node ./test/samples/index.js | tap-diff && node ./test/samples/bsd/index | tap-mocha-reporter spec","xo":"xo lib/*.js index.js"},"author":{"name":"Laurent Renard","email":"laurent34azerty@gmail.com"},"license":"MIT","dependencies":{"deep-equal":"^1.0.1"},"devDependencies":{"ava":"^0.25.0","jest":"^22.2.2","mkdirp":"^0.5.1","mocha":"^5.0.0","rollup":"^0.55.4","rollup-plugin-commonjs":"^8.3.0","rollup-plugin-node-resolve":"^3.0.2","tap-diff":"^0.1.1","tap-mocha-reporter":"^3.0.6","tape":"^4.8.0","xo":"^0.18.2"},"jest":{"testRegex":".*.js","roots":["./benchmarks/jest/test"],"testEnvironment":"node"},"readme":"# zora\n\nFast javascript test runner for **nodejs** and **browsers**\n\n[![CircleCI](https://circleci.com/gh/lorenzofox3/zora.svg?style=svg)](https://circleci.com/gh/lorenzofox3/zora)\n\n## installation\n``npm install --save-dev zora``\n\n## (Un)Opinions and Design\n\nThese are the following rules and ideas I have followed while developing zora. Whether they are right or not is an entire different topic ! :D\nNote I have decided to develop zora specially because I was not able to find a tool which complies entirely with these ideas.\n\n### Tests are regular Javascript programs.\n\nYou don't need a specific test runner, a specific platform or any build step to run your `zora` tests. They are only regular valid EcmaScript 2017 programs.\nIf you have the following test.\n```Javascript\nimport test from 'path/to/zora';\n\ntest('should result to the answer', t=>{\n    const answer = 42\n    t.equal(answer, 42, 'answer should be 42');\n});\n```\n\nYou can run your test with\n1. Node: ``node ./myTestFile.js``\n2. In the browser ``<script type=\"module\" src=\"./myTestFile.js></script>`` identically\n\nMoreover zora does not use specific platform API which should make it transparent to most of your tools such module bundlers or transpilers.\n\nIn few words:\n> Zora is only Javascript, no less, no more.\n\n### Tests are fast\n\nTests are part of our daily routine as software developers. Performance is part of the user experience and there is no reason you should wait seconds for your tests to run.\nZora is by far the **fastest** Javascript test runner in the ecosystem.\n\n### Benchmark\n\nThis repository includes a benchmark which consists on running N test files, with M tests in each and where one tests lasts T milliseconds.\nAbout 10% of tests should fail.\n\n1. profile library: N = 5, M = 8, T = 25ms\n2. profile web app: N = 10, M = 8, T = 40ms\n3. profile api: N =12, M = 10, T = 100ms\n\nEach framework runs with its default settings\n\nHere are the result of different test frameworks on my developer machine with node 9.3.0 :\n\n|        |  zora@2.0.0  |  tape@4.8.0 |  Jest@22.2.2  |  AvA@0.25.0  |  Mocha@5.0.0|\n|--------|:------------:|:-----------:|:-------------:|:------------:|------------:|\n|Library |  118ms       |  1239ms     |  1872ms       |  1703ms      |  1351ms     |\n|Web app |  142ms       |  3597ms     |  4356ms       |  2441ms      |  3757ms     |\n|API     |  203ms       |  12637ms    |  13385ms      |  2966ms      | 12751ms     |\n\nOf course as any benchmark, it may not cover your use case and you should probably run your own tests before you draw any conclusion\n\n### Focus on tests only\n\nzora does one thing but hopefully does it well: **test**.\n\nIn my opinions:\n1. Pretty reporting (I have not said *efficient reporting*) should be handled by a specific tool.\n2. Transipilation and other code transformation should be handled by a specific tool.\n3. File watching and caching should be handled by a specific tool.\n4. File serving should be handled by a specific tool.\n5. Coffee should me made by a specific tool.\n\nAs a result zora is only **1Kb** of code whereas it lets you use whatever better tool you want for any other specific task you may need within your workflow.\n\n### Control flow is managed the way you want with regular Javascript idioms\n\nLately Ecmascript specification has improved a lot (and its various implementation) in term of asynchronous code.\nThere is no reason you could not benefit from it while writing your tests.\nIn zora, asynchronous code is as simple as async function, you do not need to manage a plan or to notify the test framework the end of a test\n\n```Javascript\nimport test from 'zora';\n\ntest('should handle async operation', async t => {\n    const user = await getUserAsync();\n    t.deepEqual(user,{name:'John doe'});\n});\n```\n\n### Reporter is handled with other process (TAP)\n\nWhen you run a test you usually want to know whether there is any failure, where and why in order to debug and solve the issue as fast as possible.\nWhether you want it to be printed in red, yellow etc is a matter of preference.\n\nFor this reason, zora output [TAP](http://testanything.org/) (Test Anything Protocol) by default. This protocol is widely used and [there are plenty of tools](https://github.com/sindresorhus/awesome-tap) to parse and deal with it the way **you** want.\n\nYou are not stuck into a specific reporting format, you'll be using a *standard* instead.\n\n## Usage\n\nZora API is very straightforward: you have only **1** function and the assertion library is pretty standard and obvious.\nThe tests will start by themselves with no extra effort.\n\n```Javascript\nimport test from 'zora';\n\ntest('some independent test', t=>{\n    t.equal(1+1,2,'one plus one should equal 2');\n});\n\ntest('other independent test', t=>{\n    t.equal(1+2,3,'one plus two should equal 3');\n});\n```\n\n### Assertions API\n\nThe assertion api you can use within your test is pretty simple and highly inspired by [tape](https://github.com/substack/tape)\n* ok\n* notOk\n* equal\n* notEqual\n* deepEqual\n* notDeepEqual\n* throws\n* doesNotThrow\n* fail\n\n### Control flow\n\nNotice that each test runs in its own micro task in parallel (for performance). It implies your tests should not depend on each other.\nIt is often a good practice.\nHowever, you'll be able to group your tests if you wish to conserve some state between them or wait one to finish before you start another one (ideal with tests running against real database).\n\nThe sequence is simply controlled by AsyncFunction (and await keyboard)\n\n```Javascript\n\nlet state = 0;\n\ntest('test 1', t=>{\n    t.ok(true);\n    state++;\n});\n\ntest('test 2', t=>{\n    //Maybe yes maybe no, you have no guarantee ! In this case it will work as everything is sync\n    t.equal(state, 1);\n});\n\n//Same thing here even in nested tests\nt.test('grouped', t=>{\n    let state = 0;\n\n    t.test('test 1', t=>{\n        t.ok(true);\n        state++;\n    });\n\n    t.test('test 2', t=>{\n        //Maybe yes maybe no, you have no guarantee ! In this case it will work as everything is sync\n        t.equal(state, 1);\n    });\n});\n\n//And\nt.test('grouped', t=>{\n    let state = 0;\n\n    t.test('test 1', async t=>{\n        t.ok(true);\n        await wait(100);\n        state++;\n    });\n\n    test('test 2', t=>{\n        t.equal(state, 0, 'see the old state value as it will have started to run before test 1 is done');\n    });\n});\n\n//But\nt.test('grouped', async t=>{\n    let state = 0;\n\n    //specifically wait the end of this test before continuing !\n    await t.test('test 1', async t=>{\n        t.ok(true);\n        await wait(100);\n        state++;\n    });\n\n    test('test 2', t=>{\n        t.equal(state, 1, 'see the updated value!');\n    });\n});\n```\n\n### BDD style\n\nzora also allows you to nest tests in each other in a [BDD style](https://en.wikipedia.org/wiki/Behavior-driven_development).\nYou just need to call the `test` property of zora at root level.\n\n```\nimport zora from 'zora';\nconst describe = zora.test;\n\n// and write you tests\ndescribe('test 1', t => {\n\n\tt.ok(true, 'assert1');\n\n    // inside simply call t.test for nested test\n\tt.test('some nested test', t => {\n\t\tt.ok(true, 'nested 1');\n\t\tt.ok(true, 'nested 2');\n\t});\n\n\tt.test('some nested test bis', t => {\n\t\tt.ok(true, 'nested 1');\n\n\t\tt.test('deeply nested', t => {\n\t\t\tt.ok(true, 'deeply nested really');\n\t\t\tt.ok(true, 'deeply nested again');\n\t\t});\n\n\t\tt.ok(true, 'nested 2');\n\t});\n\n\tt.ok(true, 'assert2');\n});\n\ndescribe('test 2', t => {\n\tt.ok(true, 'assert3');\n\n\tt.test('nested in two', t => {\n\t\tt.ok(true, 'still happy');\n\t});\n\n\tt.ok(true, 'assert4');\n});\n```\n\nThe output is a valid tap output where sub plans are indented\n```\nTAP version 13\n    # Subtest: test 1\n    ok 1 - assert1\n        # Subtest: some nested test\n        ok 1 - nested 1\n        ok 2 - nested 2\n        1..2\n        # time=1ms\n    ok 2 - some nested test # time=1ms\n        # Subtest: some nested test bis\n        ok 1 - nested 1\n            # Subtest: deeply nested\n            ok 1 - deeply nested really\n            ok 2 - deeply nested again\n            1..2\n            # time=1ms\n        ok 2 - deeply nested # time=1ms\n        ok 3 - nested 2\n        1..3\n        # time=1ms\n    ok 3 - some nested test bis # time=1ms\n    ok 4 - assert2\n    1..4\n    # time=1ms\nok 1 - test 1 # time=1ms\n    # Subtest: test 2\n    ok 1 - assert3\n        # Subtest: nested in two\n        ok 1 - still happy\n        1..1\n        # time=1ms\n    ok 2 - nested in two # time=1ms\n    ok 3 - assert4\n    1..3\n    # time=1ms\nok 2 - test 2 # time=1ms\n1..2\n# ok\n```\n\nThe structure can be parsed with common tap parser (such as [tap-parser]()) And will be parsed as well by tap parser which\ndo not understand the indentation. However to take full advantage of the structure you should probably use a formatter (such [tap-mocha-reporter](https://www.npmjs.com/package/tap-mocha-reporter)) aware of this specific structure to get the whole benefit\nof the format.\n\n![tap output in a BDD format](./media/bsd.png)\n\n### In the browser\n\nZora itself does not depend on native nodejs modules (such file system, processes, etc) so the code you will get is regular EcmaScript.\n\n// todo add some more recipe (WIP) karma, dependencies, transpilations etc\n\n#### drop in file\nYou can simply drop the dist file in the browser and write your script below (or load it).\nYou can for example play with this [codepen](http://codepen.io/lorenzofox3/pen/zoejxv?editors=1112)\n\n```Html\n<!-- some content -->\n<body>\n<script type=\"module\">\n\nimport test from 'path/to/zora';\n\ntest('some test', (assert) => {\n    assert.ok(true, 'hey there');\n})\n\ntest('some failing test', (assert) => {\n    assert.fail('it failed');\n})\n</script>\n</body>\n<!-- some content -->\n```\n\n#### As part of CI (example with rollup)\nI 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.\n\nassuming you have your entry point as follow :\n```Javascript\n//./test/index.js\nimport test1 from './test1.js'; // some tests here\nimport test2 from './test2.js'; // some more tests there\nimport test3 from './test3.js'; // another test plan \n```\n\nwhere for example ./test/test1.js is \n```Javascript\nimport test from 'zora';\n\ntest('mytest',(assertions) => {\n   assertions.ok(true);\n})\n\ntest('mytest',(assertions) => {\n   assertions.ok(true);\n});\n```\nyou can then bundle your test as single app.\n\n```Javascript\nconst node = require('rollup-plugin-node-resolve');\nconst commonjs = require('rollup-plugin-commonjs');\nmodule.exports = {\n  input: './test/index.js',\n  output:[{\n    name:'test',\n    format:'test',\n    sourcemap:'inline' // ideal to debug\n  }]\n  plugins: [node(), commonjs()], //you can add babel plugin if you need transpilation\n};\n```\n\nYou can now drop the result into a debug file\n``rollup -c path/to/conf > debug.js``\n\nAnd read with your browser (from an html document for example).\n\n![tap output in the browser console](./media/console-sc.png)\n\nEven better, you can use tap reporter browser friendly such [tape-run](https://www.npmjs.com/package/tape-run) so you'll have a proper exit code depending on the result of your tests. \n\nso all together, in your package.json you can have something like that\n```Javascript\n{\n// ...\n  \"scripts\": {\n    \"test\": \"rollup -c path/to/conf | tape-run\"\n  }\n// ...\n}\n```","readmeFilename":"README.md","gitHead":"de3c7323eb4a355c5a0f376a4e8a5603e4f02513","bugs":{"url":"https://github.com/lorenzofox3/zora/issues"},"homepage":"https://github.com/lorenzofox3/zora#readme","_id":"zora@2.0.0-0","_npmVersion":"5.5.1","_nodeVersion":"9.3.0","_npmUser":{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"},"dist":{"integrity":"sha512-+JHZjxrvsaEsMnxo1ukhEx+4jLdVQTFurYzWHg64dFa4XtGSJVlraiOaT1YCIM13R3vV6VasCouY8eb8py793A==","shasum":"6ce23b3164b70fc4dbb46ab1c0b97bd9f89a0975","tarball":"http://registry-npm.ywwl.com/zora/download/zora-2.0.0-0.tgz","fileCount":14,"unpackedSize":140470,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCC15nLzRuhVFe3umR9KXgDatG2Qbzjji0FzCFzSHKWwAIgOWRV6gniUcWUIfTo9o86laH9jfUyTF0C0bcdA3J7Rfo="}],"size":26051,"noattachment":false,"key":"/zora/-/zora-2.0.0-0.tgz"},"maintainers":[{"name":"lorenzofox3","email":"laurent34azerty@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/zora_2.0.0-0_1518200502224_0.27956422607518094"},"_hasShrinkwrap":false,"publish_time":1518200503129,"_cnpm_publish_time":1518200503129,"dist-tags":{"latest":"6.0.4","next":"5.0.0-beta.1"}}