Every repository with this icon (
Every repository with this icon (
| Fork of jgehtland/javascript_testing | |
| Description: | Framework for JavaScript Testing (currently a Rails Plugin) edit |
-
6 comments Created 5 months ago by mudphonefixxStubbing global method (setTimeout) seems to stop test execution.screw.unitxIf I place the following override in a before call:
before(function(){ setTimeout = function () {print('setTimeout stub');}; });Then, the following tests do not execute as I would expect. The first following test runs, but then all the rest of the tests do not run.
it("should...", function(){ print('start test1'); }); it("should...", function(){ print('start test2'); }); it("should...", function(){ print('start test3'); });My test output looks like this:
.......start test1 .setTimeout stubAs you can see, test2 and test3 are never executed. Am I don't something wrong here?
Thanks!
Comments
-
9 comments Created 4 months ago by drnicfixxRandom asset load order in Safari causing runtime bugssafarixComments
Dr Nic, thanks for pointing this out. It looks like we need to explicitly chain the requires in the blue-ridge.js file rather than just require them all asynchronously.
Hi,
I reordered the require's in blue-ridge.js like so:
require(BLUE_RIDGE_LIB_PREFIX + "jquery-1.3.2.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "jquery.fn.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "jquery.print.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "screw.builder.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "screw.matchers.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "screw.events.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "screw.behaviors.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "smoke.core.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "smoke.mock.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "smoke.stub.js", { onload: function() { require(BLUE_RIDGE_LIB_PREFIX + "screw.mocking.js", { onload: function() { require(derive_spec_name_from_current_file()); }}); }}); }}); }}); }}); }}); }}); }}); }}); }}); }});Everything loads in order, but it tests still don't run correctly on Safari 4. Any ideas?
Let's just take a moment to observe how disturbing that code looks due to the nested nature. ... I need another moment... :D
If we do get this working, it would be fun to come up with a DSL for nested require's, something like:
require('some_file.js'). then_require('dependent_file.js)That would be sweet.
Are you coming to FutureRuby this weekend?
@tanzeeb: Have you actually got it working with that? When I make that change, the files load correctly, but Safari 4.0.2 doesn't actually run any of the tests.
It looks like Safari either 1) isn't telling jQuery that the DOM is ready or 2) telling jQuery that the DOM is ready too soon.
@karnowski - @tanzeeb says above it still isn't working for him on Safari.
Hmm, interesting problem. I'm sure I've seen the tests run occasionally on Safari. Hopefully I can find some time to poke around. Stupid bug.
@drnic Well if you rotate your monitor 90 degrees, it looks like a very nice pyramid. ;-) Missed out on FutureRuby, did you go? How was it?
@karnowski No I still haven't figured out why it doesn't run in Safari 4. Tight deadline on my project, but once its done I'll take a look to see why. I think you're right about it being a jQuery / DOM Ready issue.
any updates?
I'm stuck with a safari specific bug and I'd love to write some tests to verify the bugs are fixed.
-
Would it be possible to reload the HTML fixture before each spec? I'm having problems because one spec will modify the dom, affecting the state for all other specs.
Comments
In theory we could clone $('body').html() before each test and then restore it afterwards. Would this retain any events etc attached to all the DOM elements?
BTW, I see this issue as the only thing (and the Safari bug and acceptance of #14) stopping blue-ridge from being perfect.
I use this:
function fixture(element) {
$('').append(element).appendTo("body"); }function teardownFixtures() {
$("#fixtures").remove(); }Then I call the "fixture" function in my spec and "teardownFixtures" in an after block. I've been hesitating to include this as a standard BlueRidge component, though, as it's very jQuery specific. I might have to rethink that.
dan-manges
Mon Aug 10 17:57:36 -0700 2009
| link
@karnowski what do you think about reloading the html fixture? Is that something you would welcome in blue-ridge?
jonah-carbonfive
Fri Oct 02 13:58:49 -0700 2009
| link
I've found myself adding the following to many of my specs and writing my tests to operate only on DOM elements within a #fixtures div:
var bodyContent; before(function() { if (bodyContent == null) { bodyContent = $("#fixture").html(); } else { $("#fixture").html(bodyContent); } });I'll probably add that to my fixture and spec templates at some point but I'm not sure it makes sense to try to reload the fixture in all cases. I don't see how you could be certain to reload the fixture's state while still being able to run the tests by opening the fixture's html file. Would including the sort of reset I'm using in the default templates be useful to anyone else?
botandrose
Mon Nov 16 16:08:57 -0800 2009
| link
Hello, folks! The following gist is a proof of concept for automatic transactional fixtures (including events).
Is there interest in developing this into a patch?
There is a dependency on jQuery... $.fn.clone(true) is doing all the heavy lifting, but isn't this a moot point since Screw Unit depends on jQuery as well?
-
1 comment Created 3 months ago by drnicStarting to cover blue-ridge with cucumber integration testsfeaturexI've started writing integration tests for the rake tasks. Specifically there are scenarios for running 'rake test:javascripts' on: a rails project, a non-rails project, and on blue-ridge itself. With integration tests this will allow us to explore alternate compositions of technology (say trialling htmltest instead of env.js + rhino, or switching out screw.unit for jspec or whatever), but make sure that the core generators and headless test rake tasks keep working.
This work is in a "features" branch (http://github.com/drnic/blue-ridge/tree/features) though this branch also includes all my other commits and merged commits from other people's branches.
If you want the cucumber specific changes only, let me know, else hopefully you can pull in all the changes (some which solve other issues such as #14)
Comments
-
in javascript: 0, 0.0, null, undefined, '', ' ', etc. all evaluate to false when cast to a boolean, and almost everything else evaluates to true. the be_true and be_false method should not just check actual and !actual, but (actual === true) and (actual === false).
A similar issue is present with be_null, be_undefined and equal, (false == 0, false !== 0, null == undefined, but null !== undefined).
Comments
kristopher
Wed Aug 05 11:49:05 -0700 2009
| link
Agreed the == operators type coercion is a tricky thing to deal with in javascript testing frameworks almost all the frameworks I've looked at handle their equal and be matchers differently. Some of these issues you stated are fixed in my or other peoples forks of screw-unit they just haven't been pull into blue ridge yet.
-
1 comment Created 3 months ago by karnowskifixxgoogle chromexTests do not run in super-fast JavaScript engines (Safari 4 & Chrome)safarixChad Humphries and I spent a day trying to track this down, and we haven't found it yet, but it looks like the timing of Screw.Unit, jQuery, and the BlueRidge requires are in such an order that Safari never fires the jQuery ready function. So your Screw.Unit specs never run. (Actually, it might be firing the ready function, just before BlueRidge and Screw.Unit are ready for it.)
Still more work to do, any ideas welcome.
Comments
Looked into this a bit more, and the tests are not running in exactly the same way in Google Chrome too (both on Windows, version 2.0.172.43, and Chromium on Mac, the 2009/09/04 nightly). It appears that the require() functions and the jQuery ready() timing are out of whack on Nitro (Safari's JS engine) and V8 (Chrome's JS engine).
-
Specs running on the command line under env.js don't execute inline tags in the fixture body. Even if this is supposed to be the default behavior, there should be a way to re-enable inline script loading without modifying test_runner.js. We monkey-patched to fix this issue just by commenting out line 57 in test_runner.js ("loadInlineScript: function(){},").
Looks like there was a recent commit that changed the way test_runner is loading fixtures ( http://github.com/relevance/blue-ridge/commit/7617cd85fb71e5cfe0e6e54d9d8f5281e31079ea ). Just wondering what the rationale behind that particular change was...
Comments
Hmm, I had just turned that feature off because it was conflicting in some of my tests. I hadn't thought that some folks might be relying on it. You have a great point, though, that this should be configurable. I'm marking this ticket as a feature request for a config option. Thanks!
-
Generate fixtures on the fly from the Rails itself
1 comment Created about 1 month ago by cmanfu
- env.js▾
- feature▾
- fix▾
- google chrome▾
- rhino▾
- safari▾
- screw.unit▾
- smoke▾
- suggestion▾
- wontfix▾
- Apply to Selection
-
Change Color…
Preview:preview
- Rename…
- Delete














Is it possibly that 'setTimeout' is a bad thing to be stubbing out (and possibly used by the Blue-Ridge framework)? If so, 'doh' (on me).
We're definitely not using setTimeout in Blue Ridge, but maybe Screw.Unit is? We'll look into it.
Thanks! The night after I posted my comment, I noticed in John Resig's JS "Ninja" book, that he gives a simple example of a JS testing framework that uses setTimeout to queue tests. So, perhaps it is indeed in Screw.Unit.
Does anyone have samples of testing behaviour that does take some time to complete? how do we "wait X seconds" before asserting that some behaviour has been performed?
@drnic - Perhaps there is a better way of accomplishing this test, as JS is single-threaded. Maybe passing callback or firing an event would be better?
i'm stuck with the same issue. i'm trying to test code that uses setTimeout and the test completes before the code is executed. does screwunit support some kind of asyn callback for testing?