Gathering detailed insights and metrics for grunt-mocha-concurrent
Gathering detailed insights and metrics for grunt-mocha-concurrent
Gathering detailed insights and metrics for grunt-mocha-concurrent
Gathering detailed insights and metrics for grunt-mocha-concurrent
Run mocha tests in parallel using concurrent grunt tasks
npm install grunt-mocha-concurrent
Typescript
Module System
Min. Node Version
Node Version
NPM Version
69.2
Supply Chain
98.7
Quality
75.1
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
14 Commits
2 Branches
1 Contributors
Updated on Nov 12, 2020
Latest Version
0.2.0
Package Id
grunt-mocha-concurrent@0.2.0
Unpacked Size
13.73 kB
Size
4.87 kB
File Count
13
NPM Version
6.13.4
Node Version
12.15.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
4
Run mocha tests via concurrent grunt tasks.
1npm install grunt-mocha-concurrent --save-dev
Even though there are lots of posts online that don't recommend running tests in parallel, I've almost halved the time it takes for my tests to run. Sure, it can be harder to debug issues, but since this uses grunt-concurrent
to spawn separate processes there won't be any "cross wire" bugs. Besides, if your test fails you can just revert to running your regular serial grunt test task along with a mocha .only
. But when things are green then why not go faster? :thumbsup:
This plugin requires grunt-mocha-test
and grunt-concurrent
. grunt-env
is optional.
Check that your Gruntfile.js
looks something similar to this. It's important that Concurrent.init(grunt);
appears after you call initConfig()
.
1const Concurrent = require("grunt-mocha-concurrent");
2...
3grunt.loadNpmTasks('grunt-mocha-test');
4grunt.loadNpmTasks('grunt-concurrent');
5grunt.loadNpmTasks('grunt-mocha-concurrent');
6...
7grunt.initConfig({
8 ...
9});
10Concurrent.init(grunt);
11
If your tests don't have any central external dependencies like a database, then this is the example for you.
1grunt.initConfig({ 2 ... 3 mocha_concurrent: { 4 your_target: { 5 specs: [ 6 { 7 mochaSpec: { 8 options: { 9 reporter: 'dot', 10 timeout: '2000' 11 }, 12 src: ['tests/unit/**/test*.js'] 13 } 14 }, 15 { 16 mochaSpec: { 17 options: { 18 reporter: 'dot', 19 timeout: '2000' 20 }, 21 src: ['tests/functional/**/test*.js'] 22 } 23 } 24 ] 25 }, 26 } 27 ... 28}); 29... 30grunt.registerTask('spec:concurrent', ['mocha_concurrent:your_target']);
When you run grunt spec:concurrent
it will run your unit tests and your functional tests in parallel.
mochaSpec
is just forwarded directly togrunt-mocha-test
so look up their documentation if you want to know more about the options.
Say your functional tests read and/or write to the database. You can't run parallel tests in the same process as your tests will step all over each other. You can't run parallel tests in different processes pointing to the same database either! So we get around this by using a different database instance in each task. :v:
If you use an environment variable to set which database to connect to, then you can use this example. This assumes that your test framework will dynamically create your database/schema for you. I'm using mongodb so this just happens automagically.
1grunt.initConfig({ 2 grunt.loadNpmTasks('grunt-env'); 3 ... 4 mocha_concurrent: { 5 your_target: { 6 specs: [ 7 { 8 mochaSpec: { 9 options: { 10 reporter: 'dot', 11 timeout: '2000' 12 }, 13 src: ['tests/unit/**/test*.js'] 14 } 15 }, 16 { 17 mochaSpec: { 18 options: { 19 reporter: 'dot', 20 timeout: '2000' 21 }, 22 src: ['tests/functional/controllers/**/test*.js'] 23 }, 24 envSpec: { 25 MONGODB_URI: 'mongodb://localhost:27017/my-test-db-1' 26 } 27 }, 28 { 29 mochaSpec: { 30 options: { 31 reporter: 'dot', 32 timeout: '2000' 33 }, 34 src: ['tests/functional/models/**/test*.js'] 35 }, 36 envSpec: { 37 MONGODB_URI: 'mongodb://localhost:27017/my-test-db-2' 38 } 39 } 40 ] 41 }, 42 } 43 ... 44}); 45... 46grunt.registerTask('spec:concurrent', ['mocha_concurrent:your_target']);
When you run grunt spec:concurrent
it will run your unit tests and two of your functional test flavours in parallel.
1grunt.initConfig({
2 mocha_concurrent: {
3 options: {
4 concurrentLimit: 1, // Number of concurrent tasks to run in parallel. Defaults to number of cpu cores.
5 envDefault: {}, // Environment variables to pass to all tasks. Defaults to null.
6 envTaskPrefix: "", // Prefix to use for grunt-env tasks. Defaults to mochaConcurrent-.
7 mochaTaskPrefix: "", // Prefix to use for grunt-env tasks. Defaults to mochaConcurrent-.
8 },
9 ...
10 },
11});
tests/functional/controllers
and created a separate spec for each, each with a unique database connection string..after()
and included it in the mochaSpec src for each spec. Mongoose gives you a way to delete the database.grunt-continue
.No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/13 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More