Skip to content
Browse files

Report file names in test failures

This commit changes the way unit tests are ran. Previously
all test files were loaded then run in one go. Now each test
file is loaded and ran. The internal page is refreshed before
running every test file.

Squashed commit of the following:

commit 351cc855799c9d5cf15a4d7cbf0eb2f8e9ab57f1
Author: twinturbo <me@broadcastingadam.com>
Date:   Mon Aug 27 12:44:02 2012 +0200

    Tets to assure casper behavior

commit 0ecd6984bcef4e42153eee5a1425c7811b6d06bf
Author: twinturbo <me@broadcastingadam.com>
Date:   Mon Aug 27 12:36:06 2012 +0200

    File names always present

commit 962a450eeeb17a5a46bdb872686f473349887679
Author: twinturbo <me@broadcastingadam.com>
Date:   Mon Aug 27 12:01:36 2012 +0200

    Capture filename from unit tests
  • Loading branch information...
1 parent ada46a4 commit 5d21fc155ee398f215e8562198cf46e5a743ebb6 twinturbo committed Aug 27, 2012
View
1 lib/iridium/casperjs/lib/iridium.coffee
@@ -122,6 +122,7 @@ class IridiumCasper extends require('casper').Casper
currentTest = {}
currentTest.assertions = 0
currentTest.name = testFile
+ currentTest.file = testFile
# This doesn't mean that the entire test passed, but simply one
# single assertion was correct
View
15 lib/iridium/casperjs/lib/iridium/integration_test_runner.coffee
@@ -1,10 +1,15 @@
-casper.start casper.appURL
-
injectJsStep = (path) ->
casper.then ->
if !casper.page.injectJs(path)
console.abort "Failed to load #{path}!"
+startTestStep = (path) ->
+ casper.then ->
+ @evaluate((file) ->
+ window.currentTestFileName = file
+ window.startTests()
+ , { file: path})
+
waitForTestStep = (path) ->
casper.waitFor(
->
@@ -21,6 +26,8 @@ waitForTestStep = (path) ->
casper.logger.message result
)
+casper.start casper.appURL
+
for integrationTest in casper.integrationTests
if integrationTest != casper.integrationTests[0]
@@ -29,9 +36,7 @@ for integrationTest in casper.integrationTests
injectJsStep integrationTest
- casper.then ->
- @evaluate ->
- window.startTests()
+ startTestStep integrationTest
waitForTestStep integrationTest
View
2 lib/iridium/casperjs/lib/iridium/qunit_adapter.coffee
@@ -3,6 +3,7 @@
QUnit.testStart (context) =>
@currentTest = {}
+ @currentTest.file = window.currentTestFileName
@currentTest.name = context.name
@currentTest.assertions = 0
@currentTest.backtrace = []
@@ -54,6 +55,7 @@ QUnit.done (context) =>
QUnit.config.autorun = false
window.startTests = ->
+ window.testsDone = false
container = document.createElement('div')
container.setAttribute "id", "qunit"
document.body.insertBefore container, document.body.firstChild
View
52 lib/iridium/casperjs/lib/iridium/unit_test_runner.coffee
@@ -13,25 +13,45 @@ casper.on 'resource.received', (request) ->
logger.message result
casper.test.done()
-casper.start casper.unitTestLoader, ->
- for test in @unitTests
- if !@page.injectJs(test)
+injectJsStep = (path) ->
+ casper.then ->
+ if !casper.page.injectJs(path)
console.abort "Failed to load #{path}!"
-casper.then ->
- @evaluate ->
- window.startTests()
+waitForTestStep = (path) ->
+ casper.waitFor(
+ ->
+ casper.evaluate ->
+ window.testsDone == true
+ , ->
+ # do nothing, the test passed
+ true
+ , ->
+ result = {}
+ result.name = apth
+ result.message = "Test timed out"
+ result.error = true
+ casper.logger.message result
+ )
-casper.waitFor(
- ->
- casper.evaluate ->
- window.testsDone == true
- , ->
- casper.test.done()
- , ->
- console.log "Test timed out"
- casper.test.done()
-)
+startTestStep = (path) ->
+ casper.then ->
+ @evaluate((file) ->
+ window.currentTestFileName = file
+ window.startTests()
+ , { file: path})
+
+casper.start casper.unitTestLoader
+
+for unitTest in casper.unitTests
+ casper.then ->
+ casper.reload()
+
+ injectJsStep unitTest
+
+ startTestStep unitTest
+
+ waitForTestStep unitTest
casper.run ->
@test.done()
View
3 lib/iridium/test_report.rb
@@ -58,8 +58,7 @@ def print_results(results)
puts "\n"
results.reject(&:passed?).each do |result|
- io.puts result.name
- io.puts " #{result.file}" if result.file
+ io.puts "#{result.file}: #{result.name}"
io.puts " #{result.message}"
if result.error?
View
14 test/integration/running_casper_tests_test.rb
@@ -28,7 +28,10 @@ def test_reports_basic_information
results, stdout, stderr = invoke "test/casper/success.js"
+ assert_kind_of Array, results
+ assert_equal 1, results.size
test_result = results.first
+ assert_equal "test/casper/success.js", test_result.file
assert_kind_of Fixnum, test_result.time
assert_equal 1, test_result.assertions
assert test_result.name
@@ -62,6 +65,8 @@ def test_reports_a_failure
test
results, stdout, stderr = invoke "test/casper/failure.js"
+ assert_kind_of Array, results
+ assert_equal 1, results.size
test_result = results.first
assert test_result.failed?
assert_includes test_result.message, "Server should be down!"
@@ -81,6 +86,8 @@ def test_reports_an_error
test
results, stdout, stderr = invoke "test/casper/error.js"
+ assert_kind_of Array, results
+ assert_equal 1, results.size
test_result = results.first
assert test_result.error?
assert_equal "ReferenceError: Can't find variable: foobar", test_result.message
@@ -125,6 +132,7 @@ def test_handles_javascript_errors_in_source_files
results, stdout, stderr = invoke "test/casper/error.js"
+ assert_kind_of Array, results
assert_equal 1, results.size
test_result = results.first
assert test_result.error?
@@ -150,6 +158,7 @@ def test_does_not_let_one_test_bring_down_others
results, stdout, stderr = invoke "test/casper/error.js", "test/casper/success.js"
+ assert_kind_of Array, results
assert_equal 2, results.size
assert results[0].error?
assert results[1].passed?
@@ -198,6 +207,7 @@ def test_internal_assertion_failure_handling_does_not_bring_down_other_tests
results, stdout, stderr = invoke "test/casper/failing_assertions.js", "test/casper/truth.js"
+ assert_kind_of Array, results
assert_equal 2, results.size
end
@@ -225,6 +235,7 @@ def test_errors_are_reported_multiple_times
results, stdout, stderr = invoke "test/casper/failing_assertions.js", "test/casper/error.js"
+ assert_kind_of Array, results
assert_equal 2, results.size
end
@@ -242,6 +253,7 @@ def test_test_cannot_be_tereminated
results, stdout, stderr = invoke "test/casper/double_termination.js"
+ assert_kind_of Array, results
assert_equal 1, results.size
end
@@ -266,6 +278,7 @@ def test_happy_path_steps_work_correctly
results, stdout, stderr = invoke "test/casper/multiple_steps.js"
+ assert_kind_of Array, results
assert_equal 1, results.size
result = results.first
assert result.passed?
@@ -293,6 +306,7 @@ def test_failed_assertions_halt_the_next_step
results, stdout, stderr = invoke "test/casper/multiple_steps.js"
+ assert_kind_of Array, results
assert_equal 1, results.size
result = results.first
assert result.failed?
View
6 test/integration/running_qunit_tests_test.rb
@@ -59,10 +59,12 @@ def test_captures_basic_test_information
results, stdout, stderr = invoke "test/truth_test.js"
assert_kind_of Array, results
+ assert_equal 1, results.size
test_result = results.first
assert_equal "Truth", test_result.name
assert_kind_of Fixnum, test_result.time
assert_equal 1, test_result.assertions
+ assert_equal "test/truth_test.js", test_result.file
end
def test_reports_passes
@@ -73,6 +75,7 @@ def test_reports_passes
test
results, stdout, stderr = invoke "test/truth_test.js"
+ assert_equal 1, results.size
assert_kind_of Array, results
test_result = results.first
assert test_result.passed?
@@ -88,6 +91,7 @@ def test_reports_assertion_errors
results, stdout, stderr = invoke "test/failed_assertion.js"
assert_kind_of Array, results
+ assert_equal 1, results.size
test_result = results.first
assert test_result.failed?
assert_equal "failed", test_result.message
@@ -104,6 +108,7 @@ def test_reports_expectation_errors
results, stdout, stderr = invoke "test/failed_expectation.js"
assert_kind_of Array, results
+ assert_equal 1, results.size
test_result = results.first
assert test_result.failed?
assert_match test_result.message, /expect/i
@@ -122,6 +127,7 @@ def test_reports_errors
results, stdout, stderr = invoke "test/error.js"
assert_kind_of Array, results
+ assert_equal 1, results.size
test_result = results.first
assert test_result.error?
assert test_result.backtrace

0 comments on commit 5d21fc1

Please sign in to comment.
Something went wrong with that request. Please try again.