Skip to content
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

ReferenceError: Can't find variable: jasmine #28

Closed
Toralion opened this issue Apr 12, 2013 · 35 comments
Closed

ReferenceError: Can't find variable: jasmine #28

Toralion opened this issue Apr 12, 2013 · 35 comments

Comments

@Toralion
Copy link

While trying to setup a hudson project using jasmine, phantomjs and your junit_reporter, I permanently get an error when running your example:
"ReferenceError: Can't find variable: jasmine"

Here some info about my System:

  • Hudson 3.0.0
  • WIndows 7 64bit
  • cygwin
  • phantomjs 1.9 (also tried 1.6.1)

It seems that the included in junit_xml_reporter.html are not loaded (tried a console.log within the jasmine.js) but don't understand why.
I also made the relative paths (../ext) absolute. But that doesn't work either

I suppose that the bug could have to do s.t. with my environment by I don't have any clue.

Does any has an idea what could be the problem?

Here's the full stacktrace:

ReferenceError: Can't find variable: jasmine

phantomjs://webpage.evaluate():3
phantomjs://webpage.evaluate():9

phantomjs://webpage.evaluate():9

@rwstoneback
Copy link

I am having this same issue. When I run phantomjs with "--debug=yes", I get the following output:

......removed some output......
2013-05-22T14:20:43 [DEBUG] WebPage - updateLoadingProgress: 10
2013-05-22T14:20:43 [DEBUG] WebPage - updateLoadingProgress: 100
2013-05-22T14:20:43 [DEBUG] WebPage - setupFrame ""
2013-05-22T14:20:43 [DEBUG] WebPage - setupFrame ""
2013-05-22T14:20:43 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {
window["__jr965331"] = {};
window.fs_path_separator = "";
window.__phantom_writeFile = function(filename, text) {
window["__jr965331"][filename] = text;
};
})(); })()"
SyntaxError: Parse error

2013-05-22T14:20:43 [DEBUG] WebPage - evaluateJavaScript result QVariant(, )
2013-05-22T14:20:43 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {
// if there's a JUnitXmlReporter, return a boolean indicating if it is finished
if (jasmine.JUnitXmlReporter) {
return jasmine.JUnitXmlReporter.finished_at !== null;
}
// otherwise, see if there is anything in a "finished-at" element
return document.getElementsByClassName("finished-at").length &&
document.getElementsByClassName("finished-at")[0].innerHTML.length > 0;
})(); })()"
ReferenceError: Can't find variable: jasmine

So there are a couple issues.
First is the SyntaxError, which is found in phantomjs-testrunner.js at setupWriteFileFunction().
Second is the ReferenceError, where it doesn't know what "jasmine" is. This is in the processPage() function where it checks if the JUnitXmlReporter exists.

Am I doing something wrong, or is this a bug?

@scho
Copy link

scho commented Jun 5, 2013

