Bug 745741 - Find a way to get easy code coverage information on GCLI unit tests; r=dcamp
authorJoe Walker <jwalker@mozilla.com>
Tue, 15 May 2012 11:27:18 +0100
changeset 94086 1934b36b8a8d52d94a40ce2cbdc06d4072620a12
parent 94085 1e82a90aeee486ca6a05caaa6e4540a50c5fca0e
child 94087 5467d61f6e6e1fb83f6b19b3de78b184dc65e8ff
push id22696
push userrcampbell@mozilla.com
push dateWed, 16 May 2012 19:04:23 +0000
treeherdermozilla-central@65fb8b9ea0b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp
bugs745741
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 745741 - Find a way to get easy code coverage information on GCLI unit tests; r=dcamp
browser/devtools/shared/test/browser_gcli_web.js
browser/devtools/webconsole/gcli.jsm
--- a/browser/devtools/shared/test/browser_gcli_web.js
+++ b/browser/devtools/shared/test/browser_gcli_web.js
@@ -850,50 +850,55 @@ exports.testSingleNumber = function() {
 exports.testElement = function(options) {
   update({ typed: 'tse', cursor: { start: 3, end: 3 } });
   test.is(        'VVV', statuses);
   test.is(Status.ERROR, status);
   test.is('tse', requ.commandAssignment.value.name);
   test.ok(assign1.arg.isBlank());
   test.is(undefined, assign1.value);
 
-  update({ typed: 'tse :root', cursor: { start: 9, end: 9 } });
-  test.is(        'VVVVVVVVV', statuses);
-  test.is(Status.VALID, status);
-  test.is('tse', requ.commandAssignment.value.name);
-  test.is(':root', assign1.arg.text);
-  if (!options.window.isFake) {
-    test.is(options.window.document.documentElement, assign1.value);
+  if (!options.isNode) {
+    update({ typed: 'tse :root', cursor: { start: 9, end: 9 } });
+    test.is(        'VVVVVVVVV', statuses);
+    test.is(Status.VALID, status);
+    test.is('tse', requ.commandAssignment.value.name);
+    test.is(':root', assign1.arg.text);
+    if (!options.window.isFake) {
+      test.is(options.window.document.documentElement, assign1.value);
+    }
+
+    if (!options.window.isFake) {
+      var inputElement = options.window.document.getElementById('gcli-input');
+      if (inputElement) {
+        update({ typed: 'tse #gcli-input', cursor: { start: 15, end: 15 } });
+        test.is(        'VVVVVVVVVVVVVVV', statuses);
+        test.is(Status.VALID, status);
+        test.is('tse', requ.commandAssignment.value.name);
+        test.is('#gcli-input', assign1.arg.text);
+        test.is(inputElement, assign1.value);
+      }
+      else {
+        test.log('Skipping test that assumes gcli on the web');
+      }
+    }
+
+    update({ typed: 'tse #gcli-nomatch', cursor: { start: 17, end: 17 } });
+    // This is somewhat debatable because this input can't be corrected simply
+    // by typing so it's and error rather than incomplete, however without
+    // digging into the CSS engine we can't tell that so we default to incomplete
+    test.is(        'VVVVIIIIIIIIIIIII', statuses);
+    test.is(Status.ERROR, status);
+    test.is('tse', requ.commandAssignment.value.name);
+    test.is('#gcli-nomatch', assign1.arg.text);
+    test.is(undefined, assign1.value);
   }
-
-  if (!options.window.isFake) {
-    var inputElement = options.window.document.getElementById('gcli-input');
-    if (inputElement) {
-      update({ typed: 'tse #gcli-input', cursor: { start: 15, end: 15 } });
-      test.is(        'VVVVVVVVVVVVVVV', statuses);
-      test.is(Status.VALID, status);
-      test.is('tse', requ.commandAssignment.value.name);
-      test.is('#gcli-input', assign1.arg.text);
-      test.is(inputElement, assign1.value);
-    }
-    else {
-      test.log('Skipping test that assumes gcli on the web');
-    }
+  else {
+    test.log('Skipping :root test due to jsdom (from isNode)');
   }
 
-  update({ typed: 'tse #gcli-nomatch', cursor: { start: 17, end: 17 } });
-  // This is somewhat debatable because this input can't be corrected simply
-  // by typing so it's and error rather than incomplete, however without
-  // digging into the CSS engine we can't tell that so we default to incomplete
-  test.is(        'VVVVIIIIIIIIIIIII', statuses);
-  test.is(Status.ERROR, status);
-  test.is('tse', requ.commandAssignment.value.name);
-  test.is('#gcli-nomatch', assign1.arg.text);
-  test.is(undefined, assign1.value);
-
   update({ typed: 'tse #', cursor: { start: 5, end: 5 } });
   test.is(        'VVVVE', statuses);
   test.is(Status.ERROR, status);
   test.is('tse', requ.commandAssignment.value.name);
   test.is('#', assign1.arg.text);
   test.is(undefined, assign1.value);
 
   update({ typed: 'tse .', cursor: { start: 5, end: 5 } });
@@ -2991,26 +2996,31 @@ exports.testWorking = function() {
   // The fact that we can get anything at all working is a testament to
   // require doing what it should - we don't need to test the
   var requireable = require('gclitest/requirable');
   test.is('thing1', requireable.thing1);
   test.is(2, requireable.thing2);
   test.ok(requireable.thing3 === undefined);
 };
 
-exports.testDomains = function() {
+exports.testDomains = function(options) {
   var requireable = require('gclitest/requirable');
   test.ok(requireable.status === undefined);
   requireable.setStatus(null);
   test.is(null, requireable.getStatus());
   test.ok(requireable.status === undefined);
   requireable.setStatus('42');
   test.is('42', requireable.getStatus());
   test.ok(requireable.status === undefined);
 
+  if (options.isUnamdized) {
+    test.log('Running unamdized, Reduced tests');
+    return;
+  }
+
   if (define.Domain) {
     var domain = new define.Domain();
     var requireable2 = domain.require('gclitest/requirable');
     test.is(undefined, requireable2.status);
     test.is('initial', requireable2.getStatus());
     requireable2.setStatus(999);
     test.is(999, requireable2.getStatus());
     test.is(undefined, requireable2.status);
--- a/browser/devtools/webconsole/gcli.jsm
+++ b/browser/devtools/webconsole/gcli.jsm
@@ -1593,16 +1593,23 @@ exports.findCssSelector = function(ele) 
  * Work out the path for images.
  */
 exports.createUrlLookup = function(callingModule) {
   return function imageUrl(path) {
     try {
       return require('text!gcli/ui/' + path);
     }
     catch (ex) {
+      // Under node/unamd callingModule is provided by node. This code isn't
+      // the right answer but it's enough to pass all the unit tests and get
+      // test coverage information, which is all we actually care about here.
+      if (callingModule.filename) {
+        return callingModule.filename + path;
+      }
+
       var filename = callingModule.id.split('/').pop() + '.js';
 
       if (callingModule.uri.substr(-filename.length) !== filename) {
         console.error('Can\'t work out path from module.uri/module.id');
         return path;
       }
 
       if (callingModule.uri) {
@@ -9467,17 +9474,18 @@ History.prototype.backward = function() 
   if (this._current < this._buffer.length - 1) {
     this._current++;
   }
   return this._buffer[this._current];
 };
 
 exports.History = History;
 
-});define("text!gcli/ui/inputter.css", [], "");
+});
+define("text!gcli/ui/inputter.css", [], "");
 
 /*
  * Copyright 2009-2011 Mozilla Foundation and contributors
  * Licensed under the New BSD license. See LICENSE.txt or:
  * http://opensource.org/licenses/BSD-3-Clause
  */
 
 define('gcli/ui/completer', ['require', 'exports', 'module' , 'gcli/util', 'gcli/ui/domtemplate', 'text!gcli/ui/completer.html'], function(require, exports, module) {