karma-runner / karma-mocha Goto Github PK
View Code? Open in Web Editor NEWA Karma plugin. Adapter for Mocha testing framework.
License: MIT License
A Karma plugin. Adapter for Mocha testing framework.
License: MIT License
Versions ^0.1.4
of this plug-in require a newer version of karma as shown by the npm install
error below:
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.12.8
When upgrading to this version of karma the symlink to the karma binary which used to get created at node_modules/.bin/karma
is no longer. As a result, to use the expected version of karma, users will also need to install karma-cli
as described in the preceding link. With karma-cli installed the karma symlink in the .bin
directory will be restored. Please update your documentation to reflect this.
Another way to address this issue (for end-users) is to lock down the version range used by this module in the calling application's package.json
file:
"karma-mocha": ">= 0.1 < 0.1.4"
Perhaps it's worth pointing out that, per SemVer, patch releases should not introduce breaking changes - which seems to be the overarching cause here.
Just a question.
Line 38 in 1080810
In debug mode, karma proposes a very-simple in-browser reporter that prints the result in browser console.
Would that be possible to plug the usual Mocha HTML reporter?
Notice that only karma-mocha requires greater than karma 0.10.
In my opinion, the upgrade to 0.12 necessitates karma-mocha to increment it's minor version (0.2.0), as it is a breaking change if karma 0.12 is necessary for future development.
npm ERR! peerinvalid The package karma does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9.3
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.12.8
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.10
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.10 <=0.13
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
I get something like this:
ERROR [karma]: [TypeError: Object ["login.js", "delete login"] has no method 'join']
TypeError: Object ["login.js", "delete login"] has no method 'join'
at [object Object].specFailure (/xxx/node_modules/karma/lib/reporters/Base.js:98:33)
at [object Object].onSpecComplete (/xxx/node_modules/karma/lib/reporters/Base.js:82:12)
at [object Object].EventEmitter.emit (events.js:98:17)
at [object Object].onResult (/xxx/node_modules/karma/lib/browser.js:177:13)
at Socket.EventEmitter.emit [as $emit] (events.js:117:20)
at SocketNamespace.handlePacket (/xxx/node_modules/karma/node_modules/socket.io/lib/namespace.js:335:22)
at Manager.onClientMessage (/xxx/node_modules/karma/node_modules/socket.io/lib/manager.js:488:38)
where at Base.js around line 98 is
this.specFailure = function(browser, result) {
var specName = result.suite.join(' ') + ' ' + result.description;
var msg = util.format(this.SPEC_FAILURE, browser, specName);
result.log.forEach(function(log) {
msg += formatError(log, '\t');
});
this.writeCommonMsg(msg);
};
for some reason the result.suite
is a string and not an array in order to have a join
function. In more details, what I get back as result
is the following:
{ id: '',
description: 'should delete a login when the #loginList .dellogin is clicked',
suite: '["login.js", "delete login"]',
success: false,
skipped: false,
log: '["TypeError: Object #<Assertion> has no method \'Equal\'\\n at Context.<anonymous> (http://localhost:9876/base/src/login.spec.js?1393363453000:56:43)\\n at Test.Runnable.run (http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:4336:32)\\n at Runner.runTest (http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:4724:10)\\n at http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:4802:12\\n at next (http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:4649:14)\\n at http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:4659:7\\n at next (http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:4597:23)\\n at http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:4626:5\\n at timeslice (http://localhost:9876/base/node_modules/mocha/mocha.js?1390426114000:5733:27)"]' }
I was wondering which assertion lib is provided with the Mocha adapter. I can see that expect() works when using Jasmine adapter.
But I can't use expect(), assert(), or should when I set Karma to use Mocha.
Thank you
I can't figure out the syntax of how to pass the compilers
option to mocha from the karma configuration. What I'm trying to do is have the equivalent of this:
mocha --compilers js:mocha-traceur my_test_dir/*.js
in my karma config.
I tried
client: {
mocha: {
compilers: 'js:mocha-traceur my_test_dir/*.js'
}
}
but that didn't work.
As of today, getting the following error:
Firefox 34.0.0 (Mac OS X 10.10) ERROR
You need to include some adapter that implements __karma__.start method!
We are running karma 0.12.19, karma-mocha 0.1.6, and mocha 1.21.3. Tried updating everything to the latest versions with the same result.
I was wondering how to set mocha options, like the timeout. Thanks
Rather than having a copy of it ;-)
If I set:
client: {
mocha: {
ui: 'tdd'
}
},
to use TDD interface for mocha, it works great. But when I hit "DEBUG", it does not respect this option, causing a "Uncaught ReferenceError: suite is not defined" and making the debug unusable.
Client options should be passed in debug mode as well as regular mode.
// karma.conf.js
module.exports = function(config) {
config.set({
client: {
mocha: {
ui: 'tdd'
}
}
});
};
Should do:
window.mocha.setup({ui: 'tdd'});
Once you have a ton of Mocha tests it becomes pretty important to be able to run certain ones using Mocha's grep pattern filter. Other mocha grunt plugins like grunt-mocha-test support this and it's great. It would need to be available both as an option in the gruntfile and as a cli arg.
grunt test --grep myfilter
I initially opened an issue on karma (karma-runner/karma#1553), but after doing a bit more research think it's more appropriate here. I want to expose Mocha's test properties inside of Karma's test results. From my understanding of Karma, the adapter seems to be the place to do such a thing.
I've noticed that the test
object in the runner.on
callback is the Mocha test object. I can edit the adapter to add other properties such as Mocha's fn
property (demonstrated in the snippet below)
runner.on('test end', function (test) {
var skipped = test.pending === true
var result = {
id: '',
description: test.title,
suite: [],
success: test.state === 'passed',
skipped: skipped,
time: skipped ? 0 : test.duration,
log: test.$errors || [],
code: test.fn.toString() // If I add this line here, `code` will be available to a reporter
}
var pointer = test.parent
while (!pointer.root) {
result.suite.unshift(pointer.title)
pointer = pointer.parent
}
tc.result(result)
})
However, if I try to pass along the test object to Karma (demonstrated below), Karma just hangs.
runner.on('test end', function (test) {
tc.result(test)
})
Does karma expect a specific format for it's result
object (my intuition says that is the exact reason for such an adapter)? If so, what properties does it look for? Is there any way to just forward on the entire Mocha test to a Karma reporter?
Any advice would be greatly appreciated
Discussion moved from #40:
Also I noticet that mocha entries are not removed from the stacktrace.
return stack.replace(/\n.+\/mocha\/mocha.js\?\d*\:.+(?=(\n|$))/g, '');
does not work for the following stacktrace:
Error: Expected PUT /api/lists/123 with different data
EXPECTED: {"foo":"bar"}
GOT: {"_id":123,"name":"New List Name"}
at $httpBackend (http://localhost:8080/base/app/bower_components/angular-mocks/angular-mocks.js?506e0a37bcd764ec63da3fd7005bf56592b3df32:1149)
at sendReq (http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:8408)
at http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:8125
at http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:11574
at http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:11574
at http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:11660
at http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:12751
at http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:12555
at http://localhost:8080/base/app/bower_components/angular-mocks/angular-mocks.js?506e0a37bcd764ec63da3fd7005bf56592b3df32:1454
at http://localhost:8080/base/test/client/spec/controllers/list/formCtrlSpec.js?67eaca0f801cf45a86802a262618a6cfdc6a47be:110
at invoke (http://localhost:8080/base/app/bower_components/angular/angular.js?7deca05396a4331b08f812e4962ef9df1d9de0b5:4068)
at workFn (http://localhost:8080/base/app/bower_components/angular-mocks/angular-mocks.js?506e0a37bcd764ec63da3fd7005bf56592b3df32:2194)
at callFn (http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4338)
at http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4331
at http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4728
at http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4819
at next (http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4653)
at http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4663
at next (http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4601)
at http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:4630
at timeslice (http://localhost:8080/base/node_modules/mocha/mocha.js?529c1ea3966a13c21efca5afe9a2317dafcd8abc:5763)
I'm pretty sure I am missing something obvious... Anything I need in karma.conf.js
in addition to this?:
'frameworks' : [ 'mocha' ],
'client' : {
'mocha' : {
'ui' : 'tdd'
}
}
$ ./node_modules/karma/bin/karma start
/Users/folder/node_modules/karma/node_modules/di/lib/injector.js:9
throw error('No provider for "' + name + '"!');
^
Error: No provider for "framework:mocha"! (Resolving: framework:mocha)
at error (/Users/folder/node_modules/karma/node_modules/di/lib/injector.js:22:68)
at Object.parent.get (/Users/folder/node_modules/karma/node_modules/di/lib/injector.js:9:13)
at get (/Users/folder/node_modules/karma/node_modules/di/lib/injector.js:54:19)
at /Users/folder/node_modules/karma/lib/server.js:31:14
at Array.forEach (native)
at start (/Users/folder/node_modules/karma/lib/server.js:30:21)
at invoke (/Users/folder/node_modules/karma/node_modules/di/lib/injector.js:75:15)
at Object.exports.start (/Users/folder/node_modules/karma/lib/server.js:310:12)
at Object.exports.run (/Users/folder/node_modules/karma/lib/cli.js:224:25)
at Object.<anonymous> (/Users/folder/node_modules/karma/bin/karma:3:23)
I have the requirement, where I need to pass the reporter option to the mocha. Something like this:
mocha -u tdd -R mocha-better-spec-reporter
I tried with this:
client: {
mocha: {
reporter: 'mocha-better-spec-reporter', // change Karma's debug.html to the mocha web reporter
ui: 'tdd'
}
}
and run as:
karma start
But that doesn't work. Anything I'm making mistake?
Note that I have already installed this package.
Here is the full karma.config
// Karma configuration
// Generated on Tue Sep 02 2014 23:03:20 GMT+0200 (CEST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha','chai'],
// list of files / patterns to load in the browser
files: [
'lib/*.js',
//'test-lib/mocha.js',
'utils.js',
'tests.js'
],
client: {
mocha: {
reporter: 'mocha-better-spec-reporter', // change Karma's debug.html to the mocha web reporter
ui: 'tdd'
}
},
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: [],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Safari'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};
I've specified in my karma.conf.js file that I'm using mocha... but how do I pass in arguments for mocha? For example:
frameworks: ['mocha', 'should'],
//doesn't work^
plugins: ['karma-*', 'should'],
//also doesn't work^
//...how could I make karma recognize that I'm passing arguments into mocha:
//something like this:
reporter: 'nyan',
growl : true
Is there a hook anywhere?
Needs correcting, I guess.
When using mocha and chai in a Node.js environment, when an assertion using deepEquals fails, you get a detailed output showing piece by piece what is different between the expected and actual values.
Take for example, these tests, located in a file, tests/objects_are_equal.js
:
if(!expect)
var expect = require('chai').expect;
describe('nice output', function(){
it('should fail this test with a nice output when objects are not equal', function(){
var objectA = {
a: 'some string',
b: 9,
c: 20,
d: 100,
},
objectB = {
a: 'some other string',
b: 10,
g: '100',
};
expect(objectA).to.eql(objectB);
});
it('should fail this test with a nice output when arrays are not equal', function(){
var arrayA = ['a', 6, 10, 9, 20, '15', 20, 30, 45, 60],
arrayB = ['c', 2, '8', '15', 8, 30, '8', 5, 10, 'a', 8, '60'];
expect(arrayA).to.eql(arrayB);
});
});
If you run the above tests with mocha in a node.js environment, with the command mocha
, you get the following output:
But if you run them using karma-mocha, you get the following output:
This makes it really challenging to debug why object comparisons didn't work, and I find myself having to do console.log on the objects in the test to see what is different between objects, which is not ideal.
According to an issue in chai:
...with diffing...it is in the test harness domain, so if you are not seeing useful diffs, I'd kindly ask you raise the issue with your test harness, for example Mocha.
I'm not sure if this bug belongs in karma-mocha or karma.
The bug still happens if the tests run in Chrome or Phantomjs, and if I load chai.js directly onto the page instead of via a karma-chai.
For the reference, here is my karma.conf file:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
files: [
'test/*.js'
],
reporters: ['progress'],
colors: true,
logLevel: config.LOG_INFO,
browsers: ['Chrome'],
})
}
When the assertion raises message with multiline strings in the stacktrace this message is duplicated.
For instance consider the following code snippet:
describe('an exmaple', function() {
it('throws', function() {
// works fine
throw new Error('foo');
});
it('throws', function() {
// message will be duplicated
throw new Error('foo\nbar');
});
});
for the first example I have nice error message:
PhantomJS 1.9.7 (Linux) Module chaiMatchers karma-mocha blows FAILED
Error: foo
at /home/lucassus/Projects/OpenSource/glossary/test/client/spec/chaiMatchersSpec.js:73
at callFn (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4338)
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4331
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4728
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4819
at next (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4653)
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4663
at next (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4601)
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4630
at timeslice (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:5763)
but when I'm trying to ouptup multiline message I get:
PhantomJS 1.9.7 (Linux) Module chaiMatchers karma-mocha blows FAILED
foo
bar
Error: foo
bar
at /home/lucassus/Projects/OpenSource/glossary/test/client/spec/chaiMatchersSpec.js:77
at callFn (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4338)
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4331
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4728
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4819
at next (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4653)
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4663
at next (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4601)
at /home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:4630
at timeslice (/home/lucassus/Projects/OpenSource/glossary/node_modules/mocha/mocha.js:5763)
I have simillar results google-chrome, on firefox I don't see duplicated messagtes.
This problem affects also tests with $httpBackend
, for example:
PhantomJS 1.9.7 (Linux) Controller: list.FormCtrl #submit() when the list is persisted does the magic FAILED
Expected PUT /api/lists/123 with different data
EXPECTED: {"foo":"bar"}
GOT: {"_id":123,"name":"New List Name"}
Error: Expected PUT /api/lists/123 with different data
EXPECTED: {"foo":"bar"}
GOT: {"_id":123,"name":"New List Name"}
On bare mocha everything works fine. I guess it could be related with #16
Hi,
I'm exploring using karma-mocha
for testing Mocha itself. I'm concerned about peerDependencies
. With npm v3, an unmet peer dep will result in a warning only. This is fine, but until npm v3 becomes more commonly used, if karma-mocha
becomes a dev dep of mocha
, it's pointless for Mocha to npm install
itself.
(This will also potentially cause problems with forks of Mocha that do various weird things, but I don't know if anyone's complained about that.)
How does the karma-runner org plan on handling the peerDependencies
issue? Perhaps it's prudent to remove peerDependencies
altogether and note that mocha
should be installed within README.md
?
As discussed in js-reporters/js-reporters#1, the event names which Mocha emits will eventually change. Requiring version *
of Mocha may be dangerous.
If this test is executed in karma-mocha:
it('This test should be skipped!', function() {
this.skip();
});
It will be marked as failed (FAILED This test should be skipped!
, Skipped 0 tests
). If the test is run using mocha from the command line, the test is marked as pending.
However the followings works as expected in karma-mocha (Skipped 1 tests
):
xit('This test should be skipped!', function() {
...
});
I stepped through it in the debugger and it seems that mocha tries to emit a "pending"
event, however there are no listeners attached to this event.
This package is generating some dependency conflicts, since it has a ~ instead of a >= like all the others:
npm ERR! peerinvalid The package karma does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9.3
npm ERR! peerinvalid Peer [email protected] wants karma@~0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.11.14
npm ERR! peerinvalid Peer [email protected] wants karma@>=0.9
Is there any strong reason for limiting the dependence to the 0.9.X version of Karma in this module?
Wrong repository
Actual: "Karma's docs http://karma-runner.github.io/0.8/plus/RequireJS.html"
Expected: "Karma's docs http://karma-runner.github.io/0.12/plus/requirejs.html" OR "Karma's docs http://karma-runner.github.io/0.12/plus/RequireJS.html"
Also links from the 0.8/plus/RequireJS.html to the 0.12 version are broken due to differences in letter captitalization.
Hi,
I am using Gulp to run karma with mocha/sinon/chai and jquery
My karma.conf.js has:
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jquery-2.1.0', 'mocha'],
// Plugin specific config
client: {
mocha: {
reporter: 'spec',
ui: 'tdd'
}
}
And the node-modules installed are
"devDependencies": {
"chai": "*",
"gulp": "*",
"gulp-jslint": "*",
"gulp-notify": "*",
"gulp-phpunit": "*",
"gulp-util": "*",
"karma": "*",
"karma-chai": "*",
"karma-chrome-launcher": "*",
"karma-cli": "*",
"karma-firefox-launcher": "*",
"karma-ie-launcher": "*",
"karma-jquery": "*",
"karma-mocha": "*",
"karma-opera-launcher": "*",
"karma-safari-launcher": "*",
"karma-sinon": "*",
"mocha": "*",
"sinon": "*"
}
But when I run karma I get this error
"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1.5\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" C:\Projects\INRXInsights\Code\Analytics-UI-Insights\httpdocs\node_modules\gulp\bin\gulp.js --color --gulpfile c:\Projects\INRXInsights\Code\Analytics-UI-Insights\httpdocs\Gulpfile.js karma:unit
[10:58:05] Using gulpfile c:\Projects\INRXInsights\Code\Analytics-UI-Insights\httpdocs\Gulpfile.js
[10:58:05] Starting 'karma:unit'...
[2015-10-07 10:58:05.142] [DEBUG] config - Loading config c:\Projects\INRXInsights\Code\Analytics-UI-Insights\httpdocs\karma.conf.js
07 10 2015 10:58:05.236:WARN [karma]: No captured browser, open http://localhost:9876/
07 10 2015 10:58:05.245:INFO [karma]: Karma v0.13.10 server started at http://localhost:9876/
07 10 2015 10:58:05.249:INFO [launcher]: Starting browser Chrome
07 10 2015 10:58:06.262:INFO [Chrome 45.0.2454 (Windows 7 0.0.0)]: Connected on socket 3C6LlqYiiMMpHEnaAAAA with id 29319610
Chrome 45.0.2454 (Windows 7 0.0.0) ERROR
Uncaught ReferenceError: describe is not defined
at c:/Projects/INRXInsights/Code/Analytics-UI-Insights/httpdocs/test/test.class.view.js:7
Please help!
Thanks
Yogesh
Hi I am just trying to get started with karma and have a very simple test file
var assertEqual = function(a, b) { console.assert(a === b, a + " should equal " + b) }
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
assertEqual(-1, [1,2,3].indexOf(5));
})
it('should fail', function(){
assertEqual(2, [1,2,3].indexOf(2));
})
})
})
with the following karma config
module.exports = function(config) {
config.set({
frameworks: ['mocha'],
basePath: 'Scripts/tests',
browsers: ['Chrome'],
autoWatch: true,
files: [
'*.js'
],
client: {
mocha: {
reporter: 'html', // change Karma's debug.html to the mocha web reporter
ui: 'tdd'
}
}
});
};
It seems like everything is getting loaded properly
but I get the describe is not defined
error as if mocha is not loaded. In fact, I can open up the dev console and I don't see describe
in any frame's global js scope so its not a matter of timing.
npm WARN package.json [email protected] No README data
How do you configure karma to use the mocha tdd interface instead of the bdd interface?
I've had karma / mocha / chai all working in the past but after upgrading to 0.12.19 today I realized I'm getting an error like this when I run a simple test
Uncaught TypeError: undefined is not a function
references the /node_modules/mocha/mocha.js:1401
also, below this I see about the same thing for setup/describe "is not a function"
here is a my simple test (the only spec file in the project right now)
describe('integration like tests', function() {
it('should render a link for each session at boot', function (done) {
throw new Error("ouch");
});
});
here is my karma config file
```js
module.exports = function(karma) {
karma.set({
frameworks: ['mocha', 'chai'],
files: [
"dist/karma.min.js"
],
reporters: ['progress'],
browsers: ['Chrome'],
singleRun: false,
autoWatch: true
});
};
Using the latest karma-mocha and karma-chai (tried w/ both karma 0.12.10 and 0.12.19)
I'm getting an error that window.mocha is not defined:
karma.js:229 Console was cleared
adapter.js:177 Uncaught TypeError: Cannot read property 'setup' of undefined(anonymous function) @ adapter.js:177(anonymous function) @ adapter.js:178__exec @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:1374entry.execute @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:3310linkDynamicModule @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:2933link @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:2776execute @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:3108doDynamicExecute @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:715link @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:908doLink @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:569updateLinkSetOnLoad @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:617(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:430M @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4H @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4R.when @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4b.run @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4t._drain @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4drain @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4e @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4
chai-adapter.js:4 Uncaught TypeError: Cannot read property 'should' of undefined(anonymous function) @ chai-adapter.js:4(anonymous function) @ chai-adapter.js:7__exec @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:1374entry.execute @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:3310linkDynamicModule @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:2933link @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:2776execute @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:3108doDynamicExecute @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:715link @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:908doLink @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:569updateLinkSetOnLoad @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:617(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:430M @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4H @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4R.when @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4b.run @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4t._drain @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4drain @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4e @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4
system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:1049 GET http://localhost:9876/base/node_modules/karma-sinon-chai/node_modules/sinon/pkg/core 404 (Not Found)fetchTextFromURL @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:1049(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:1567n @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4e @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:1566(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:2458(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:3023(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:3254(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:3816(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:4007(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:4253(anonymous function) @ system.src.js?8a7dc2b121cf30cbcb09362dbeab69432cb0db29:326M @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4H @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4R.when @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4b.run @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4t._drain @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4drain @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4e @ system-polyfills.js?d0b1078944376f51a16bffe23ac5488965b69b33:4
Any ideas?
Not this repos issue.
When I npm install this package I get the error:
npm WARN package.json [email protected] No README data
Normally I only see that when a package doesn't have a README.md file, but this one has one, so I'm not sure what the problem is. You'll notice that it doesn't have any README.md data on the package listing on npmjs.org. But I'd really like to get rid of this warning as it clutters up my warnings and makes it difficult for me to find real issues.
The module
Angular functions are not available within tests, switch framework to jasmine works fine.
Uncaught ReferenceError: module is not defined
Hi. I am using karma server to run my mocha unit tests for an angular app. The problem I am having is that messages that I write inside each it
to console.log
don't show up in the terminal. They do show up, however, if I simply run mocha [unit_test_file_name].js
at command line. Am I missing something in the configuration? Here are my files:
// gulfile.js
karma = require('karma').server,
gulp.task('unit', function (done) {
karma.start({
configFile: __dirname + '/config/unit/karma-unit.conf.js',
singleRun: true
}, done);
});
// karma-unit-conf
module.exports = function(config) {
config.set({
basePath: '../../',
autoWatch: false,
frameworks: ['mocha', 'chai', 'sinon-chai', 'chai-as-promised'],
// frameworks: ['mocha'],
browsers: ['PhantomJS'],
files: [
'bower_components/angular/angular.js',
'bower_components/lodash/dist/lodash.js',
'app/**/*.coffee'
],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-phantomjs-launcher',
'karma-script-launcher',
'karma-mocha',
'karma-chai-plugins',
'karma-coffee-preprocessor'
],
preprocessors: {
'**/*.coffee': ['coffee']
},
coffeePreprocessor: {
options: {
bare: true,
sourceMap: false
},
transformPath: function(path) {
return path.replace(/\.coffee$/, '.js');
}
},
logLevel: config.LOG_DEBUG,
client: {
mocha: {
bail: true
}
}
});
};
Thank you!
From the top project dir (same place karma.conf lives)
npm list --depth=0 |grep karma
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
relevant sections cut from karma.conf
'plugins': [
'karma-mocha'
],
frameworks: ['mocha'],
getting:
Error: No provider for "framework:mocha"! (Resolving: framework:mocha)
and
WARN [plugin]: Cannot find plugin "karma-mocha".
Try this:
expect('Hello\nWorld').toBe(0);
The displayed error message is:
PhantomJS 1.9.8 (Mac OS X) schemaUtils checkResourceResult should work for collection item endpoints FAILED
World' to be 0.
Error: Expected 'Hello
at src/__tests__/schemaUtils-test.js:126:0
Possibly related issues: #40, jasmine/jasmine#742, jasmine/jasmine#796, litixsoft/karma-mocha-reporter#23
Hi,
We are trying to using karma-mocha in our application. While running karma start we are getting "require is not defined error". So we have included "node_modules/requirejs/require.js" now we are getting module is not defined error.
Below are the karma.config.js and our test files.
Could you please check that file and let me know if you find any solution for that.
Thanks,
It is tagged on github, just not released to the public.
Thanks :)
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'mocha-chai']
});
};
Should include chai library.
Could you please confirm and fix this little issue. Rather annoying for us :) Tnx!
When I use "setTimeout" function inside test function and when test fails duplicate fail messages are printed on the console screen.
The code is similar to this one:
suite("Some module tests", function() {
suiteSetup(function() {
$("body").append("some_html_code");
});
teardown(function () {
$("#container").empty();
});
suiteTeardown(function() {
$("#container").remove();
});
var getPrototypeFunction = function(functionName) {
return SomeProject().SomeObject.prototype[functionName];
};
suite("some function suite", function(done) {
test("some test", function(done) {
var isButtonClicked = false;
var clickCallback = function () {
isButtonClicked = true;
};
var createSomeButton = getPrototypeFunction("createSomeButton");
var $someButton = createSomeButton(clickCallback);
$someButton.trigger("click");
setTimeout(function() {
expect(isButtonClicked).to.not.be.ok();
done();
}, 0);
});
});
});
Btw I am using karma v0.10.2, karma-mocha v0.1.0, phantomjs v1.9.2, jQuery v1.8.3.
When I run karma command I receive two the same error messages stating that "isButtonClicked" variable is false instead of true.
At the bottom of the console window, following message is printed:
"... Executed (2 of 1) (2 FAILED) (some_number secs / NaN secs)".
How can two tests be executed when there is only one in the test suite?
I have this issue only when "setTimeout" function is used, when I remove it the code
works as expected (only one error message is printed).
Why is this happening and is this issues related to my code?
Thanks.
As discussed in karma-runner/karma#133 there are some issues with the mocha adapter.
netTime
not always availableHi - I can't use before()
with karma-mocha
, only beforeEach()
. I get TypeError: Cannot read property '$injector' of null
TypeError: Cannot read property '$injector' of null
at Context.workFn (/Users/timruffles/dev/capco/analytics/public/lib/angular-mocks/angular-mocks.js:2215:22)
When trying to use the require interface of mocha in the karma runner, I get an error:
Uncaught ReferenceError: require is not defined
My code looks like:
var api = require('./api');
describe('api', function(){
});
module.exports = function (config) {
config.set({
port: 9001,
browsers : ['PhantomJS'],
frameworks: [/*'mocha-debug', */'mocha', 'chai', 'chai-as-promised'],
reporters : ['mocha', 'progress', 'coverage'],
client: {
mocha: {
reporter: 'html',
ui: 'bdd'
}
},
preprocessors: {
'tests/**/*.js': [ 'babel' ],
'{trunk,utils}/**/*.js': [ 'coverage' ]
},
// https://github.com/karma-runner/karma-coverage
coverageReporter: {
type: 'html',
dir : 'cache/coverage/'
},
files: [
'tests/**/*.js'
],
colors: true,
autoWatch: false,
});
};
I see a blank page
But with mocha-debug
framework all normal
At adapter.js:132
, it would be very helpful for some use cases to expose the runner with e.g.
window.__mochaRunner__ = mocha.run();
This gives users the option to hook for any of the mocha events. For example, I like to use speech synthesis to tell me when a test fails, with something like (pardon the CoffeeScript):
window.__mochaRunner__.on 'fail', ->
msg = new SpeechSynthesisUtterance("Bad karma. " + @currentTest.fullTitle())
speechSynthesis.cancel()
speechSynthesis.speak(msg)
$(window).unload(-> speechSynthesis.cancel())
Please correct me if I am wrong (I am fairly new to Karma), but the alternatives to achieve this simple hook seem to be rather daunting. They seem to be:
mocha.run
), orWhich all seem to be overkill for such a simple hook that is available via the runner. But then, I could very well be missing a rather obvious option here, but having spent a couple hours rooting through karma's source I did not see anything sticking out, and mocha is designed to make this possible by exposing the runner - so that would seem to be the easiest option.
Thanks & cheers. 🍻
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.