dwf/rva: added better exception handling for Webkit

This commit is contained in:
pivotal 2009-01-15 12:40:00 -08:00
parent 183b06bb9d
commit c94496c9fe
3 changed files with 161 additions and 72 deletions

View File

@ -80,7 +80,7 @@
<file leaf-file-name="bootstrap.html" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
<provider selected="true" editor-type-id="text-editor">
<state line="12" column="4" selection-start="533" selection-end="533" vertical-scroll-proportion="0.25249168">
<state line="12" column="4" selection-start="533" selection-end="533" vertical-scroll-proportion="0.23799582">
<folding />
</state>
</provider>
@ -89,19 +89,19 @@
</provider>
</entry>
</file>
<file leaf-file-name="bootstrap.js" pinned="false" current="true" current-in-tab="true">
<file leaf-file-name="bootstrap.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="842" column="193" selection-start="26377" selection-end="26377" vertical-scroll-proportion="0.94043887">
<state line="893" column="101" selection-start="27681" selection-end="27681" vertical-scroll-proportion="0.6620553">
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="jasmine.js" pinned="false" current="false" current-in-tab="false">
<file leaf-file-name="jasmine.js" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="389" column="1" selection-start="8626" selection-end="8626" vertical-scroll-proportion="0.88271606">
<state line="246" column="7" selection-start="5573" selection-end="5573" vertical-scroll-proportion="0.4935065">
<folding />
</state>
</provider>
@ -122,7 +122,7 @@
<file leaf-file-name="jasmine.css" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/lib/jasmine.css">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="36" selection-start="351" selection-end="351" vertical-scroll-proportion="0.33230454">
<state line="17" column="36" selection-start="351" selection-end="351" vertical-scroll-proportion="0.3145083">
<folding />
</state>
</provider>
@ -131,7 +131,7 @@
<file leaf-file-name="example.js" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/example.js">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11728395">
<state line="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11100292">
<folding />
</state>
</provider>
@ -296,6 +296,13 @@
<RUBY_DOC NAME="NUMBER" VALUE="0" />
</component>
<component name="RunManager">
<configuration default="true" type="Remote" factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" value="javadebug" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
</configuration>
<configuration default="true" type="RubyRunConfigurationType" factoryName="Ruby test">
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="" />
@ -310,6 +317,31 @@
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
<RTEST_RUN_CONFIG_SETTINGS_ID NAME="INHERITANCE_CHECK_DISABLED" VALUE="false" />
</configuration>
<configuration default="true" type="Applet" factoryName="Applet">
<module name="" />
<option name="MAIN_CLASS_NAME" />
<option name="HTML_FILE_NAME" />
<option name="HTML_USED" value="false" />
<option name="WIDTH" value="400" />
<option name="HEIGHT" value="300" />
<option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
<option name="VM_PARAMETERS" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
</configuration>
<configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="" />
<envs />
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit" enabled="false" merge="false">
<module name="" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
@ -329,38 +361,6 @@
</option>
<envs />
</configuration>
<configuration default="true" type="Application" factoryName="Application" enabled="false" merge="false">
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="" />
<envs />
</configuration>
<configuration default="true" type="Applet" factoryName="Applet">
<module name="" />
<option name="MAIN_CLASS_NAME" />
<option name="HTML_FILE_NAME" />
<option name="HTML_USED" value="false" />
<option name="WIDTH" value="400" />
<option name="HEIGHT" value="300" />
<option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
<option name="VM_PARAMETERS" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
</configuration>
<configuration default="true" type="Remote" factoryName="Remote">
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" value="javadebug" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
</configuration>
<list size="0" />
<configuration name="&lt;template&gt;" type="WebApp" default="true" selected="false">
<Host>localhost</Host>
@ -412,13 +412,13 @@
</todo-panel>
</component>
<component name="ToolWindowManager">
<frame x="43" y="39" width="1862" height="1116" extended-state="0" />
<frame x="26" y="22" width="1833" height="1171" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="IDEtalk" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="3" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="7" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.2107005" order="0" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.2102018" order="0" />
<window_info id="RDoc" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" order="8" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32837301" order="1" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" order="1" />
@ -514,7 +514,7 @@
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.html">
<provider selected="true" editor-type-id="text-editor">
<state line="12" column="4" selection-start="533" selection-end="533" vertical-scroll-proportion="0.25249168">
<state line="12" column="4" selection-start="533" selection-end="533" vertical-scroll-proportion="0.23799582">
<folding />
</state>
</provider>
@ -534,28 +534,28 @@
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.css">
<provider selected="true" editor-type-id="text-editor">
<state line="17" column="36" selection-start="351" selection-end="351" vertical-scroll-proportion="0.33230454">
<state line="17" column="36" selection-start="351" selection-end="351" vertical-scroll-proportion="0.3145083">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/example.js">
<provider selected="true" editor-type-id="text-editor">
<state line="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11728395">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="389" column="1" selection-start="8626" selection-end="8626" vertical-scroll-proportion="0.88271606">
<state line="6" column="0" selection-start="183" selection-end="183" vertical-scroll-proportion="0.11100292">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/bootstrap.js">
<provider selected="true" editor-type-id="text-editor">
<state line="842" column="193" selection-start="26377" selection-end="26377" vertical-scroll-proportion="0.94043887">
<state line="893" column="101" selection-start="27681" selection-end="27681" vertical-scroll-proportion="0.6620553">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/jasmine.js">
<provider selected="true" editor-type-id="text-editor">
<state line="246" column="7" selection-start="5573" selection-end="5573" vertical-scroll-proportion="0.4935065">
<folding />
</state>
</provider>

