{"id":13549317,"url":"https://github.com/kmiyashiro/grunt-mocha","last_synced_at":"2025-10-22T21:33:34.082Z","repository":{"id":3121152,"uuid":"4148423","full_name":"kmiyashiro/grunt-mocha","owner":"kmiyashiro","description":"[MOVED] Grunt task for running mocha specs in a headless browser (PhantomJS)","archived":true,"fork":false,"pushed_at":"2017-04-09T19:56:50.000Z","size":244,"stargazers_count":369,"open_issues_count":16,"forks_count":106,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-12-27T09:09:07.404Z","etag":null,"topics":["grunt-mocha","grunt-plugins","grunt-task","mocha","phantomjs","test-automation","test-runner","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/kmiyashiro.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-26T14:25:03.000Z","updated_at":"2024-09-21T17:57:42.000Z","dependencies_parsed_at":"2022-07-18T08:49:01.297Z","dependency_job_id":null,"html_url":"https://github.com/kmiyashiro/grunt-mocha","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmiyashiro%2Fgrunt-mocha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmiyashiro%2Fgrunt-mocha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmiyashiro%2Fgrunt-mocha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kmiyashiro%2Fgrunt-mocha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kmiyashiro","download_url":"https://codeload.github.com/kmiyashiro/grunt-mocha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234827057,"owners_count":18892884,"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":["grunt-mocha","grunt-plugins","grunt-task","mocha","phantomjs","test-automation","test-runner","testing"],"created_at":"2024-08-01T12:01:20.619Z","updated_at":"2025-10-01T05:30:41.915Z","avatar_url":"https://github.com/kmiyashiro.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Repo deprecated\n\nDisqus has adopted this project and npm module, visit https://github.com/disqus/grunt-mocha for further updates.\n\n---\n\n# grunt-mocha\n\n\u003e Automatically run *client-side* mocha specs via grunt/mocha/PhantomJS\n\nFor a grunt task for server-side mocha tests, see [grunt-mocha-test](https://github.com/pghalliday/grunt-mocha-test) or [grunt-simple-mocha](https://github.com/yaymukund/grunt-simple-mocha)\n\n## Getting Started\n\nThis plugin requires Grunt `~0.4.0`. Use a `0.1.x` tag of this plugin to use with Grunt `~0.3.0`.\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-mocha --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-mocha');\n```\n\n## Mocha task\n_Run this task with the `grunt mocha` command._\n\n### Settings\n\n#### files/src\n\nType: `String|Array`\n\nThis defines which HTML spec files to run using PhantomJS. These are the same files you would open to run tests in a browser.\n\nThere are a number of options available. Please review the [minimatch options here](https://github.com/isaacs/minimatch#options).\n\nExample:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n  },\n},\n```\n\n#### dest\nType: `String`\nDefault: `undefined`\n\nWrite reporter output to a file. Useful if you need a file to feed your CI bot.\n\nExample:\n```js\nmocha: {\n  test: {\n    options: {\n      reporter: 'XUnit'\n    },\n    src: ['tests/**/*.html'],\n    dest: './test/output/xunit.out',\n  },\n},\n```\n\n#### options.run\nType: `Boolean`\nDefault: `true`\n\ngrunt-mocha injects a script into the PhantomJS instance that loads your HTML spec files. The file sets up a reporter and listeners so the output can be output in the command line. This option will call `mocha.run()` after the script is injected, ensuring that the proper listeners are setup.\n\nYou may want to set this to false if your files are loaded asynchronously via AMD and call `mocha.run` in your own callback.\n\nIn HTML spec:\n```html\n\u003c!-- run mocha after all test are loaded --\u003e\n\u003cscript type=\"text/javascript\" charset=\"utf-8\"\u003e\n  // Only tests run in real browser, injected script run if options.run == true\n  if (navigator.userAgent.indexOf('PhantomJS') \u003c 0) {\n    mocha.run();\n  }\n\u003c/script\u003e\n```\n\nGruntfile:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n    options: {\n      run: true,\n    },\n  },\n},\n```\n\n#### options.urls\nType: `Array|String`\nDefault: `[]`\n\nInstead of files, hit these URLs. Usually used in conjunction with the connect task to spin up a server for testing.\n\n```js\nconnect: {\n  server: {\n    options: {\n      port: 8888,\n      base: '.',\n    },\n  },\n},\nmocha: {\n  test: {\n    options: {\n      urls: [ 'http://localhost:8888/example/test/test2.html' ],\n    },\n  },\n},\n```\n\nThen run:\n```\ngrunt connect mocha\n```\n\n#### options.timeout\nType: `Number`\nDefault: `5000`\n\nPhantomJS timeout in milliseconds. If nothing happens within 5 seconds, exit.\n\nExample:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n    options: {\n      timeout: 10000,\n    },\n  },\n},\n```\n\n#### options.bail\nType: `Boolean`\nDefault: `false`\n\nCall `grunt.warn` and exit the grunt task on the first failed test. This only calls `grunt.warn` after the entire spec file is finished.\n\nExample:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n    options: {\n      bail: true,\n    },\n  },\n},\n```\n\n#### options.growlOnSuccess\nType: `Boolean`\nDefault: `true`\n\nDisplay a Growl notification when all tests successfully pass.\n\nExample:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n    options: {\n      growlOnSuccess: false,\n    },\n  },\n},\n```\n\n#### options.log\nType: `Boolean`\nDefault: `false`\n\nPrint any `console.log` calls from PhantomJS to the command line. Only used for very quick and dirty debugging. It is highly recommended that you open the failing spec file in a browser so you can use much richer debugging tools.\n\nExample:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n    options: {\n      log: true,\n    },\n  },\n},\n```\n\n#### options.logErrors\nType: `Boolean`\nDefault: `false`\n\nFail and output script errors.\n\nExample:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n    options: {\n      logErrors: true,\n    },\n  },\n},\n```\n\n#### options.mocha\nType: `Object`\n\nA mocha options simple object. Very few options are currently supported. Actually, I think `grep` is the only one.\n\nExample:\n```js\nmocha: {\n  test: {\n    src: ['tests/**/*.html'],\n    options: {\n      mocha: {\n        grep: 'router*'\n      }\n    }\n  },\n},\n```\n\n#### options.reporter\nType: `String`\nDefault: `'Dot'`\n\nThe reporter to use. **Note:** XUnit and those types of reporters should probably use the `dest` option.\n\nExample:\n```js\nmocha: {\n  test: {\n    files: ['tests/**/*.html'],\n    options: {\n      reporter: 'Nyan',\n    }\n  },\n},\n```\n\nCustom reporter example:\nExample:\n```js\nmocha: {\n  test: {\n    files: ['tests/**/*.html'],\n    options {\n      reporter: './path/to/custom/reporter', // included via require\n    },\n  },\n},\n```\n\n### options.page\nType: `Object`\n\nSet properties in the PhantomJS webpage instance used for tests, see http://phantomjs.org/api/webpage/\n\nExample:\n```js\nmocha: {\n  test: {\n    options: {\n      page: {\n        settings: {\n          webSecurityEnabled: false,  // disable cors checks in phantomjs\n        },  \n      },\n    },\n  },\n},\n```\n\n## Hacks\n\nThe PhantomJS -\u003e Grunt superdimensional conduit uses `alert`. If you have disabled or aliased alert in your app, this won't work. I have conveniently set a global `PHANTOMJS` on `window` so you can conditionally override alert in your app.\n\n## Examples\n\n### Vanilla JS\n\n#### Option 1 (recommended)\n\n- Write mocha task description in grunt config using and specify `run: true` option (see [this task's Gruntfile.js](Gruntfile.js) for details);\n- Check for PhantomJS `userAgent` in a test html file and run tests only in a real browser (see [test2.html](example/test/test2.html) for details).\n\nIn this case you shouldn't include [bridge.js](phantomjs/bridge.js) (it will be included automatically) and tests will be run from [bridge.js](phantomjs/bridge.js).\n\n#### Option 2\n\nAlternatively, include `bridge.js` from `tasks/phantomjs` after you include `mocha.js` and run `mocha.setup` in your HTML file. The helper will override `mocha.setup` if it detects PhantomJS. See [test.html](example/test/test.html).\n\n### AMD\n\nMocha **must** be included via script tag in the header. There is no need to load Mocha via AMD. You may load other testing libs via AMD if that gives you a fuzzy feeling.\n\nExample setup with AMD (advanced): https://gist.github.com/2655876\n\n## License\nCopyright (c) 2013 Kelly Miyashiro\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmiyashiro%2Fgrunt-mocha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkmiyashiro%2Fgrunt-mocha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkmiyashiro%2Fgrunt-mocha/lists"}