yaymukund / grunt-simple-mocha Goto Github PK
View Code? Open in Web Editor NEWA simple wrapper for running mocha tests.
License: MIT License
A simple wrapper for running mocha tests.
License: MIT License
When using mocha via the command line you can specify files with -r
which will cause them to be required before your tests are. This is useful for doing setup, but it seems there is no way to do that with simplemocha.
How do you feel about a setup
option that receives the Mocha
instance and can execute arbitrary operations before mocha is actually run?
I'm attempting to add tests to my Grunt plugin. I want to use Mocha and Chai.
I've added simple mocha and installed chai from npm. initConfig is
simplemocha: {
options: {
globals: ['chai']
},
all: {
src: [
'node_modules/chai/lib/chai.js',
'test/**/*.js'
]
}
}
I have test.js with content as per
'use strict';
var assert = require("chai");
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
assert.equal(-1, [1,2,3].indexOf(5));
assert.equal(-1, [1,2,3].indexOf(0));
})
})
});
...which is an example provided on the Chai website. I get the error
TypeError: Object #<Object> has no method 'equal'
Am I configuring things incorrectly?
The usage description on npmjs.com for this package still uses the mocha name for the task (0.1.x version). Consider updating to the latest usage to avoid confusion with users finding the package on npm.
app/
├── tests/
│ ├── data
│ ├──── data.json
│ ├── sample-test.js
└── Gruntfile.js
└── package.json
Gruntfile:
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
...
simplemocha: {
all: { src: 'test/**/*-test.js' }
},
...
});
Issue:
Expected:
Grunt file that looks something like this:
regarde: {
all: {
files: '<%= jshint.all %>'
, tasks: ['simplemocha', 'mocha']
}
}
, simplemocha: {
options: {
globals: ['should']
, timeout: 1000
, ignoreLeaks: true
, ui: 'bdd'
}
, all: {
src: 'test/**/*.js'
}
}
run grunt regarde
Results look something like:
grunt regarde
Running "regarde" task
Watching Gruntfile.js,test/**/*.js
Running "simplemocha:all" (simplemocha) task
․․․․․․․
7 tests complete (7 ms)
Running "regarde" task
Running "simplemocha:all" (simplemocha) task
0 tests complete (0 ms)
Running "regarde" task
With nothing changing, the tests should run again.
My simplemocha run is failing with
Warning: undefined is not a function Use --force to continue.
How can I run in verbose mode, so to know at which line of which file this undefined
popped up?.
warning grunt-simple-mocha > mocha > glob > [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
warning grunt-simple-mocha > mocha > [email protected]: to-iso-string has been deprecated, use @segment/to-iso-string instead.
warning grunt-simple-mocha > mocha > [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
grunt-simple-mocha/package.json
Line 38 in 4001662
The latest mocha version is 4.0.1 now.
I have glued grunt-simple-mocha with mocha-as-promised
https://github.com/llamerr/grunt-simple-mocha/tree/grunt-simple-mocha-as-promised
I can make further improvements if this is interesting for someone
directly with mocha:
$ mocha --compilers coffee:coffee-script test/mocha-common.js test/unit/*
․․․․․․․․․․․․ ✖ 1 of 12 tests failed:
1) web-server testacular source handler should serve client.html:
TypeError: null is not a spy or a call to a spy!
at assertCanWorkWith (/Users/vojta/Code/testacular/node_modules/sinon-chai/lib/sinon-chai.js:35:19)
at Assertion.alwaysSinonMethod (/Users/vojta/Code/testacular/node_modules/sinon-chai/lib/sinon-chai.js:58:13)
at Assertion.Object.defineProperty.get (/Users/vojta/Code/testacular/node_modules/chai/lib/chai/utils/addProperty.js:35:29)
at MockHTTPResponse.includedFiles.path (/Users/vojta/Code/testacular/test/unit/web-server.spec.coffee:164:43)
at MockHTTPResponse.g (events.js:185:14)
at MockHTTPResponse.EventEmitter.emit (events.js:85:17)
at MockHTTPResponse.end (/Users/vojta/Code/testacular/node_modules/mock-http-response/src/index.coffee:80:19)
at /Users/vojta/Code/testacular/lib/web-server.js:40:21
at Array.Mock.readFile (/Users/vojta/Code/testacular/node_modules/mocks/lib/fs.js:195:7)
at nextTickHandler (/Users/vojta/Code/testacular/node_modules/mocks/lib/util.js:29:31)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
through simple-mocha:
grunt simplemocha:unit
Running "simplemocha:unit" (simplemocha) task
․․․․․․․․․․․Fatal error: null is not a spy or a call to a spy!
After I update Node to v0.10.x, simplemocha
task cannot be proceeded with this warning:
$ grunt simplemocha
Running "simplemocha:test" (simplemocha) task
Warning: Arguments to path.resolve must be strings Use --force to continue.
Aborted due to warnings.
My task definition is here:
path:
test: 'test'
simplemocha:
options:
compilers: 'coffee:coffee-script'
globals: []
ignoreLeaks: false
ui: 'bdd'
reporter: 'spec'
test:
src: '<%= path.test %>/**/*.coffee'
Any idea? Thanks in advance.
Mocha has a recursive option, if I add recursive:true to the config options there is a nother set of tests run as if i do mocha --recursive on the command line
I am using simplemocha with the spec reporter. My options are:
options: {
globals: ['expect'],
timeout: 1000,
ignoreLeaks: false,
ui: 'bdd',
reporter: 'spec' // was 'tap'
},
I'd like to see the whole stack trace in case of errors, as presented in https://mochajs.org/images/reporter-spec-fail.png, but I see on screen only the first line of the stack trace.
I want to see the whole stack trace.
I assume this is a simplemocha bug, but I may be wrong :-)
Thank you for your attention.
Hi, I can run my tests via the mocha
cmd, but when I run it through grunt-simply-mocha
, I always get this error: Warning: object is not a function Use --force to continue.
Any ideas?
// My configuration
simplemocha: {
options: {
ui: "bdd",
reporter: "spec"
},
all: "test/mocha/node.js"
}
Hello! I've opened a pull request into grunt-mocha plugin to merge the contents of this plugin there: kmiyashiro/grunt-mocha#17
There is some confusion and conflict between these two plugins, and I'd love to see these being resolved so that work can continue on a single, better plugin. Hopefully kmiyashiro will merge these changes in, and these plugins can be merged. I've tried to make the changes as non-invasive as possible, so that neither this or grunt-mocha -plugin users need to change their grunt configs.
For new users of mocha, they might not know what the grep
option is for. For people familiar with jasmine, they might think that the value *-test
pertains to the filename suffix, e.g. thing-test.js
, since Jasmine by default looks for files like thing.spec.js
. But that is not what grep
does.
The README should mention that the grep
option filters the tests and only runs those that match the pattern. It does not run those that don't.
Or else, the README needs to include a basic unit test that works with the configuration. Because most likely, the configuration (as is) won't run the tests that new users write.
Mocha allows you to pass a --require flag for things like should.js, and it will load it so you don't have to manually require('should')
in every single test. Setting this option doesn't do anything with grunt-simple-mocha.
Hi,
I'm trying to add a reporter for the test coverage and I was unable to set the attributes for the reporter.
Its not even throwing any error can suggest a solution for this?
Thanks and Regards
Lalith Narayan
It would be great if you could pass grep
from command line so that you wouldn't have to modify Gruntfile
when you need to focus on a specific test.
In the grep function, "*" is not able to act as a wildcard character. I suggest you amend it as "grep: /.-test/".
I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.
If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.
If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8"
as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0"
to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.
Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.
Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!
If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.
Thanks, we really appreciate your work!
Hello,
What is the full list of supported reporters?
I currently tried to use XUnit but I got the following: Warning: invalid reporter "XUnit"
Thank you in advance.
I'm trying to get my mocha tests integrated with Jenkins via the xUnit reporter in mocha. This works fine when using mocha without grunt as I can do this:
mocha -R xunit -r should $WORKSPACE/tests/mocha/*.js > $WORKSPACE/testresults.xml
With grunt, I'd like to do this:
grunt test
// runs simplemocha:production
simplemocha: {
options: {
globals: ['should'],
reporter: 'spec',
timeout: 5000
},
all: {
src: [
// require should...
'node_modules/should/lib/should.js',
// This test can use it!
'tests/mocha/*.js']
},
production: {
options: {
reporter: 'xunit'
},
src: [
// require should...
'node_modules/should/lib/should.js',
// This test can use it!
'tests/mocha/*.js'],
dest: 'tests/mocha.xml'
}
}
I'm after just the XML output, not the "Running "simplemocha:production" (simplemocha) task" console message before it, otherwise Jenkins won't accept the file as valid xUnit.
I quite like grunt-simple-mocha. Great work! However, I've been working on a migration over to Vows. I was a little disappointed with the test runners currently pairing Grunt and Vows. I couldn't find any which supported multitasks and the same form of pattern expansion. (i.e. test/**/*.js
)
I found copying the basic structure of grunt-simple-mocha to be quite useful in trying to do something similar for Vows. I considered just releasing grunt-simple-vows, but I was curious to hear your thoughts on whether these might better exist as a single project.
When adding grunt 0.4.x support, I didn't correctly update how grunt-simple-mocha does options. Working on a fix for 0.3.1.
in your readme, it have not comments for this filesSrc, it let user confuse. it should be fixed.
before
grunt.initConfig({
simplemocha: {
options: {
globals: ['should'],
timeout: 3000,
ignoreLeaks: false,
grep: '*-test',
ui: 'bdd',
reporter: 'tap'
},
all: { src: 'test/**/*.js' }
}
});
should be change to
grunt.initConfig({
simplemocha: {
options: {
globals: ['should'],
timeout: 3000,
ignoreLeaks: false,
grep: '*-test',
ui: 'bdd',
reporter: 'tap'
},
filesSrc: ['test/**/*.js' ]
}
});
Grunt 0.4 has some API changes that break this task.
https://github.com/gruntjs/grunt/wiki/Upgrading-from-0.3-to-0.4
My tests need to be run from a different working directory than the one where my Gruntfile resides. Is there a way to run mocha through this plugin with a different working directory?
FYI, it does look like selecting files with cwd works, but then when the plugin tries to run those test files, it does not use the cwd working directory.
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.