{"id":13846825,"url":"https://github.com/kt3k/kocha","last_synced_at":"2025-07-12T08:30:49.911Z","repository":{"id":37693217,"uuid":"93113821","full_name":"kt3k/kocha","owner":"kt3k","description":":tea: Modern, simpler Mocha clone, no globals, lint friendly","archived":true,"fork":false,"pushed_at":"2024-09-17T06:47:13.000Z","size":2394,"stargazers_count":69,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T22:30:24.192Z","etag":null,"topics":["bdd","karma-plugin","mocha","test","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kt3k.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-02T01:19:55.000Z","updated_at":"2024-09-17T06:47:48.000Z","dependencies_parsed_at":"2023-02-18T03:00:26.635Z","dependency_job_id":"a63a05ca-a1a9-480a-91b2-9b32502d920d","html_url":"https://github.com/kt3k/kocha","commit_stats":{"total_commits":321,"total_committers":6,"mean_commits":53.5,"dds":0.2710280373831776,"last_synced_commit":"767adfe80ae38cfd82f84b0f962e3b4158734e49"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fkocha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fkocha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fkocha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kt3k%2Fkocha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kt3k","download_url":"https://codeload.github.com/kt3k/kocha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225807346,"owners_count":17527238,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdd","karma-plugin","mocha","test","unit-testing"],"created_at":"2024-08-04T18:00:48.489Z","updated_at":"2024-11-21T21:30:43.175Z","avatar_url":"https://github.com/kt3k.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# \u003cimg src=\"https://kt3k.github.io/kocha/media/logo.svg\" /\u003e\n\n\n\n![CI](https://github.com/kt3k/kocha/workflows/CI/badge.svg)\n[![codecov](https://codecov.io/gh/kt3k/kocha/branch/master/graph/badge.svg)](https://codecov.io/gh/kt3k/kocha)\n[![npm](https://img.shields.io/npm/v/kocha.svg)](https://npm.im/kocha)\n\n\n\u003e Modern, simpler Mocha clone, no globals, lint friendly\n\nSupports node.js \u003e= maintained LTS.\n\n# Use in node.js\n\n## :cd: Install\n\n    npm install kocha --save-dev\n\n\nRequire `describe`, `it` etc from kocha, and write tests as in `mocha`:\n\n`test.js`:\n\n```js\nconst { describe, it } = require('kocha')\nconst assert = require('assert')\n\nconst add = (a, b) =\u003e a + b\n\ndescribe('add', () =\u003e {\n  it('adds the given numbers', () =\u003e {\n    const sum = add(12, 13)\n\n    assert(sum === 25)\n  })\n})\n```\n\nThen run it by `kocha` command.\n\n    ./node_modules/.bin/kocha test.js\n\nThis outputs the report like the below:\n\n```console\n$ ./node_modules/.bin/kocha test.js\n\nadd\n  ✓ adds the given numbers\n\n  1 passing (4ms)\n```\n\n# Use in [karma][karma]\n\n## :cd: Install\n\n    npm install kocha karma-kocha --save-dev\n\nInit karma.conf.js by invoking `karma init` command and following the instructions.\n\nThen add `kocha` configs to `karma.conf.js` like the below:\n\n```js\nmodule.exports = config =\u003e config.set({\n  frameworks: ['kocha', 'browserify'],\n  files: [\n    'test/**/*.js'\n  ],\n  preprocessors: {\n    'test/**/*.js': 'browserify'\n  }\n  browserify: {\n    debug: true,\n    ...\n  },\n  ...\n})\n```\n\nAnd write the tests like the below:\n\n`test/add.js`:\n\n```js\nconst { describe, it } = require('kocha')\nconst assert = require('assert')\n\nconst add = (a, b) =\u003e a + b\n\ndescribe('add', () =\u003e {\n  it('adds the given numbers', () =\u003e {\n    const sum = add(12, 13)\n\n    assert(sum === 25)\n  })\n})\n```\n\nThen hit the command `karma start`:\n\n    karma start\n\nIt outputs the test result like the below:\n\n```console\n$ karma start\n07 06 2017 13:41:07.792:INFO [framework.browserify]: bundle built\n07 06 2017 13:41:07.809:INFO [karma]: Karma v1.7.0 server started at http://0.0.0.0:9876/\n07 06 2017 13:41:07.809:INFO [launcher]: Launching browser Chrome with unlimited concurrency\n07 06 2017 13:41:07.819:INFO [launcher]: Starting browser Chrome\n07 06 2017 13:41:09.349:INFO [Chrome 58.0.3029 (Mac OS X 10.12.5)]: Connected on socket Qs7TxwAJjfsy7LElAAAA with id 79520559\nChrome 58.0.3029 (Mac OS X 10.12.5): Executed 1 of 1 SUCCESS (0.007 secs / 0.001 secs)\n```\n\nThat's it.\n\n**Note**: You need a CommonJS bundler (typically `browserify` or `webpack`) to use kocha in karma.\n\n**Note**: If you use [babel][babel] together with the bundler, then import `describe`, `it` etc like the below:\n\n```js\nimport { describe, it } from 'kocha'\n\ndescribe('foo', () =\u003e { ... })\n```\n\n# APIs\n\n```js\nconst {\n  describe,\n  it,\n  before,\n  beforeEach,\n  after,\n  afterEach,\n  timeout,\n  retries\n} = require('kocha')\n```\n\n## describe(title, callback)\n\nAdds the test suite by the `title` and `callback`. In `callback` function you can add child test suites and/or test cases.\n\n**Note**: The alias `context(title, callback)` is also available.\n\n## describe.skip(title, callback)\n\nAdds the skipped test suite by the `title` and `callback`. The test suites and cases under this suite are all skipped as well.\n\n**Note**: The alias `xdescribe(title, callback)` and `xcontext(title, callback)` are also available.\n\n## it(title, callback)\n\nAdds the skipped test case by the `title` and `callback`. `callback` implements your test case.\n\n**Note**: The alias `specify(title, callback)` is also available.\n\n## it.skip(title, callback)\n\nAdds the skipped test case by the `title` and `callback`.\n\n**Note**: The alias `xit(title, callback)` and `xspecify(title, callback)` is also available.\n\n## before(callback)\n\nAdds the before hook to the current suite.\n\n## beforeEach(callback)\n\nAdds the beforeEach hook to the current suite.\n\n## after(callback)\n\nAdds the after hook to the current suite.\n\n## afterEach(callback)\n\nAdds the afterEach hook to the current suite.\n\n## timeout(timeout)\n\nSets the timeout duration to the test cases or the test suites.\n\n## retries(n)\n\nSets the retry count of the test cases or the test suites.\n\n# Kocha CLI\n\n```\nUsage: kocha [options] \u003cfile[, ...files]\u003e\n\nOptions:\n  -h, --help                Shows the help message\n  -v, --version             Shows the version number\n  -r, --require \u003cname\u003e      Requires the given module e.g. --require @babel/register\n  -c, --config \u003cpath\u003e       Specify the config file path e.g. --config kocha.e2e.config.js\n  -t, --timeout \u003cms\u003e        Sets the test-case timeout in milliseconds. Default is 2000.\n\nExamples:\n  kocha test/               Runs all the tests under test/.\n\n  kocha \"src{/,**/}__tests__/**/*.js\"\n                            Runs tests under the directory pattern src/**/__tests__/.\n\n  kocha --require @babel/register --require @babel/polyfill test/\n                            Runs tests under test/ using @babel/register and @babel/polyfill.\n\n  kocha --require coffee-script/register \"test/**/*.coffee\"\n                            Runs coffeescript tests under test/.\n```\n\n## kocha.config.js\n\nkocha command automatically looks up `kocha.config.js` from the current directory and execute it. You can configure the test runner there.\n\nkocha.config.js:\n\n```js\nconst { timeout, retries } = require('kocha')\n\ntimeout(5000) // Sets the default timeout to 5000ms\nretries(2) // Sets the default retry count to 2\n\n// Other preparations\n\n// For example, babel settings\nrequire('@babel/register')\nrequire('@babel/polyfill')\n\n// For example, power-assert settings\nrequire('espower-loader')({\n  pattern: 'test/**/*.js'\n})\n\n// For example, coffee-script settings\nrequire('coffee-script/register')\n```\n\n# Goals\n\n- Support BDD mode, Spec reporter of [mocha][mocha] in CommonJS environment.\n  - This includes Karma environment with CommonJS bundler (browserify, webpack).\n- Keeping the basic usability of Mocha, modernize the rusty old aspects of Mocha.\n\n## Non-goals\n\n- Kocha isn't a drop-in replacement of [mocha][mocha].\n- Kocha doesn't support interfaces other than `BDD`, like `TDD`, `QUnit`, `Exports` etc\n- Kocha doesn't support standalone mode in browser. Use bundlers and [karma][karma] for browser unit testing.\n- Kocha's BDD interface is not identical to Mocha's BDD interface. See the below for details.\n\n# Differences from mocha\n\n## BDD interface\n\n- Kocha doesn't have `this.timeout(ms)` API. Use `kocha.timeout(ms)` API instead.\n- Kocha doesn't have `this.retries(n)` API. Use `kocha.retries(n)` API instead.\n\n## CLI\n\n- Kocha doesn't support `--opts` option and `mocha.opts` (or `kocha.opts`). Write options directly instead.\n- Kocha doesn't support `-w, --watch` option. Use `chokidar-cli` and run-scripts instead.\n- Kocha doesn't support `--compilers` option. Use `--require` instead.\n\n# Migration from mocha\n\n## For node.js\n\n1. Install `kocha`\n1. Use `kocha` command instead of `mocha` or `_mocha` command.\n1. Add `const { describe, it, ... } = require('kocha')` statement on the top of each mocha test script.\n1. Rewrite `this.timeout(N)` to `kocha.timeout(N)` if you have any.\n1. Rewrite `this.retries(N)` to `kocha.retries(N)` if you have any.\n1. Then your tests should work with kocha.\n\nIf the above doesn't work, please file an issue.\n\n## For [karma][karma]\n\n1. Install `karma-kocha` and `kocha`\n1. Set `framework: ['kocha', ...]` instead of `framework: ['mocha', ...]`.\n1. Introduce a bundler (`browserify` or `webpack`) if don't have any.\n1. Add `const { describe, it, ... } = require('kocha')` statement on the top of each mocha test script.\n1. Rewrite `this.timeout(N)` to `kocha.timeout(N)` if you have any.\n1. Rewrite `this.retries(N)` to `kocha.retries(N)` if you have any.\n1. Then your tests should work with kocha.\n\nIf the above doesn't work, please file an issue.\n\nExamples of migration: [1](https://github.com/kt3k/moneybit-app/pull/3/files)\n\n# Name\n\nKocha (紅茶, pronounced like ko-cha, not like ko-ka) means black tea in Japanese.\n\n# History\n\n- 2017-12-14   v1.9.0   Change handling of --require option.\n- 2017-06-20   v1.8.0   Add node v4 support.\n- 2017-06-18   v1.7.0   Add kocha.config.js feature. Add --config option.\n- 2017-06-17   v1.6.0   Add --timeout option. Input path handling is now similar to mocha.\n- 2017-06-12   v1.5.6   Fail when done is called multiple times.\n- 2017-06-12   v1.5.5   Add uncaught error handling.\n- 2017-06-11   v1.5.4   Improve hook error handling.\n- 2017-06-11   v1.5.3   Improve error formatting of karma-kocha.\n- 2017-06-10   v1.5.1   Support IE11.\n- 2017-06-09   v1.4.0   Support hook events.\n- 2017-06-07   v1.3.0   Add babel's import support.\n\n# License\n\nMIT\n\n[mocha]: https://github.com/mochajs/mocha\n[babel]: https://babeljs.com/\n[karma]: https://github.com/karma-runner/karma\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkt3k%2Fkocha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkt3k%2Fkocha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkt3k%2Fkocha/lists"}