{"id":21076309,"url":"https://github.com/coderoad/mocha-coderoad-deprecated","last_synced_at":"2025-08-20T02:13:46.706Z","repository":{"id":57299770,"uuid":"51604897","full_name":"coderoad/mocha-coderoad-deprecated","owner":"coderoad","description":"Mocha test runner \u0026 reporter for CodeRoad","archived":false,"fork":false,"pushed_at":"2016-09-22T02:05:16.000Z","size":130,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-02T04:41:17.316Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://coderoad.github.io/docs#test-runners","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coderoad.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-12T17:36:36.000Z","updated_at":"2019-09-13T02:52:08.000Z","dependencies_parsed_at":"2022-08-26T21:51:44.528Z","dependency_job_id":null,"html_url":"https://github.com/coderoad/mocha-coderoad-deprecated","commit_stats":null,"previous_names":["coderoad/mocha-coderoad"],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/coderoad/mocha-coderoad-deprecated","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderoad%2Fmocha-coderoad-deprecated","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderoad%2Fmocha-coderoad-deprecated/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderoad%2Fmocha-coderoad-deprecated/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderoad%2Fmocha-coderoad-deprecated/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coderoad","download_url":"https://codeload.github.com/coderoad/mocha-coderoad-deprecated/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coderoad%2Fmocha-coderoad-deprecated/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271252993,"owners_count":24726918,"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","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-19T19:27:47.431Z","updated_at":"2025-08-20T02:13:46.684Z","avatar_url":"https://github.com/coderoad.png","language":"JavaScript","readme":"# Mocha CodeRoad\n\n[Atom-CodeRoad](https://github.com/coderoad/atom-coderoad) Javascript test runner \u0026 reporter.\n\n    npm install mocha-coderoad\n\n\n### Snippets\n\nUse [atom-snippets](https://atom.io/docs/latest/using-atom-snippets) to quickly generate test files.\n\nOpen up *Atom* -\u003e *Open Your Snippets*. Add the contents of *mocha-coderoad* `snippets.cson` to your global `snippets.cson` file.\n\nQuickly generate tests using the following snippet prefixes:\n\n* mochacr-f - test a function\n* mochacr-a - test an array\n* mochacr-o - test an object\n\n### Test Statements\n\nIt makes sense to write test statements using 'should', 'must' or negative statements. Remember, the failing test message will be delivered as feedback to the user.\n\n```js\nit('should be a function')\nit('must be a function')\nit('isn\\'t a function')\n```\n\n### Loaders\n\nUse a **loader** to run the user saved file in the context of your file. Think of a loader as a way to place the file your testing inside of your test file. Loaders are written inside of comments.\n\n```js\n// load('user-file.js');\n/* workspaceDirectory/user-file.js */\n```\n\nWhen loading files within your tutorial directory, add a second parameter of `true`. This can allow you to low additional data variables or functions, for example: `var data = {...}`.\n\n```js\n// load('data-file.js', true)\n/* workspaceDirectory/node_modules/tutorial-name/tutorial/data-file.js */\n```\n\n\n### Writing Tests\n\nHere are examples using *mocha* with *chai*'s *expect*. See the [docs](http://chaijs.com/api/bdd/).\n\n#### exists\n\n```js\nit('doesn\\'t exist', function() {\n    expect(target).to.not.be.undefined;\n});\n```\n\n#### type\n\n```js\nit('should be a function', function() {\n    expect(target).to.be.a('function');\n});\n```\n\n#### function params\n\n```js\nit('should have two parameters', function() {\n    expect(target).to.have.length(2);\n});\n```\n\n#### function returns\n\n```js\nit('should add one to the number', function () {\n    expect(addOne(1)).to.equal(2);\n});\n```\n\n#### equals\n\n```js\nit('should be 42', function () {\n    expect(target).to.equal(42);\n});\n```\n\n#### deep equals (with objects or arrays)\n\n```js\nit('should be {a: 42}', function () {\n    expect(target).to.deep.equal({a: 42});\n});\n```\n\n#### regex\n\n```js\nit('should include the variable \"count\"', function () {\n    var regex = new RegExp('count');\n    var string = target.toString();\n    expect(string.match(regex)).to.be.true;\n});\n```\n\n```js\nit('should access the property \"prop\"', function () {\n    var regex1 = /\\.prop/;            // dot notation\n    var regex2 = /\\[[\"']prop[\"']\\]/;  // bracket notation\n    var string = target.toString();\n    var result = !!string.match(regex1) || !!string.match(regex2);\n    expect(result).to.be.true;\n});\n```\n\n#### spies\n\nYou can use [*sinon*](http://sinonjs.org/docs/) or [*chai-spies*](https://github.com/chaijs/chai-spies) to create a spy. See an example below:\n\n`\u003e npm i -s chai-spies`\n\n```js\nvar chai = require('chai'),\n    spies = require('chai-spies');\nvar expect = chai.expect;\n    chai.use(spies);\n\nvar spy = chai.spy.on(console, 'log');\nloadJS('04-forEach.js');\n\nit('should write \"hello world\" to the console', function () {\n    expect(spy).to.have.been.called.with('hello world');\n});\n```\n\n### Dynamic Tests\n\nThere are situations where you might want to change data based on the current task. In this case, be careful, as all earlier tests must continue to pass.\n\nSome variables are passed into the test runner through the node environment *process.env*.\n\nSee an example of dynamic data based on the task position below:\n\n```js\nvar data = [1, 2, 3];\n\nif (process.env.TASK_POSITION === '4') {\n    data = [1, 2, 3, 4];\n}\n```\n\nTests can also change based on the task position.\n\n```js\nif (process.env.TASK_POSITION !== '4') {\n    it('should do this', function () { ... });\n} else {\n    it('should to that', function () { ... });\n}\n```\n\nSee a full [example](https://github.com/coderoad/coderoad-functional-school/blob/master/tutorial/1/04/01-forEach.spec.js).\n\n### Test Writing Tool\n\nIt's entirely possible to create a simplified testing tool that could make writing tests faster \u0026 easier.\n\nThe easiest solution would be to use editor snippets to generate a page of tests from a simple configuration object. This does not yet exist.\n\n## Config\n\nCodeRoad tutorial configurations can be set in the *package.json* config.\n\n```json\n{\n  \"config\": {\n      \"testDir\": \"tutorial\",\n      \"testSuffix\": \".spec.js\",\n      \"testRunner\": \"mocha-coderoad\",\n      \"edit\": true\n  }\n}\n```\n\nThis section will likely expand in the future. For now, let's go over some of the configurations.\n\n#### testDir\n\nThe relative path to the unit test directory. This makes writing unit tests paths easier.\n\n#### testSuffix\n\nThe common suffix for unit tests. Also making writing unit test paths shorter.\n\n#### testRunner\n\nSpecified test runner. Currently only \"mocha-coderoad\" is available.\n\n#### edit\n\nIf set to true, *Atom-CodeRoad* will allow users to submit issues or submit markdown pull requests. You will also need to specify \"repository\" \u0026 \"bugs\" in your *package.json* file. See an [example config file](https://github.com/coderoad/coderoad-functional-school/blob/master/package.json).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderoad%2Fmocha-coderoad-deprecated","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderoad%2Fmocha-coderoad-deprecated","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderoad%2Fmocha-coderoad-deprecated/lists"}