mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 873126: integrate Assert.jsm into Mochitest. r=ted
This commit is contained in:
parent
90242b923f
commit
59d741243b
@ -75,12 +75,14 @@ function Tester(aTests, aDumper, aCallback) {
|
||||
this.SimpleTest = simpleTestScope.SimpleTest;
|
||||
this.Task = Components.utils.import("resource://gre/modules/Task.jsm", null).Task;
|
||||
this.Promise = Components.utils.import("resource://gre/modules/commonjs/sdk/core/promise.js", null).Promise;
|
||||
this.Assert = Components.utils.import("resource://testing-common/Assert.jsm", null).Assert;
|
||||
}
|
||||
Tester.prototype = {
|
||||
EventUtils: {},
|
||||
SimpleTest: {},
|
||||
Task: null,
|
||||
Promise: null,
|
||||
Assert: null,
|
||||
|
||||
repeat: 0,
|
||||
runUntilFailure: false,
|
||||
@ -437,7 +439,8 @@ Tester.prototype = {
|
||||
this.SimpleTest.reset();
|
||||
|
||||
// Load the tests into a testscope
|
||||
this.currentTest.scope = new testScope(this, this.currentTest);
|
||||
let currentScope = this.currentTest.scope = new testScope(this, this.currentTest);
|
||||
let currentTest = this.currentTest;
|
||||
|
||||
// Import utils in the test scope.
|
||||
this.currentTest.scope.EventUtils = this.EventUtils;
|
||||
@ -445,6 +448,23 @@ Tester.prototype = {
|
||||
this.currentTest.scope.gTestPath = this.currentTest.path;
|
||||
this.currentTest.scope.Task = this.Task;
|
||||
this.currentTest.scope.Promise = this.Promise;
|
||||
// Pass a custom report function for mochitest style reporting.
|
||||
this.currentTest.scope.Assert = new this.Assert(function(err, message, stack) {
|
||||
let res;
|
||||
if (err) {
|
||||
res = new testResult(false, err.message, err.stack, false, err.stack);
|
||||
} else {
|
||||
res = new testResult(true, message, "", false, stack);
|
||||
}
|
||||
currentTest.addResult(res);
|
||||
});
|
||||
|
||||
// Allow Assert.jsm methods to be tacked to the current scope.
|
||||
this.currentTest.scope.export_assertions = function() {
|
||||
for (let func in this.Assert) {
|
||||
this[func] = this.Assert[func].bind(this.Assert);
|
||||
}
|
||||
};
|
||||
|
||||
// Override SimpleTest methods with ours.
|
||||
["ok", "is", "isnot", "ise", "todo", "todo_is", "todo_isnot", "info", "expectAssertions"].forEach(function(m) {
|
||||
@ -483,8 +503,6 @@ Tester.prototype = {
|
||||
if ("test" in this.currentTest.scope) {
|
||||
throw "Cannot run both a add_task test and a normal test at the same time.";
|
||||
}
|
||||
let testScope = this.currentTest.scope;
|
||||
let currentTest = this.currentTest;
|
||||
this.Task.spawn(function() {
|
||||
let task;
|
||||
while ((task = this.__tasks.shift())) {
|
||||
@ -501,7 +519,7 @@ Tester.prototype = {
|
||||
this.SimpleTest.info("Leaving test " + task.name);
|
||||
}
|
||||
this.finish();
|
||||
}.bind(testScope));
|
||||
}.bind(currentScope));
|
||||
} else if ("generatorTest" in this.currentTest.scope) {
|
||||
if ("test" in this.currentTest.scope) {
|
||||
throw "Cannot run both a generator test and a normal test at the same time.";
|
||||
@ -771,6 +789,7 @@ testScope.prototype = {
|
||||
SimpleTest: {},
|
||||
Task: null,
|
||||
Promise: null,
|
||||
Assert: null,
|
||||
|
||||
/**
|
||||
* Add a test function which is a Task function.
|
||||
|
@ -5,3 +5,4 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
|
||||
BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
|
||||
|
1
testing/modules/tests/browser/browser.ini
Normal file
1
testing/modules/tests/browser/browser.ini
Normal file
@ -0,0 +1 @@
|
||||
[browser_test_assert.js]
|
18
testing/modules/tests/browser/browser_test_assert.js
Normal file
18
testing/modules/tests/browser/browser_test_assert.js
Normal file
@ -0,0 +1,18 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function test() {
|
||||
export_assertions();
|
||||
|
||||
ok(true, "pass ok");
|
||||
is(true, true, "pass is");
|
||||
isnot(false, true, "pass isnot");
|
||||
ise(true, true, "pass ise");
|
||||
todo(false, "pass todo");
|
||||
todo_is(false, true, "pass todo_is");
|
||||
todo_isnot(true, true, "pass todo_isnot");
|
||||
info("info message");
|
||||
|
||||
var func = is;
|
||||
func(true, 1, "pass indirect is");
|
||||
}
|
Loading…
Reference in New Issue
Block a user