taras42 / karma-jasmine-html-reporter

A Karma plugin. Dynamically displays tests results at debug.html page
MIT License
44 stars 17 forks source link

Uncaught ReferenceError: jasmineRequire is not defined #4

Closed sarahquigley closed 8 years ago

sarahquigley commented 9 years ago

Hi,

Encountered the following error when trying to use karma-jasmine-html-reporter.

ERROR [karma]: Uncaught ReferenceError: jasmineRequire is not defined at http://localhost:9876/base/node_modules/karma-jasmine-html-reporter/src/lib/adapter.js?9d2c71b931979c6194d209809111ee3a72cf149b:6 

I found the issue was resolved when I downgraded my karma-jasmine plugin from v0.3.4 (the latest version) to v0.2.3. I am using karma-jasmine-html-reporter v0.1.5. Have you come across this incompatibility with the latest version of karma-jasmine? Do you have any plans to resolve this issue?

Thanks and all the best,

Sarah

taras42 commented 9 years ago

Hi, I haven't seen this one. Thanks. I will look into it.

taras42 commented 9 years ago

I've changed version of karma-jasmine plugin from v0.2.2 to v0.3.4 and it works correct. I'll probably dig into it a bit more than just changing the versions. Maybe you could provide me your karma configuration file, so I could compare it to mine. Or if your project is open source, I could fork it and check it out. (That's would be the best option)

Thanks.

sarahquigley commented 9 years ago

Hey, thanks for getting back to me. This is the project where I encountered this issue.

https://github.com/mstewart/angular-skeleton

I'll be interested to find out if you can replicate the issue when you fork the repo. Thanks for looking into this!

taras42 commented 9 years ago

Hi, I've forked the project and did setup. I can't replicate the issue. I tried with v0.3.4 and v0.3.5 just released, I can run tests.

Maybe you could provide additional info how did you setup the project or run tests (single run or continious) or any other info.

And one more thing. Is this issue persistent? Or sometimes it works? Just thinking if it may be some async stuff.

Thanks.

nil-ni-ck commented 9 years ago

same issue maybe I need to downgrade karma jasmine also?

sarahquigley commented 9 years ago

@taras42 I'll try to provide you with more info about this error soon. I hope to revisit the project where I'm encountering the error some time this week. I'll be in touch again once I have done so. Thanks for your help!

nil-ni-ck commented 9 years ago

Actually I removed the node_module dir and do a fresh npm i. everything back to work

budajeff commented 9 years ago

I get this error as well. To work around it I have to delete my project's node_module dir, delete my global npm-cache folder, and then do a npm install

warpdesign commented 9 years ago

I am having the same error. Deleting node_modules and cleaning npm cache didn't help.

I am using karma-jasmine v0.2.3

maxwellpeterson-wf commented 9 years ago

Also seeing this error today.

warpdesign commented 9 years ago

It seems html.jasmine.reporter.js is executed before jasmins is loaded. I added a simple console.log(jasmine); before the call to jasmineRequire that's failing, and it returns undefined.

maxwellpeterson-wf commented 9 years ago

It looks like I no longer have this issue when I downgrade from karma@0.12.32 to karma@0.12.31. Can anyone else confirm?

warpdesign commented 9 years ago

I can confirm that's the problem: I set LOG_LEVEL to debug, and the web server is serving html reporter files, and then only jasmine.core.js.

No wonder jasmine is undefined. Question is: why ?

juliogc commented 9 years ago

I'm getting the same errors in adpter.js and html.jasmine.reporter.js

INFO [karma]: Karma v0.12.32 server started at http://dev.local:8080/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 42.0.2311 (Mac OS X 10.10.3)]: Connected on socket MXiAWX-DJbw02UfCAAAA with id 10270798
ERROR [karma]: Uncaught ReferenceError: jasmineRequire is not defined
at http://dev.local:8080/base/node_modules/karma-jasmine-html-reporter/src/lib/html.jasmine.reporter.js?4af523ab7bfaa86c4966fa332c4dc2bd2278b4cc:24

ERROR [karma]: Uncaught ReferenceError: jasmineRequire is not defined
at http://dev.local:8080/base/node_modules/karma-jasmine-html-reporter/src/lib/adapter.js?9d2c71b931979c6194d209809111ee3a72cf149b:6
package.json
...
    "devDependencies": {
        ...
        "karma": "^0.12.31",
        "karma-jasmine": "^0.3.4",
        "karma-jasmine-html-reporter": "^0.1.6",
        ...
    }
...
gavriguy commented 9 years ago

I have the same problem. deleting my project's node_modules folder, clearing npm cache and reinstalling (npm install) didn't help

gavriguy commented 9 years ago

explicitly stating karma version 0.12.31 solves the issue for me. "karma": "0.12.31" instead of "karma": "^0.12.31" Currently Karma latest version is 0.12.32 and its seams to cause the problem

taras42 commented 9 years ago

As said @warpdesign jasmine is undefined, and for some reason plugin loads into env before jasmine. Maybe karma devs changed the way how it works and there needed some changes to be done from my side. Currently I can't see what have changed, because of this issue https://github.com/karma-runner/karma/issues/1415, 0.12.32 appears to be on npm but it's missing on git, so I can't see change log. If anyone have any guess (maybe someone here have more experience on karma plugins) please share. Basically this reporter is what you can see here http://jasmine.github.io/2.0/introduction.html at the very bottom, but wrapped as karma-plugin.

juliogc commented 9 years ago

@taras42 what about you make some interval/timeout for wait for jasmine be defined to fix this issue for while?

taras42 commented 9 years ago

For now you can remove html from reporters:[] option and do next in karma.conf.js file:

files: [
  .....
     {pattern: 'node_modules/karma-jasmine-html-reporter/src/css/jasmine.css'},
     {pattern: 'node_modules/karma-jasmine-html-reporter/src/lib/html.jasmine.reporter.js'},
     {pattern: 'node_modules/karma-jasmine-html-reporter/src/lib/adapter.js'},
  .....

So it will load all plugin resources after jasmine loaded.

I created post here https://groups.google.com/forum/#!topic/karma-users/T702DO3DuAY. Will notify if there will be any updates.

taras42 commented 9 years ago

After digging for a while in karma sources I found the changes which are the cause of such behaviour.

Changes located at karma/lib/server.js line 30 (three lines of code has been removed and moved to line 324) which changes the order of plugin injection to the page.

I'm going to open an issue, to find out if it's going to be changed back or not, to decide what to do next with a plugin.

warpdesign commented 9 years ago

Good. But other plugins should break as well, don't you think ?

taras42 commented 9 years ago

Definitely, if they have deps on frameworks, and they are being injected.

Paz23 commented 9 years ago

I came across this issue, but had one site working and another giving the error. To fix I updated package.json to:

"karma": "^0.12",
"karma-chrome-launcher": "^0.1",
"karma-firefox-launcher": "^0.1",
"karma-jasmine": "^0.3.0",
"karma-jasmine-html-reporter": "^0.1.8",
"karma-ng-html2js-preprocessor": "^0.1.2"

For mine, it was the karma-jasmine that was wrong. Actual versions:

_q master % npm ls | grep karma
├─┬ karma@0.12.36
├─┬ karma-chrome-launcher@0.1.12
├── karma-firefox-launcher@0.1.6
├── karma-jasmine@0.3.5
├─┬ karma-jasmine-html-reporter@0.1.8
│ └── karma-jasmine@0.2.3
├── karma-ng-html2js-preprocessor@0.1.2
taras42 commented 9 years ago

Hi,

I've tried to use karma 0.13.9 and karma-jasmine 0.3.5. Looks like they changed the order of injection like it was before. It works now as expected.

If anybody can confirm, that would be nice.

Thanks.

askucher commented 8 years ago

Got same issue

voltrevo commented 8 years ago

same issue here

krlm commented 8 years ago

Encountered same issue; my configuration:

    "jasmine": "^2.4.1",
    "karma": "^1.1.0",
    "karma-chrome-launcher": "^1.0.1",
    "karma-firefox-launcher": "^1.0.0",
    "karma-jasmine": "^1.0.2",
    "karma-jasmine-html-reporter": "^0.2.0",
    "karma-mocha-reporter": "^2.0.4",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^1.7.0",

but earlier mentioned workaround is still working:

files: [
  .....
     {pattern: 'node_modules/karma-jasmine-html-reporter/src/css/jasmine.css'},
     {pattern: 'node_modules/karma-jasmine-html-reporter/src/lib/html.jasmine.reporter.js'},
     {pattern: 'node_modules/karma-jasmine-html-reporter/src/lib/adapter.js'},
  .....
adbre commented 8 years ago

Proposing the README is updated with this as a known issue, along with the work-around until karma have a solution for the plugin loading order. A fix in karma does not seem to be merged very soon since it's been over a year the issue was reported.

yudhasetiawan commented 8 years ago

Hi,

I've the same issue here. For now to fix this issue I updated karma-jasmine-html-reporter/src/index.js#L9-L11 to:

var TEST_JASMINE_CORE = /(\/karma-jasmine\/)/i;
var jasmineIndex = 0;

files.forEach(function(file, index) {
  if (TEST_JASMINE_CORE.test(file.pattern)) {
    jasmineIndex = index;
  }
});

files.splice(++jasmineIndex, 0, createPattern(__dirname + '/css/jasmine.css'));
files.splice(++jasmineIndex, 0, createPattern(__dirname + '/lib/html.jasmine.reporter.js'));
files.splice(++jasmineIndex, 0, createPattern(__dirname + '/lib/adapter.js'));
darkmavis1980 commented 8 years ago

Same issue using karma 1.1.0, reverted back to 0.13.14 and then everything works fine

intentionally-left-nil commented 8 years ago

@taras42 both the fix proposed by @yudhasetiawan as well as bumping the karma-jasmine dependency to >= 1.0.2 are needed to get this codebase working with the latest versions of karma.

Please update this library accordingly.

In the meantime, anyone who hits this thread can feel free to npm install karma-jasmine-textio-html-reporter which has these fixes.

P.S. also I removed the extra CRLF characters in your .gitignore in my fork :-)

mchaulakana commented 8 years ago

Same issue using karma 1.1.1, even with karma-jasmine1.0.2

Glad to see that the fix proposed by @yudhasetiawan seems to work. Waiting patiently for @taras42 to implement

taras42 commented 8 years ago

Sorry for not responding that long. Just don't have time now. @yudhasetiawan you can make pull request.

Also, how do you think (all of the users), maybe it would be better to make this reporter a bower package rather then karma plugin, and load it via karma.config in files: [] configuration, till karma team didn't introduced some kind of dependency handling. That way we would be less dependent on loading order, unless files will be loaded before frameworks which I doubt will happen. Or we could have two versions: bower and currenly fixed.

intentionally-left-nil commented 8 years ago

From my understanding, @yudhasetiawan is working around this issue in a general sense? I generally would prefer to keep things as simple as possible from a devops perspective. Adding bower is another dependency (one which I currently don't have right now).

nolazybits commented 8 years ago

Hey @taras42 do you think you could merge the PR and bump the version please? Having exactly the same problem here :/

yudhasetiawan commented 8 years ago

@AnilRedshift yes you're right. In the meantime my PR is just temp solution rather than to downgrade a karma itself and I would prefer to use this package as a karma plugin.

protazy commented 8 years ago

Hi guys, I've experienced this issue today and couldn't figure out why it is not working even though I can see that this issue was already closed. Turns out there is one case where you will encounter "jasmineRequire is not defined" once more - when you are using Windows :)

Since the regex you use has forward slashes - it won't match paths on Windows environment and the dependencies will be loaded in wrong order.

The simplest solution would be to remove forward slashes from the regex and just leave: var JASMINE_CORE_PATTERN = /(karma-jasmine)/i;

Can I count on an update?

intentionally-left-nil commented 8 years ago

@protazy File a new issue 👍