I spent a lot of time trying to debug this, and decided that I would ask. I even created a GitHub repository , but I wonβt rely on it, so here it is. I am trying to use CommonJS syntax in a Karma tester using PhantomJS. For my module, I created the simplest thing that I could think of:
exports.returnYes = function() { return "Yes"; };
Jasmine test:
var returnYes = require("../js/returnYes").returnYes; describe("returnYes", function() { it("should return Yes", function() { expect(returnYes()).toBe("Yes"); }); });
And, if I do jasmine init , I can run it from the command line using jasmine-npm by simply typing jasmine with the output:
$ jasmine Started . 1 spec, 0 failures Finished in 0.003 seconds
Now, to try to get it to work inside karma: I create karma.conf.js with the frameworks: jasmine , commonjs . And, I add commonjs as a preprocessor.
I try to make karma run , and I found that it cannot find global , which is part of getJasmineRequireObj in jasmine.js , where it declares jasmineGlobal = global;
Command line output is a little hard to read, but here it is:
$ karma run [2015-06-27 17:41:35.266] [DEBUG] config - Loading config /Users/zen/Projects/karma-commonjs-test/karma.conf.js ##teamcity[enteredTheMatrix] ##teamcity[testSuiteStarted nodeId='1' parentNodeId='0' name='karma.conf.js' nodeType='config' locationHint='config:///Users/zen/Projects/karma-commonjs-test/karma.conf.js'] ##teamcity[testSuiteStarted nodeId='2' parentNodeId='1' name='PhantomJS 1.9.8 (Mac OS X 0.0.0)' nodeType='browser'] ##teamcity[testStarted nodeId='3' parentNodeId='2' name='Error' nodeType='browserError'] ##teamcity[testFailed nodeId='3' error='yes' message='ReferenceError: Can|'t find variable: global|nat http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?68f13ab3f93af5a219b9fe8409f8763b31998bba:27'] ##teamcity[testSuiteFinished nodeId='2'] ##teamcity[testSuiteFinished nodeId='1']
For good measure, here are the devDependencies in my packages. json:
"devDependencies": { "jasmine-core": "^2.3.4", "karma": "^0.12.37", "karma-commonjs": "0.0.13", "karma-jasmine": "^0.3.5", "karma-phantomjs-launcher": "^0.2.0", "phantomjs": "^1.9.17" }
I am not sure why I cannot find global . Any help would be greatly appreciated! :)