The same thing happened to me as well.
In the end it was an authentication issue. Have you tried to use the file protocol (file://...) instead of http?

ynonp added a commit to ynonp/jasmine-reporters that referenced this issue Jul 24, 2013
The line:
window.fs_path_separator = "\%fs_path_separator%";

yields a syntax error on windows. %fs_path_separator% is \, and so the resulting line is:
window.fs_path_separator = "\";

But this is not valid JS (backslash escapes the closing quote).

This should solve issue larrymyers#28


Prefixing with a backslash solves the problem on Windows, and is ignored on Mac/Unix, so everything still works there.
@ynonp
Copy link

ynonp commented Jul 24, 2013

Hi,
I had the same problem. I think it's a bug in phantomjs-testrunner.js, and was able to fix by changing the line:
window.fs_path_separator = "%fs_path_separator%";
to
window.fs_path_separator = "%fs_path_separator%";

I also submitted a pull request with this change.

@kelseyh
Copy link

kelseyh commented Sep 2, 2013

Hi,
I had the same problem on Phantomjs 1.9.1 even after applying the window.fs_path_separator change which is required. What fixed for me was removing the addition of 'file://' to the address and using an absolute path. Basically page.open is returning success when file:// protocol is used even though the page cannot be found.

@putermancer
Copy link
Collaborator

It's been a while since this issue got any comments, are people still observing this problem with recent versions of PhantomJS (1.9.6+) and up-to-date jasmine-reporters? If not I would like to close the issue. If so, can someone still observing the issue provide an updated pull request?

@karlkras
Copy link

+1
Yes... as of yesterday, using the latest version of Phantom with my existing Jasmine 1.3.1 based project am having this same issue.

So it would appear that there's a game of finger pointing between PhantomJS the jasmine-reporters projects?

putermancer added a commit that referenced this issue Apr 22, 2014
…ke on it when stringified.

This should fix #28.
@putermancer
Copy link
Collaborator

I think this is fixed on the jasmine2 branch. I tested this on Windows 7 with PhantomJS 1.9.7, but the fix should be good for older versions as well.

I successfully generated JUnit xml files like so:

phantomjs bin\phantomjs-testrunner.js file:///Users/IEUser/Downloads/jasmine-reporters/test/junit_xml_reporter.html

Please try this branch / fix and let me know if it's working for others. If so, I'll merge this into master as well.

@karlkras
Copy link

Hey Ben, so were you ever able to reproduce this originally?
Would the fix be in phantomjs-testrunner.js ?

@putermancer
Copy link
Collaborator

Yes, I was able to reproduce the issue on Win 7, and the commit I pushed fixed it for me. Is it not working for you?—
Ben Loveridge (phone--sorry for typos)

On Tue, Apr 22, 2014 at 8:36 AM, karlkras [email protected]
wrote:

Hey Ben, so were you ever able to reproduce this originally?

Reply to this email directly or view it on GitHub:
#28 (comment)

@karlkras
Copy link

Oh, I'm just getting into the office now... so I'm going to give it a go now. Just curious to know if you actually saw the problem personally. I can see by the change that this would be the logical problem.
I'll let you know shortly.

@karlkras
Copy link

so with this change I need to use the new reporters too? It wouldn't do just to swap out the jasime2 phantomjs-testrunner.js ?

@putermancer
Copy link
Collaborator

This change has only been applied to the new reporters branch. The single line change could be copied over directly, but you couldn't just take phantomjs-testrunner.js wholesale -- the logic for determining that the test run has finished is only compatible with the jasmine2 branch.

@karlkras
Copy link

and just wanted to make sure... this example that I'm trying to run, if phantomjs is indicated as the target browser, these are the reporters being issued:
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('target/test-reports/'));
jasmine.getEnv().addReporter(new jasmine.ConsoleReporter());

does that look right?

@putermancer
Copy link
Collaborator

If you copy that line over, then what you have might work. It is quite possible you'll need to switch your savePath to use the appropriate separator for the OS you're running the tests on, ie it might need to be target\test-reports.

Alternately, you could just check out the jasmine2 branch and try out the included example runner, which just uses .. as the savePath, and see if that works. That should be enough to tell us if the "fix" is actually a fix :)

@karlkras
Copy link

I see that jasmine.console_reporter.js is no longer in the jasmine2 branch. should I be using jasmine.terminal_reporter.js ?

Okay, yeah, I'll try the test in the branch... but I am trying to avoid (for now) having to move to jasmine 2.0

@putermancer
Copy link
Collaborator

ConsoleReporter is no longer in the jasmine2 branch because Jasmine Core has a console reporter. TerminalReporter has very nice output when run from the command line.

TrivialReporter was also replaced with HtmlReporter in Jasmine 2.

Out of curiosity, what is your reason for avoiding Jasmine 2 right now? (I've got one project with a few thousand test cases that I have been avoiding, simply because of the size of the test suite, but I recently migrated a smaller project to Jasmine 2 with very little difficulty.)

@karlkras
Copy link

Fear of the unknown ;)

@putermancer
Copy link
Collaborator

Have you had a chance to give the PhantomJS fix a try? From your question to the jasmine-js group it sounds like either you are having fewer troubles or you think that the health is generally improving for unspecified reasons :)

If it's working for you, I'd like to port the change to the Jasmine 1 branch and close this issue.

@karlkras
Copy link

well, I'm working on porting my tests over to jasmine 2.0 which is having it's own set of challenges. At which point I'll confirm the fixes for the reporters. Let's just say this is pretty bad timing.

@putermancer
Copy link
Collaborator

Don't let that stop you. I can port the change to the jasmine 1 branch pretty quickly. I thought you could verify pretty quickly, I don't mean to be a road block. —
Ben Loveridge (phone--sorry for typos)

On Tue, Apr 22, 2014 at 9:30 PM, karlkras [email protected]
wrote:

well, I'm working on porting my tests over to jasmine 2.0 which is having it's own set of challenges. At which point I'll confirm the fixes for the reporters. Let's just say this is pretty bad timing.

Reply to this email directly or view it on GitHub:
#28 (comment)