View File

@ -210,6 +210,11 @@ Jasmine.Matchers.method('should_be_defined', function () {
'Expected ' + this.actual + ' to be defined.');
});
Jasmine.Matchers.method('innerHTML_should_match', function (reg_exp) {
return this.report((reg_exp.match(this.actual.innerHTML)),
'Expected ' + this.actual.innerHTML + ' to match ' + reg_exp + '.');
});
/*
* Jasmine spec constructor
*/
@ -254,8 +259,7 @@ var it = function (description, func) {
catch (e) {
that.results.push({
passed: false,
message: e.name + ': '+ e.message + ' in ' + e.fileName +
' (line ' + e.lineNumber +')'
message: Jasmine.Util.formatException(e)
});
queuedFunc.next();
}
@ -388,3 +392,35 @@ Jasmine.Reporters.reporter = function (callbacks) {
return that;
}
Jasmine.Util = {
formatException: function(e) {
// if (typeof e === 'String') {
// return e;
// }
var lineNumber;
if (e.line) {
lineNumber = e.line;
}
else if (e.lineNumber) {
lineNumber = e.lineNumber;
}
var file;
if (e.sourceURL) {
file = e.sourceURL;
}
else if (e.fileName) {
file = e.fileName;
}
var message = e.name + ': ' + e.message;
if (file && lineNumber) {
message += ' in ' + file +' (line ' + lineNumber + ')';
}
return message;
}
}

81
test/bootstrap.js vendored
View File

@ -693,9 +693,15 @@ var testReporterWithCallbacks = function () {
var bar = 0;
var baz = 0;
var specCallback = function (results) { foo++; }
var suiteCallback = function (results) { bar++; }
var runnerCallback = function (results) { baz++; }
var specCallback = function (results) {
foo++;
}
var suiteCallback = function (results) {
bar++;
}
var runnerCallback = function (results) {
baz++;
}
jasmine.reporter = Jasmine.Reporters.reporter({
specCallback: specCallback,
@ -732,8 +738,8 @@ var testJSONReporter = function () {
runner.execute();
setTimeout(function() {
var expectedSpecJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}';
var expectedSuiteJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}';
var expectedSpecJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}';
var expectedSuiteJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}';
var expectedRunnerJSON = '{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"totalCount": 1, "passedCount": 1, "failedCount": 0, "results": [{"passed": true, "message": "Passed."}], "description": "should be a test"}], "description": "Suite for JSON Reporter, NO DOM"}], "description": "All Jasmine Suites"}';
specJSON = jasmine.reporter.specJSON;
@ -782,9 +788,11 @@ var testHandlesBlankSpecs = function () {
describe('Suite for handles blank specs', function () {
it('should be a test with a blank runs block', function() {
runs(function () {});
runs(function () {
});
});
it('should be a blank (empty function) test', function() {
});
it('should be a blank (empty function) test', function() {});
});
runner.execute();
@ -797,10 +805,36 @@ var testHandlesBlankSpecs = function () {
}, 250);
}
var testFormatsExceptionMessages = function () {
var sampleFirefoxException = {
fileName: 'foo.js',
line: '1978',
message: 'you got your foo in my bar',
name: 'A Classic Mistake'
}
var sampleWebkitException = {
sourceURL: 'foo.js',
lineNumber: '1978',
message: 'you got your foo in my bar',
name: 'A Classic Mistake'
}
var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)'
reporter.test((Jasmine.Util.formatException(sampleFirefoxException) === expected),
'Should have got ' + expected + ' but got: ' + Jasmine.Util.formatException(sampleFirefoxException));
reporter.test((Jasmine.Util.formatException(sampleWebkitException) === expected),
'Should have got ' + expected + ' but got: ' + Jasmine.Util.formatException(sampleWebkitException));
};
var testHandlesExceptions = function () {
jasmine = Jasmine.init();
var runner = Runner();
//we run two exception tests to make sure we continue after throwing an exception
describe('Suite for handles exceptions', function () {
it('should be a test that fails because it throws an exception', function() {
runs(function () {
@ -812,7 +846,7 @@ var testHandlesExceptions = function () {
runs(function () {
fakeObject2.fakeMethod2();
});
runs(function () {
runs(function () {
this.expects_that(true).should_equal(true);
});
});
@ -824,6 +858,23 @@ var testHandlesExceptions = function () {
});
});
// it('should be another test that fails because it throws an exception after a wait', function() {
// runs(function () {
// var foo = 'foo';
// });
// waits(250);
// runs(function () {
// fakeObject2.fakeMethod2();
// });
// });
//
// it('should be a passing test that runs after exceptions are thrown from a async test', function() {
// runs(function () {
// this.expects_that(true).should_equal(true);
// });
// });
});
runner.execute();
@ -834,23 +885,24 @@ var testHandlesExceptions = function () {
reporter.test((runner.suites[0].specs[0].expectationResults[0].passed === false),
'First test should have failed, got passed');
reporter.test((runner.suites[0].specs[0].expectationResults[0].message === 'ReferenceError: fakeObject is not defined in file:///Users/pivotal/workspace/jasmine/test/bootstrap.js (line 807)'),
'First test should have shown some exception string, got ' + runner.suites[0].specs[0].expectationResults[0].message);
reporter.test((typeof runner.suites[0].specs[0].expectationResults[0].message.search(/fakeObject/) !== -1),
'First test should have contained /fakeObject/, got ' + runner.suites[0].specs[0].expectationResults[0].message);
reporter.test((runner.suites[0].specs[1].expectationResults[0].passed === false),
'Second test should have a failing first result, got passed');
reporter.test((runner.suites[0].specs[1].expectationResults[0].message === 'ReferenceError: fakeObject2 is not defined in file:///Users/pivotal/workspace/jasmine/test/bootstrap.js (line 813)'),
'Second test should have shown an exception message for the first result, got ' + runner.suites[0].specs[1].expectationResults[0].message);
reporter.test((typeof runner.suites[0].specs[1].expectationResults[0].message.search(/fakeObject2/) !== -1),
'First test should have contained /fakeObject/, got ' + runner.suites[0].specs[1].expectationResults[0].message);
reporter.test((runner.suites[0].specs[1].expectationResults[1].passed === true),
'Second expectation in second test should have still passed');
'Second expectation in second test should have still passed');
reporter.test((runner.suites[0].specs[2].expectationResults[0].passed === true),
'Third test should have passed, got failed');
}, 2000);
}
var testResultsAliasing = function () {
jasmine = Jasmine.init();
var runner = Runner();
@ -930,7 +982,8 @@ var runTests = function () {
testNestedResults();
testResults();
// handle blank specs will work later.
// testHandlesBlankSpecs();
// testHandlesBlankSpecs();
testFormatsExceptionMessages();
testHandlesExceptions();
testResultsAliasing();