All Projects → kmiyashiro → Grunt Mocha

kmiyashiro / Grunt Mocha

Licence: mit
[MOVED] Grunt task for running mocha specs in a headless browser (PhantomJS)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Grunt Mocha

tropic
🍍 Test Runner Library
Stars: ✭ 29 (-92.18%)
Mutual labels:  mocha, test-runner, test-automation
appium-tests
Tool to run Titanium mobile tests in Appium
Stars: ✭ 15 (-95.96%)
Mutual labels:  mocha, test-automation
Wpt
Test suites for Web platform specs — including WHATWG, W3C, and others
Stars: ✭ 3,573 (+863.07%)
Mutual labels:  test-automation, test-runner
laravel-test-watcher
Laravel Test Watcher
Stars: ✭ 20 (-94.61%)
Mutual labels:  test-runner, test-automation
Argus Eyes
A lightweight commandline tool for visual regression testing of UI components.
Stars: ✭ 158 (-57.41%)
Mutual labels:  test-automation, phantomjs
node-mocha-extjs
Framework for testing ExtJs applications
Stars: ✭ 19 (-94.88%)
Mutual labels:  mocha, phantomjs
test junkie
Highly configurable testing framework for Python
Stars: ✭ 72 (-80.59%)
Mutual labels:  test-runner, test-automation
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+9373.05%)
Mutual labels:  test-automation, test-runner
IO-TESTER
A functional test framework
Stars: ✭ 32 (-91.37%)
Mutual labels:  test-runner, test-automation
atom-mocha
Mocha test runner in Atom
Stars: ✭ 13 (-96.5%)
Mutual labels:  mocha, test-runner
playwright-fluent
Fluent API around playwright
Stars: ✭ 71 (-80.86%)
Mutual labels:  test-runner, test-automation
Zunit
A powerful testing framework for ZSH projects
Stars: ✭ 140 (-62.26%)
Mutual labels:  test-automation, test-runner
Cucable Plugin
Maven plugin that simplifies running Cucumber Scenarios in parallel.
Stars: ✭ 110 (-70.35%)
Mutual labels:  test-automation, test-runner
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (-1.89%)
Mutual labels:  mocha, test-runner
Meissa
Cross-platform Distributed Test Runner. Executes tests in parallel, time balanced on multiple machines.
Stars: ✭ 66 (-82.21%)
Mutual labels:  test-automation, test-runner
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (-88.95%)
Mutual labels:  test-runner, test-automation
Awesome Test Automation
A curated list of awesome test automation frameworks, tools, libraries, and software for different programming languages. Sponsored by http://sdclabs.com
Stars: ✭ 4,712 (+1170.08%)
Mutual labels:  test-automation, test-runner
Green
Green is a clean, colorful, fast python test runner.
Stars: ✭ 691 (+86.25%)
Mutual labels:  test-automation, test-runner
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (-94.07%)
Mutual labels:  mocha, test-automation
Openrunner
Computest Openrunner: Benchmark and functional testing for frontend-heavy web applications
Stars: ✭ 16 (-95.69%)
Mutual labels:  test-runner, test-automation

Repo deprecated

Disqus has adopted this project and npm module, visit https://github.com/disqus/grunt-mocha for further updates.


grunt-mocha

Automatically run client-side mocha specs via grunt/mocha/PhantomJS

For a grunt task for server-side mocha tests, see grunt-mocha-test or grunt-simple-mocha

Getting Started

This plugin requires Grunt ~0.4.0. Use a 0.1.x tag of this plugin to use with Grunt ~0.3.0.

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-mocha --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-mocha');

Mocha task

Run this task with the grunt mocha command.

Settings

files/src

Type: String|Array

This defines which HTML spec files to run using PhantomJS. These are the same files you would open to run tests in a browser.

There are a number of options available. Please review the minimatch options here.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
  },
},

dest

Type: String Default: undefined

Write reporter output to a file. Useful if you need a file to feed your CI bot.

Example:

mocha: {
  test: {
    options: {
      reporter: 'XUnit'
    },
    src: ['tests/**/*.html'],
    dest: './test/output/xunit.out',
  },
},

options.run

Type: Boolean Default: true

grunt-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.

You may want to set this to false if your files are loaded asynchronously via AMD and call mocha.run in your own callback.

In HTML spec:

<!-- run mocha after all test are loaded -->
<script type="text/javascript" charset="utf-8">
  // Only tests run in real browser, injected script run if options.run == true
  if (navigator.userAgent.indexOf('PhantomJS') < 0) {
    mocha.run();
  }
</script>

Gruntfile:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      run: true,
    },
  },
},

options.urls

Type: Array|String Default: []

Instead of files, hit these URLs. Usually used in conjunction with the connect task to spin up a server for testing.

connect: {
  server: {
    options: {
      port: 8888,
      base: '.',
    },
  },
},
mocha: {
  test: {
    options: {
      urls: [ 'http://localhost:8888/example/test/test2.html' ],
    },
  },
},

Then run:

grunt connect mocha

options.timeout

Type: Number Default: 5000

PhantomJS timeout in milliseconds. If nothing happens within 5 seconds, exit.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      timeout: 10000,
    },
  },
},

options.bail

Type: Boolean Default: false

Call grunt.warn and exit the grunt task on the first failed test. This only calls grunt.warn after the entire spec file is finished.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      bail: true,
    },
  },
},

options.growlOnSuccess

Type: Boolean Default: true

Display a Growl notification when all tests successfully pass.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      growlOnSuccess: false,
    },
  },
},

options.log

Type: Boolean Default: false

Print 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.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      log: true,
    },
  },
},

options.logErrors

Type: Boolean Default: false

Fail and output script errors.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      logErrors: true,
    },
  },
},

options.mocha

Type: Object

A mocha options simple object. Very few options are currently supported. Actually, I think grep is the only one.

Example:

mocha: {
  test: {
    src: ['tests/**/*.html'],
    options: {
      mocha: {
        grep: 'router*'
      }
    }
  },
},

options.reporter

Type: String Default: 'Dot'

The reporter to use. Note: XUnit and those types of reporters should probably use the dest option.

Example:

mocha: {
  test: {
    files: ['tests/**/*.html'],
    options: {
      reporter: 'Nyan',
    }
  },
},

Custom reporter example: Example:

mocha: {
  test: {
    files: ['tests/**/*.html'],
    options {
      reporter: './path/to/custom/reporter', // included via require
    },
  },
},

options.page

Type: Object

Set properties in the PhantomJS webpage instance used for tests, see http://phantomjs.org/api/webpage/

Example:

mocha: {
  test: {
    options: {
      page: {
        settings: {
          webSecurityEnabled: false,  // disable cors checks in phantomjs
        },  
      },
    },
  },
},

Hacks

The PhantomJS -> 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.

Examples

Vanilla JS

Option 1 (recommended)

  • Write mocha task description in grunt config using and specify run: true option (see this task's Gruntfile.js for details);
  • Check for PhantomJS userAgent in a test html file and run tests only in a real browser (see test2.html for details).

In this case you shouldn't include bridge.js (it will be included automatically) and tests will be run from bridge.js.

Option 2

Alternatively, 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.

AMD

Mocha 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.

Example setup with AMD (advanced): https://gist.github.com/2655876

License

Copyright (c) 2013 Kelly Miyashiro Licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].