Skip to content

Commit 6174596

Browse files
committed
test: harden the Jasmine run against restarts and startup failures
- MyActivity registers and runs the suite once per process; a recreated activity would otherwise hit Jasmine's rejection of a second run. - When Jasmine cannot start the run, boot.js writes a failing JUnit result so the runtests harness reports it instead of timing out. - The UI-thread dispatch spec is named for what it checks: with multithreaded JavaScript on, the callback may run on the calling thread.
1 parent b3961a7 commit 6174596

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

‎test-app/app/src/main/assets/app/Infrastructure/Jasmine/boot.js‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,22 @@ env.addReporter(new TerminalReporter({
3636
}));
3737
env.addReporter(new JUnitXmlReporter());
3838

39+
// Without a results file the runtests harness only gives up after its full
40+
// timeout, so a run that cannot start still writes one failing testcase.
41+
function saveRunFailure(message) {
42+
var xml = '<?xml version="1.0" encoding="UTF-8" ?>\n<testsuites>' +
43+
'\n <testsuite name="Jasmine run" hostname="localhost" time="0" errors="0" tests="1" skipped="0" failures="1">' +
44+
'\n <testcase classname="Jasmine run" name="(run could not start)" time="0">' +
45+
'\n <failure type="exception" message="Jasmine could not run the suite">' +
46+
'<![CDATA[' + message.replace(/\]\]>/g, ']]]]><![CDATA[>') + ']]>' +
47+
'\n </failure>\n </testcase>\n </testsuite>\n</testsuites>';
48+
global.__JUnitSaveResults(xml);
49+
}
50+
3951
exports.execute = function () {
4052
env.execute().catch(function (e) {
41-
// No JUnit report follows; the runtests harness times out waiting for it.
42-
console.log("Jasmine could not run the suite: " + ((e && e.stack) || e));
53+
var message = String((e && e.stack) || e);
54+
console.log("Jasmine could not run the suite: " + message);
55+
saveRunFailure(message);
4356
});
4457
};

‎test-app/app/src/main/assets/app/MyActivity.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
}
2222
}
2323
*/
24+
var testRunStarted = false;
25+
2426
var MyActivity = (function (_super) {
2527
__extends(MyActivity, _super);
2628
function MyActivity() {
@@ -29,8 +31,13 @@ var MyActivity = (function (_super) {
2931
MyActivity.prototype.onCreate = function (bundle) {
3032
_super.prototype.onCreate.call(this, bundle);
3133

32-
require('./tests/testsWithContext').run(this);
33-
require('./Infrastructure/Jasmine/boot').execute();
34+
// A recreated activity in the same process must not register or run the
35+
// suite again: Jasmine rejects both once the run has started.
36+
if (!testRunStarted) {
37+
testRunStarted = true;
38+
require('./tests/testsWithContext').run(this);
39+
require('./Infrastructure/Jasmine/boot').execute();
40+
}
3441

3542
var layout = new android.widget.LinearLayout(this);
3643
layout.setOrientation(1);

‎test-app/app/src/main/assets/app/tests/dispatchCallbacksOnUiThreadTests.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
describe("Tests dispatch callbacks on UI thread ", function () {
22

3-
it("TestProcessDataCallbackShouldBeExecutedOnUiThread", function (done) {
3+
it("TestProcessDataCallbackFromBackgroundThreadReceivesAllData", function (done) {
44

5-
__log("TEST: TestProcessDataCallbackShouldBeExecutedOnUiThread");
5+
__log("TEST: TestProcessDataCallbackFromBackgroundThreadReceivesAllData");
66

77
var received = [];
88
var D = com.tns.tests.DispatchAsyncOpOnUIThreadTest.extend("DispatchAsyncOpOnUIThreadTest", {

0 commit comments

Comments
 (0)