Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
1999 committed May 20, 2018
1 parent fc8a5e0 commit cf78aca
Show file tree
Hide file tree
Showing 122 changed files with 5,157 additions and 1,463 deletions.
11 changes: 0 additions & 11 deletions .babelrc

This file was deleted.

7 changes: 3 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4

[{package.json,.travis.yml,.babelrc}]
indent_style = space
indent_size = 2

[*.js]
indent_size = 4
28 changes: 0 additions & 28 deletions .eslintrc.js

This file was deleted.

8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ pids
logs
results

dist/
npm-debug.log
node_modules
.idea

# app specific
test/node-addon
test/reporter-custom-mochawesome/mochawesome-report/
mochawesome-report/

.idea
test/reporter-custom-jenkins/result.xml
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: node_js
node_js:
- "stable"
- "6"
- "5"
- "4"
- "8"
- "9"
env:
- CXX=g++-4.8
addons:
Expand All @@ -13,3 +12,4 @@ addons:
packages:
- gcc-4.8
- g++-4.8
script: npm run test:ci
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## (upcoming release)
## 2.0.0

* ...
More: https://github.com/yandex/mocha-parallel-tests/wiki/v2-release-notes

## 1.2.10

Expand Down
69 changes: 43 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,61 @@
# Mocha parallel tests runner

[![Greenkeeper badge](https://badges.greenkeeper.io/yandex/mocha-parallel-tests.svg)](https://greenkeeper.io/)
# mocha-parallel-tests

[![Build Status](https://img.shields.io/travis/yandex/mocha-parallel-tests/master.svg?style=flat)](https://travis-ci.org/yandex/mocha-parallel-tests)
[![DevDependency Status](http://img.shields.io/david/dev/yandex/mocha-parallel-tests.svg?style=flat)](https://david-dm.org/yandex/mocha-parallel-tests#info=devDependencies)
[![npm version](https://img.shields.io/npm/v/mocha-parallel-tests.svg?style=flat)](https://www.npmjs.com/package/mocha-parallel-tests)

`mocha-parallel-tests` is a test runner for tests written with `mocha` testing framework which allows you to run them in parallel. `mocha-parallel-tests` executes **each of your test files in a separate process** while maintaining the output structure of `mocha`. Compared to the other tools which try to parallelize `mocha` tests execution, `mocha-parallel-tests` doesn't require you to write the code in a different way or use some specific APIs - just run your tests with `mocha-parallel-tests` instead of `mocha` and you will see the difference. Or if you prefer to use `mocha` programmatic API replace it with `mocha-parallel-tests` default export and you're done!

Normally tests written with mocha run sequentially. This happens so because each test suite should not depend on another. But if you are running tests which take a lot of time (for example tests with Selenium Webdriver) waiting for so much time is impossible.
## Installation

If you're sure that running any of your test suites doesn't affect others, you should try to parallel them with `mocha-parallel-tests`. The only thing that changes for you is that you use not `mocha` but `mocha-parallel-tests` executable because it supports all of mocha options.
`npm install --save-dev mocha mocha-parallel-tests`

Also `mocha-parallel-tests` supports its own `--max-parallel` (max parallel running tests) and `--retry` (number of retries) options.
**ATTENTION**: `mocha` is a peer dependency of `mocha-parallel-tests` so you also need to install `mocha`. Currently `mocha` versions 3, 4 and 5 are supported.

## Installation
## Usage

`npm install --save-dev mocha-parallel-tests mocha`
### CLI

**ATTENTION**: Starting from 1.0.0 `mocha-parallel-tests` adds mocha as a [peerDependency](https://nodejs.org/en/blog/npm/peer-dependencies/) so you should specify what `mocha` version you want to run tests with. Only latest (3.x) mocha versions are supported.
```bash
# mocha example
$ mocha -R xunit --timeout 10000 --slow 1000 test/*.spec.js

## Usage
# mocha-parallel-tests example
$ mocha-parallel-tests -R xunit --timeout 10000 --slow 1000 test/*.spec.js
```

Most of `mocha` CLI options are supported. If you're missing some of the options support you're welcome to submit a PR: all options are applied in a same simple way.

### Programmatic API

```javascript
// mocha example
import * as Mocha from 'mocha';
const mocha = new Mocha();
mocha.addFile(`${__dirname}/index.spec.js`);
mocha.run();

// mocha-parallel-tests example
// if you're using TypeScript you don't need to install @types/mocha-parallel-tests
// because package comes with typings in it
import Mocha from 'mocha-parallel-tests'; // or `const Mocha = require('mocha-parallel-tests').default` if you're using CommonJS
const mocha = new Mocha();
mocha.addFile(`${__dirname}/index.spec.js`);
mocha.run();
```

## Parallel limit

* `./node_modules/.bin/mocha-parallel-tests your_test_directory/`
* `./node_modules/.bin/mocha-parallel-tests **/*.js`
`mocha-parallel-tests` CLI executable has its own `--max-parallel` option which is the amount of tests executed at the same time. By default it's equal to the number of logical CPI cores (`os.cpus().length`) on your computer but you can also specify your own number or set it to 0, which means that all test files will be started executing at the same time. However this is not recommended especially on machines with low number of CPUs and big number of tests executed.

## Options
Own options:
## Differences with mocha

* `--max-parallel <num>` - max number of running parallel tests
* `--retry <num>` - number of retries (0 by default)
Main difference with `mocha` comes from the fact that all files are executed in separate processes and don't share the scope. This means that even global variables values that you could've used to share the data between test suites will not be reliable. There's also some specific behaviour for some of the `mocha` CLI options like `--bail`: it's just applied to each test in its process. You can see the full list of differences [here](https://github.com/yandex/mocha-parallel-tests/wiki/Differences-with-mocha).

And all options supported by mocha:
From the reporter perspective the main difference between tests executed with `mocha` and `mocha-parallel-tests` is another level of nesting which again comes from the fact that main process adds one more "suite" level and all tests results are merged into that:

* `--reporter <name>` - specify the reporter to use
* `--timeout <n>` - set test-case timeout in milliseconds
* `--slow <n>` - "slow" test threshold in milliseconds
**mocha**

## Differences with `mocha`
![mocha reporter output](https://user-images.githubusercontent.com/73191/40283858-ac9611ce-5cc8-11e8-83a7-dc7be36817ff.png)

* `--bail` behaviour can differ due to parallel running of tests. See [this issue](https://github.com/yandex/mocha-parallel-tests/issues/88) for more info.
**mocha-parallel-tests**

## Tests
`mocha-parallel-tests` is highly covered with tests itself. If you find something bad, feel free to [post an issue](https://github.com/yandex/mocha-parallel-tests/issues/new).
![mocha-parallel-tests reporter output](https://user-images.githubusercontent.com/73191/40283870-cf470624-5cc8-11e8-8849-67718cfc3a05.png)
98 changes: 0 additions & 98 deletions api.js

This file was deleted.

22 changes: 22 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Test against the latest version of this Node.js version
environment:
matrix:
- nodejs_version: "8"
- nodejs_version: "9"
- nodejs_version: "10"

# Install scripts. (runs after repo cloning)
install:
- ps: Install-Product node $env:nodejs_version
- npm install

# Post-install test scripts.
test_script:
# Output useful info for debugging.
- node --version
- npm --version
# run tests
- npm run test:ci

# Don't actually build.
build: off
Loading

0 comments on commit cf78aca

Please sign in to comment.