rowno / grunt-mocha-cli Goto Github PK
View Code? Open in Web Editor NEWRun Mocha server-side tests in Grunt.
License: MIT License
Run Mocha server-side tests in Grunt.
License: MIT License
I am trying to run programmatically a test case scenario. I realized that each file is only running once. Here is my example
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
mochacli: {
options: {
bail: false,
colors: true,
// timeout: 900000
},
files: [
'test/adminLogin.spec.js',
'test/createUser.spec.js',
'test/deleteUser.spec.js',
'test/createUser.spec.js',
'test/updateUserUser.spec.js',
'test/deleteUser.spec.js',
'test/createUser.spec.js',
]
}
});
grunt.registerTask('default', ['mochacli']);
};
I have this scenario where I want to test different files and some of them multiple time. but when I run grunt, each file is only executed once.
Adding this will allow debugging using the V8 inspector, adding some much needed speed to debugging our tests.
Hey!
Is it possible that you update mocha from v3 to v4?
If your tests are running with mocha v4, then you can run into this issue.
Thank you!
Kate
Hey Kiwi
Using https://github.com/shootaroo/jit-grunt with your grunt task won't work because of that line in your code
grunt.registerMultiTask('mochacli', 'Run Mocha server-side tests.', function () {
If I change it to mochaCli
or mocha-cli
it works.
If mocha is a dependency in package.json, this errors out with:
execvp(): No such file or directory
Fatal error: spawn ENOENT
This has to do with mocha being installed in a different path than grunt-mocha-cli expects. The .bin is hardcoded to the node_modules of grunt-mocha-cli.
How can we output html report to a file for reference?
This is how my config looks, is there a way to output the result?
{
src: ['test/unit/**/*.js'],
options: {
timeout: 6000,
'check-leaks': true,
ui: 'bdd',
reporter: 'doc'
}
}
when I move from version 1.9.0 to 1.10.0
I am getting
Error: timeout of 2000ms exceeded
Currently if src
parameter will be something like ./test/**/*-spec.js
it will result in expanding of the parameter and Mocha will run concatenated list of files. Also mocha will ignore recursive
parameter, because the runner is executing files, but not a directory with wildcards.
If there will be thousands of test files, potentially some issues might occur while passing them as arguments. In grunt-mocha-istanbul, for example, it is solved by using parameter mask
, see https://github.com/pocesar/grunt-mocha-istanbul/blob/master/tasks/index.js line ~160. In this case Mocha will expand it internally.
If mask
parameter is set to **/*-spec.js
and src='./path/to/tests'
the following command will be executed:
mocha ./path/to/tests/**/*-spec.js
When running with the following configuration ..
options: {
reporter: 'nyan',
//ndebug: true,
harmony: true,
bail: true
}
.. things are pretty good. But when enabling ndebug
for some reason I get an Unexpected Token
error on arrow functions.
options: {
reporter: 'nyan',
ndebug: true,
harmony: true,
bail: true
}
I can see the args being passed look correct:
[ 'debug', '--bail', '--harmony', '--reporter', 'nyan', 'test/schema-test.js' ]
Is this a bug, or is there maybe something wrong with my configuration ?
Thanks!
Hey, I'll preface this by saying I'm not all that familiar with Grunt, so if there's something I need to do differently on my side just let me know.
I'm trying to pass through command line arguments to the mochacli task like so:
grunt mochacli:all --grep=seed
I've verified that this is accessible through grunt.option('seed')
both within my gruntfile and within a patched version of grunt-mocha-cli. I see though that we're not looking at grunt.option, and are instead are accepting an options object via the function that we're exporting.
I think it should be possible to loop through the existing option lists you have and check for CLI options and override the config. Does this sound like the right approach, or is there a more standard way to do this within grunt?
I'm happy to send a pull request your way if the approach sounds good.
In node v0.12, it has an option to enable harmony scoping (e.g. let and const). Command line can enable it like this: node --harmony_scoping
.
I'm getting the following error message:
CreateProcessW: %1 is not a valid Win32 application.
Windows 7
Hello,
Thanks for this module. I tried this morning and it worked well.
I also see there is a similar 'grunt-mocha-test' project, and I'm trying to evaluate which would be best to use. It would be helpful if there was a short "See Also" section in the documentation which mentioned this module and briefly summarized the differences.
I think by explaining the benefits of this a bit more, you may gain more users.
Hey @Rowno! ๐
Mocha v8 was just released, with parallel support - https://mochajs.org/#parallel-tests
Would you be able to add support for this? Thanks!
When I pass require: ['should']
as an option, it doesn't work:
TypeError: Cannot call method 'equal' of undefined
Test:
[1,2,3].indexOf(4).should.equal(-1);
Hi,
There is a way to specify: exclude_dir?
just because I have a features/ directory inside test/ directory
I have mock object or some another resources that is being used on tests,
I wan't a way to specify to mocha exclude that directory,because it is considering as test,.
and errors was thrown.
Best Regards.
Hey!
Would it be possible to get Mocha updated to v7?
Thanks!
In mocha.js
:
var spawnOptions = {
cmd: __dirname + '/../node_modules/.bin/mocha'
};
...should be...
var spawnOptions = {
cmd: __dirname + '/../../../node_modules/.bin/mocha'
};
In a previous issue you listed the fact that grunt-mocha-cli has mocha as a dependency instead of a devDependency means that you don't have to include it yourself. To the contrary this means that if mocha has released a new version and you haven't updated your dependencies, I can't update it independenty.
6 releases of mocha have been made since you last updated the package.json file.
Mocha already shipped a xunit reporter which can write a xml string into a output file.
In order to tell mocha which output file it is, we need to pass on the '--reporter-options' parameter which is missing in current grunt-mocha-cli.
The parameter is a string base on mocha command help:
option('-O, --reporter-options <k=v,k2=v2,...>', 'reporter-specific options')
Could you please add support for that string parameter?
Specified this:
module.exports = (grunt)->
grunt.initConfig
watch:
coffee:
files: ['test/**/*.coffee', 'common/**/*.coffee'] # TODO Other SubApps too...
tasks: ['mochacli'] #'clear',
mochacli:
options:
reporter: 'list'
compilers: ['coffee:coffee-script/register']
require: ['should']
ui: 'bdd'
env:
NODE_ENV: 'test'
all: ['test/**/*.coffee']
Here primary problem!
grunt.event.on 'watch', (action, filePath)->
if grunt.file.isMatch grunt.config('watch.coffee.files'), filePath
console.log 'Action: '+action
console.log 'FilePath: '+filePath
if grunt.file.isMatch grunt.config('mochacli.all'), filePath
console.log 'MochaCLI Config: '
console.log grunt.config 'mochacli'
grunt.config 'mochacli.all', [filePath]
console.log 'MochaCLI Config: '
console.log grunt.config 'mochacli'
else
console.log 'Wrong FilePath: ' + filePath
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-mocha-cli'
grunt.loadNpmTasks 'grunt-clear'
grunt.registerTask 'default'
grunt.registerTask 'test', ['mochacli']
grunt.registerTask 'test-watcher', ['watch:coffee']
= But i executes all tests...why? :(
if mochacli.all is empty - nothing will be executed
tried with files and filesraw - didnt work
globals
(array) - allow the given comma-delimited global names.
I searched in google for some time and looked at the documentation but I couldn't understand what exactly the about statement mean. Can you please update the documentation with an example?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.