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