admin管理员组文章数量:1394099
I've written a node module which can be used for both the backend and client
(exports || window).Bar= (function () {
return function () { .... }
})();
Now my karma tests use PhantomJs and plain about the not existing exports
variable
gulp.task('test', function () {
var karma = require('karma').server;
karma.start({
autoWatch: false,
browsers: [
'PhantomJS'
],
coverageReporter: {
type: 'lcovonly'
},
frameworks: [
'jasmine'
],
files: [
'bar.js',
'tests/bar.spec.js'
],
junitReporter: {
outputFile: 'target/junit.xml'
},
preprocessors: {
'app/js/!(lib)/**/*.js': 'coverage'
},
reporters: [
'progress',
'junit',
'coverage'
],
singleRun: true
});
});
The error I get is
PhantomJS 1.9.7 (Mac OS X) ERROR
ReferenceError: Can't find variable: exports
Is there a way to ignore the exports variable in karam/phantomsJs ?
I've written a node module which can be used for both the backend and client
(exports || window).Bar= (function () {
return function () { .... }
})();
Now my karma tests use PhantomJs and plain about the not existing exports
variable
gulp.task('test', function () {
var karma = require('karma').server;
karma.start({
autoWatch: false,
browsers: [
'PhantomJS'
],
coverageReporter: {
type: 'lcovonly'
},
frameworks: [
'jasmine'
],
files: [
'bar.js',
'tests/bar.spec.js'
],
junitReporter: {
outputFile: 'target/junit.xml'
},
preprocessors: {
'app/js/!(lib)/**/*.js': 'coverage'
},
reporters: [
'progress',
'junit',
'coverage'
],
singleRun: true
});
});
The error I get is
PhantomJS 1.9.7 (Mac OS X) ERROR
ReferenceError: Can't find variable: exports
Is there a way to ignore the exports variable in karam/phantomsJs ?
Share Improve this question asked Oct 4, 2014 at 11:01 Jeanluca ScaljeriJeanluca Scaljeri 29.2k66 gold badges235 silver badges382 bronze badges1 Answer
Reset to default 6A mon pattern is usually to check whether the exports
variable is defined:
(function(){
...
var Bar;
if (typeof exports !== 'undefined') {
Bar = exports;
} else {
Bar = window.Bar = {};
}
})();
This pattern is used in Backbone as example - well, it's technically bit more plicated in the source code because it does support also AMD, but the idea it's this.
You can also push down the check passing it as first argument of the wrapping function:
(function(exports){
// your code goes here
exports.Bar = function(){
...
};
})(typeof exports === 'undefined'? this['mymodule']={}: exports);
Have a look at this blog post for more info.
本文标签: javascriptKarma Can39t find variable exportsStack Overflow
版权声明:本文标题:javascript - Karma: Can't find variable: exports - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744718833a2621569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论