Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Note: You might need to run the Android Studio from the command line in order to

## How to Run Tests

* Run `npm install` in the repository root. The test app's Jasmine (`jasmine-core`) comes from there and is copied into the APK at build time.
* Go to subfolder test-app after you built the runtime.
* Start an emulator or connect a device.

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dayjs": "^1.11.7",
"eslint": "^9.15.0",
"globals": "^15.12.0",
"jasmine-core": "7.0.2",
"semver": "^7.5.0"
}
}
57 changes: 57 additions & 0 deletions test-app/app/src/main/assets/app/Infrastructure/Jasmine/boot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Boots jasmine-core for the test app. The test-runner-deps plugin
// (test-app/test-runner-deps) stages jasmine-core from the repo's node_modules
// into ./vendor at build time.
var jasmineCore = require("./vendor/jasmine-core/jasmine");
var JUnitXmlReporter = require("./jasmine-reporters/junit_reporter").JUnitXmlReporter;
var TerminalReporter = require("./jasmine-reporters/terminal_reporter").TerminalReporter;

jasmineCore.installGlobals(global);

var env = jasmine.getEnv();

env.configure({
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// Suites carry state from one spec to the next (the shared Workers suite
// counts live runtimes across its specs), so they run in declaration order.
random: false
});

// jasmine-core's pretty-printer falls back to value.toString() for tagged objects
// it does not recognize, which throws for null-prototype ones such as module
// namespaces. toBe() builds its message even when it passes, so without this an
// expect(namespace).toBe(sameNamespace) throws.
beforeEach(function () {
jasmine.addCustomObjectFormatter(function (value) {
if (value !== null && typeof value === "object" && typeof value.toString !== "function") {
var tag = Object.prototype.toString.call(value);
if (tag !== "[object Object]") {
return tag;
}
}
return undefined;
});
});

env.addReporter(new TerminalReporter({
verbosity: 2
}));
env.addReporter(new JUnitXmlReporter());

// Without a results file the runtests harness only gives up after its full
// timeout, so a run that cannot start still writes one failing testcase.
function saveRunFailure(message) {
var xml = '<?xml version="1.0" encoding="UTF-8" ?>\n<testsuites>' +
'\n <testsuite name="Jasmine run" hostname="localhost" time="0" errors="0" tests="1" skipped="0" failures="1">' +
'\n <testcase classname="Jasmine run" name="(run could not start)" time="0">' +
'\n <failure type="exception" message="Jasmine could not run the suite">' +
'<![CDATA[' + message.replace(/\]\]>/g, ']]]]><![CDATA[>') + ']]>' +
'\n </failure>\n </testcase>\n </testsuite>\n</testsuites>';
global.__JUnitSaveResults(xml);
}

exports.execute = function () {
env.execute().catch(function (e) {
var message = String((e && e.stack) || e);
console.log("Jasmine could not run the suite: " + message);
saveRunFailure(message);
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Wraps a done-style spec body that raises global `error` events or unhandled
// rejections on purpose. Jasmine fails the running spec on those unless its
// global error spy is installed, which it is for as long as the body runs; the
// spy is passed as the body's second argument. Jasmine's spy never cancels the
// event, so listeners, preventDefault() and the __onUncaughtError fallback behave
// as they do in production.
//
// The body must call done() only after every error it expects was dispatched:
// one that arrives later is charged to whatever spec is running then.
exports.raisesGlobalErrors = function (body) {
return function () {
var context = this;
return jasmine.spyOnGlobalErrorsAsync(function (globalErrorSpy) {
return new Promise(function (resolve, reject) {
function done(reason) {
if (reason === undefined) {
resolve();
} else {
reject(reason instanceof Error ? reason : new Error(String(reason)));
}
}
done.fail = function (reason) {
done(reason === undefined ? new Error("Failed") : reason);
};
body.call(context, done, globalErrorSpy);
});
});
};
};

This file was deleted.

Loading
Loading