-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't work with RequireJS #5
Comments
I've found some article, where it was advised to include |
Oh! Thank you, you saved me, I spent more than 4 hours figuring out how this error can be solved, I never though that the order of the frameworks in Karma.conf.js is significant. |
I'm afraid, that it's not Karma fault, but fact, that if a library supports AMD (and Chai does), then it in no case should be include before RequireJS, because RequireJS will detect it and complain about incorrect module loading. Same happens on regular web page too. |
Any other solutions? My errors...
|
This tells, that
This tells, that you're trying to include |
Yes, but configured everything with official karma runner description... :/
|
Here is my configuration (not from Official docs, but works): // Karma configuration
// Generated on Sat Dec 28 2013 12:21:03 GMT+0200 (EET)
module.exports = function (config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '.',
// frameworks to use
frameworks: ['mocha', 'requirejs', 'chai'],
// list of files / patterns to load in the browser
files: [
'test/bootstrap.js',
'lib/jquery-1.9.1.js',
'script.js',
{pattern: 'lib/**/*.js', included: false, watched: false},
{pattern: 'modules/**/*.js', included: false},
{pattern: 'test/**/*Test.js', included: false}
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['dots', 'coverage'/*, 'osx'*/],
preprocessors: {
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'modules/**/*.js': ['coverage']
},
coverageReporter: {
reporters: [
// {type: 'html', dir: 'coverage/'},
{type: 'text', dir: 'coverage/', file : 'coverage.txt'},
{type: 'cobertura', dir: 'coverage/', file : 'cobertura.xml'}
]
},
// 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_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['Firefox'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
}; |
Notice, that |
I spent already couple of hours on this problem... And the DEBUG for my configuration:
|
So just changing Maybe you're missing |
When I change frameworks order, then karma freeze on the node_modules/karma-requirejs/lib/adapter.js... :/ |
This is my package.json: {
"name": "xxx",
"preferGlobal": false,
"version": "0.0.1",
"author": "Bartosz Bialas <bambosz@gmail.com>",
"description": "xxx",
"devDependencies": {
"karma-script-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.2",
"karma-firefox-launcher": "~0.1.3",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.5",
"requirejs": "~2.1.10",
"karma-requirejs": "~0.2.1",
"karma-coffee-preprocessor": "~0.1.2",
"karma-phantomjs-launcher": "~0.1.1",
"karma": "~0.10.9",
"mocha": "~1.17.1",
"karma-mocha": "~0.1.1",
"karma-chai": "0.0.2",
"chai": "~1.8.1"
},
"engines": {
"node": "~0.10"
}
} |
What is you Node.js version? And Karma, and others components? |
Ok, I found a solution... I don't know why, but it works when I put requirejs before chai and put test-main.js at the first line of files array... My current karma.conf.js: module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'requirejs', 'chai'],
files: [
'project/xxx/public/scripts/modules/test-main.js',
{pattern: 'project/xxx/public/scripts/libs/*.js', included: false},
{pattern: 'project/xxx/public/scripts/modules/**/*.js', included: false},
{pattern: 'project/xxx/public/scripts/modules/**/tests/*Spec.js', included: false},
],
exclude: [
'project/xxx/public/scripts/modules/script.js'
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: false,
browsers: ['PhantomJS'],
captureTimeout: 60000,
singleRun: true
});
}; Strange, but it work 👍 Thanks for help! :) |
It's not strange, since when you put |
It is strange, because official documentation tells us, to put test-main.js at the end... :) You are right, it is logical, why we should put it in the first line :) 👍 |
Indeed, having Thanks! |
I think this deserves a note in README. Would love to get a PR. |
What text exactly? We've talked about many things. While figuring out what text you can easily put it there with 1 click I guess. |
@aik099 - thanks for posting the solution, fixed it for me! |
TL;DR: I think part of the confusion from above is that the ordering of the |
worked for me. |
The ordering of frameworks didn't have any effect for me, but overriding requirejs's path to chai did the trick:
|
@jdhuntington - Thanks! the ordering didn't work for me either but your solution worked. |
Good day to all. When I use karma frameworks in order "frameworks: ['mocha', 'chai', 'requirejs']", in logs I see TypeError: 'undefined' is not an object (evaluating 'window.chai.should') But when i've changed "requirejs" with "chai", it make an error Error: Mismatched anonymous define() module: function () {} What have I do? Thanks! |
So |
Chai is working. But files with anonymous defines define([], function () {}) having error Error: Mismatched anonymous define() module: function () {} |
That's strange. Maybe there is a bug in last RequireJS package, that wraps browser version of requirejs. |
Requirejs version is 2.1.16. Maybe I forgot some module? My modules list looks like this
|
Can you try exactly my config from: #5 (comment) ? |
Not working ((((((((((((( Error: Mismatched anonymous define() module: function () {} Ok. Thanks! I will try some else versions of requirejs. |
Else versions didn't help. A feeling that requirejs clears "window.chai" or "window.chai" don't started without requirejs. |
I was having this problem, it was related to having karma installed both locally and globally. |
I don't use requirejs, but I get the same error. It probably comes from the fact that I preprocess my tests with webpack. |
Hi All, I am getting the below error when i try to include more libraries required for my test files. Here is my karma.conf.js
and test-main.js
Thanks in advance. Tagging @alexgorbatchev @oncletom @xdissent |
Because of
chai.js
detects RequireJS presense on a page (by checkingdefine & define.amd
) it doesn't createwindow.chai
variable used by this extension.As a result I'm getting following errors, when running karma:
This is part of
karma.conf.js
, that might be relevant:The text was updated successfully, but these errors were encountered: