DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Git (975a35c0f5)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
'use strict';

/**
 * This script is used to run test case for gaia build system.
 */

var utils = require('./utils');
var Mocha = require('mocha');

exports.execute = function(options) {
  var TEST_TYPE = utils.getEnv('TEST_TYPE');
  var REPORTER = utils.getEnv('REPORTER');
  var TRY_ENV = utils.getEnv('TRY_ENV');
  var TEST_FILES = utils.getEnv('TEST_FILES');
  var TIMEOUT = '600000';
  var BUILD_TEST_PATH = 'build/test/';
  var thisChunk = utils.getEnv('THIS_CHUNK') || 1;
  var totalChunks = utils.getEnv('TOTAL_CHUNKS') || 1;

  var mocha = new Mocha({
    ui: 'tdd',
    reporter: REPORTER,
    timeout: TIMEOUT
  });

  // Specify build test libraries path for build script testing
  utils.setEnv('NODE_PATH', '$NODE_PATH:' + BUILD_TEST_PATH + TEST_TYPE);

  if (TRY_ENV === '1') {
    // Pass MOZ_DISABLE_NONLOCAL_CONNECTIONS=1 to try server in order to fail
    // testing if there are network connections.
    utils.setEnv('MOZ_DISABLE_NONLOCAL_CONNECTIONS', '1');
    // Exclude tests if mocha test description marks [Network Required]
    mocha.grep(/\[Network Required\]/).invert();
  }

  var testDir = utils.getFile(options.GAIA_DIR);
  var files = [];
  var pattern;

  if (TEST_FILES) {
    pattern = new RegExp(TEST_FILES.trim().replace(' ', '|'));
  } else {
    pattern = new RegExp('^' + options.GAIA_DIR +
      '(/build/test/|/apps/\\S+/test/build/)' + TEST_TYPE + '/\\S+_test\\.js$');
  }

  utils.ls(testDir, true).forEach(function(file) {
    if (pattern.test(file.path)) {
      files.push(file.path);
    }
  });

  // Sort test files to ensure the order of files will be the same everytime.
  files = files.sort();

  // Calculate chunks for task cluster to split tests
  if (files.length >= totalChunks) {
    let chunkLength = parseInt(Math.ceil(files.length / totalChunks));
    let chunk = parseInt((thisChunk - 1) * chunkLength);
    files = files.slice(chunk, chunk + chunkLength);
  }

  // Use Mocha to run test cases.
  files.forEach(mocha.addFile, mocha);
  mocha.run(utils.exit);
};