Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 module.metadata = {
8 "stability": "deprecated"
9 };
11 const file = require("../io/file");
12 const memory = require('./memory');
13 const suites = require('@test/options').allTestModules;
14 const { Loader } = require("sdk/test/loader");
15 const cuddlefish = require("sdk/loader/cuddlefish");
17 let loader = Loader(module);
18 const NOT_TESTS = ['setup', 'teardown'];
20 var TestFinder = exports.TestFinder = function TestFinder(options) {
21 memory.track(this);
22 this.filter = options.filter;
23 this.testInProcess = options.testInProcess === false ? false : true;
24 this.testOutOfProcess = options.testOutOfProcess === true ? true : false;
25 };
27 TestFinder.prototype = {
28 findTests: function findTests(cb) {
29 var self = this;
30 var tests = [];
31 var filter;
32 // A filter string is {fileNameRegex}[:{testNameRegex}] - ie, a colon
33 // optionally separates a regex for the test fileName from a regex for the
34 // testName.
35 if (this.filter) {
36 var colonPos = this.filter.indexOf(':');
37 var filterFileRegex, filterNameRegex;
38 if (colonPos === -1) {
39 filterFileRegex = new RegExp(self.filter);
40 } else {
41 filterFileRegex = new RegExp(self.filter.substr(0, colonPos));
42 filterNameRegex = new RegExp(self.filter.substr(colonPos + 1));
43 }
44 // This function will first be called with just the filename; if
45 // it returns true the module will be loaded then the function
46 // called again with both the filename and the testname.
47 filter = function(filename, testname) {
48 return filterFileRegex.test(filename) &&
49 ((testname && filterNameRegex) ? filterNameRegex.test(testname)
50 : true);
51 };
52 } else
53 filter = function() {return true};
55 suites.forEach(function(suite) {
56 // Load each test file as a main module in its own loader instance
57 // `suite` is defined by cuddlefish/manifest.py:ManifestBuilder.build
59 let suiteModule;
61 try {
62 suiteModule = cuddlefish.main(loader, suite);
63 }
64 catch (e) {
65 if (!/^Unsupported Application/.test(e.message))
66 throw e;
67 // If `Unsupported Application` error thrown during test,
68 // skip the test suite
69 suiteModule = {
70 'test suite skipped': assert => assert.pass(e.message)
71 };
72 }
74 if (self.testInProcess)
75 for each (let name in Object.keys(suiteModule).sort()) {
76 if(NOT_TESTS.indexOf(name) === -1 && filter(suite, name)) {
77 tests.push({
78 setup: suiteModule.setup,
79 teardown: suiteModule.teardown,
80 testFunction: suiteModule[name],
81 name: suite + "." + name
82 });
83 }
84 }
85 });
87 cb(tests);
88 }
89 };