@putermancer
Copy link
Collaborator

Committed to both master and jasmine2

@karlkras
Copy link

Okay... sorry for the false alarms... simple testing would show it working. Apparently I can't use the absolute file location (%CD%/test/testingfile.html) for the target, must be in the form file:///C:/Users/.../GitHub/vt-code-camp-2012/test/all-tests-spec.htm

@putermancer
Copy link
Collaborator

I'm glad it's working out for you. Yes, you do need to use either http or file protocol to locate your runner, as noted at the top of phantomjs-testrunner.js and printed to the console if no arguments are provided. A much earlier rendition tried to support local paths, but there were enough scenarios where things just didn't work right in PhantomJS that it was changed to only support actual protocols.

As you and I have both verified this now works, I'm going to close the issue.

@karlkras
Copy link

Okay... something completely different. I want to use require in the processing of my tests.
In the standard jasmine-html.js, reporter it provides the concept of "specFilter" ... is there something similar in these other reporters? How does one use require otherwise? I guess I should have considered this on my original eval, but just thought it would be covered? I'd like to use the teamcity reporter but not sure if I can without some added support that the html viewer supplies.

@putermancer
Copy link
Collaborator

In Jasmine 2, spec filter is something you set up in boot.js and should apply to all reporters.

In Jasmine 1, there is a similar feature.

jasmine.getEnv().specFilter = function(spec) {
    // determine if you want to run this spec
    return myDecision;
}

This is used like so:

jasmine.Spec.prototype.execute = function(onComplete) {
  var spec = this;
  if (!spec.env.specFilter(spec)) {
    spec.results_.skipped = true;
    spec.finish(onComplete);
    return;
  }
  this.env.reporter.reportSpecStarting(this);
  spec.env.currentSpec = spec;
  spec.addBeforesAndAftersToQueue();
  spec.queue.start(function () {
    spec.finish(onComplete);
  });
};

As you can see, it will mark specs that don't match the filter as skipped, which should work with all reporters.

I believe the specFilter support you are seeing in jasmine-html is simply the bit which allows you to click on a test and then it will only display results for that test. It still runs all the tests, it just doesn't show you the results in your browser (there have been several discussions about this on the jasmine-js mailing list in the by people wishing it would actually limit the test execution, not simply the results).

Give jasmine.getEnv().specFilter a try, I think you'll find it does what you need without changes to any reporters.

@karlkras
Copy link

Okay... a bit closer... but in my case my filter looks like:

    jasmineEnv.specFilter = function (spec) {
        return theReporter.specFilter(spec);
    };

and the "Decision" is being determined by the reporter. In this case (and only as far as I can tell) the html reporter.

@putermancer
Copy link
Collaborator

theReporter.specFilter(spec) just returns a boolean. You can swap this line out with whatever you want to make the decision.

@karlkras
Copy link

oh I see. Okay, if I simply return true out of this then it seems to work... any hints on conditions I'd consider returning false?

@putermancer
Copy link
Collaborator

I really don't understand what you're trying to do, a better place to ask would be the jasmine-js group and provide an example. —
Ben Loveridge (phone--sorry for typos)

On Fri, Apr 25, 2014 at 12:12 PM, karlkras [email protected]
wrote:

oh I see. Okay, if I simply return true out of this then it seems to work... any hints on conditions I'd consider returning false?

Reply to this email directly or view it on GitHub:
#28 (comment)

@karlkras
Copy link

Okay... I'll do that. One thing you might be able to address... when using the phantomjs-testrunner.js, shouldn't this kill the phantomjs process when the tests are considered complete?

@putermancer
Copy link
Collaborator

Yes it should, what is happening instead? Are you returned to your terminal session, or does the script just sit there occupying your session and you have to CTRL-C or similar to abort?

@karlkras
Copy link

yes... script just sit there occupying your session and you have to CTRL-C or similar to abort?

@karlkras
Copy link

Okay... it looks like I have to add the TrivialReporter to have this puppy work correctly.. fine now. Thanks for listening.

@putermancer
Copy link
Collaborator

Yeah, that's due to how phantomjs-testrunner checks for test completion. This is not necessary in the Jasmine2 branch, and should probably be refactored a little bit in the Jasmine1 branch too.

@karlkras
Copy link

Hey... once again, thanks for your support and have a great weekend. It's nice to end the week on a positive experience.

jawi pushed a commit to jawi/gulp-jasmine2-phantomjs that referenced this issue Jul 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants