Bug 1289258 - Part 2 - Add mocha test for search. r=bgrins
authorLin Clark <lclark@mozilla.com>
Tue, 26 Jul 2016 12:35:42 -0400
changeset 352534 568a9228a15209e3db9970bb6e822050c8e8ce19
parent 352533 40f7b2bfa6d3d7694f2594969fdd7f76cad383ff
child 352535 4deee348d5147c7bb193fab4a25fcee8dfa238ae
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1289258
milestone51.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 1289258 - Part 2 - Add mocha test for search. r=bgrins MozReview-Commit-ID: RoAVWKb0qC
.gitignore
.hgignore
devtools/client/webconsole/.babelrc
devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
devtools/client/webconsole/new-console-output/store.js
devtools/client/webconsole/new-console-output/test/components/head.js
devtools/client/webconsole/new-console-output/test/fixtures/Services.js
devtools/client/webconsole/new-console-output/test/fixtures/moz.build
devtools/client/webconsole/new-console-output/test/fixtures/stubs.js
devtools/client/webconsole/new-console-output/test/moz.build
devtools/client/webconsole/new-console-output/test/store/filters.test.js
devtools/client/webconsole/new-console-output/test/store/head.js
devtools/client/webconsole/new-console-output/test/store/test_messages.js
devtools/client/webconsole/new-console-output/test/stubs.js
devtools/client/webconsole/new-console-output/test/utils/test_render_perf.html
devtools/client/webconsole/new-console-output/utils/messages.js
devtools/client/webconsole/package.json
--- a/.gitignore
+++ b/.gitignore
@@ -69,16 +69,19 @@ parser/html/java/javaparser/
 python/psutil/**/*.so
 python/psutil/**/*.pyd
 python/psutil/build/
 
 # Ignore chrome.manifest files from the devtools loader
 devtools/client/chrome.manifest
 devtools/shared/chrome.manifest
 
+# Ignore node_modules directories in devtools
+devtools/client/**/node_modules
+
 # Tag files generated by GNU Global
 GTAGS
 GRTAGS
 GSYMS
 GPATH
 
 # Git clone directory for updating web-platform-tests
 testing/web-platform/sync/
--- a/.hgignore
+++ b/.hgignore
@@ -73,16 +73,19 @@
 
 # Git repositories
 .git/
 
 # Ignore chrome.manifest files from the devtools loader
 ^devtools/client/chrome.manifest$
 ^devtools/shared/chrome.manifest$
 
+# Ignore node_modules directories in devtools
+^devtools/client/.*/node_modules/
+
 # git checkout of libstagefright
 ^media/libstagefright/android$
 
 # Tag files generated by GNU Global
 GTAGS
 GRTAGS
 GSYMS
 GPATH
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/.babelrc
@@ -0,0 +1,3 @@
+{
+  "presets": ["es2015"]
+}
\ No newline at end of file
--- a/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
+++ b/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
@@ -4,27 +4,29 @@
 "use strict";
 
 // React & Redux
 const React = require("devtools/client/shared/vendor/react");
 const ReactDOM = require("devtools/client/shared/vendor/react-dom");
 const { Provider } = require("devtools/client/shared/vendor/react-redux");
 
 const actions = require("devtools/client/webconsole/new-console-output/actions/messages");
-const { store } = require("devtools/client/webconsole/new-console-output/store");
+const { configureStore } = require("devtools/client/webconsole/new-console-output/store");
 
 const ConsoleOutput = React.createFactory(require("devtools/client/webconsole/new-console-output/components/console-output"));
 const FilterBar = React.createFactory(require("devtools/client/webconsole/new-console-output/components/filter-bar"));
 
+const store = configureStore();
+
 function NewConsoleOutputWrapper(parentNode, jsterm) {
   let childComponent = ConsoleOutput({ jsterm });
   let filterBar = FilterBar({});
   let provider = React.createElement(
     Provider,
-    { store: store },
+    { store },
     React.DOM.div(
       {className: "webconsole-output-wrapper"},
       filterBar,
       childComponent
   ));
   this.body = ReactDOM.render(provider, parentNode);
 }
 
--- a/devtools/client/webconsole/new-console-output/store.js
+++ b/devtools/client/webconsole/new-console-output/store.js
@@ -1,34 +1,35 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
-const Services = require("Services");
 const {FilterState} = require("devtools/client/webconsole/new-console-output/reducers/filters");
 const {PrefState} = require("devtools/client/webconsole/new-console-output/reducers/prefs");
 const { combineReducers, createStore } = require("devtools/client/shared/vendor/redux");
 const { reducers } = require("./reducers/index");
 
-function storeFactory() {
+function configureStore(Services) {
+  if (!Services) {
+    Services = require("Services");
+  }
+
   const initialState = {
     prefs: new PrefState({
       logLimit: Math.max(Services.prefs.getIntPref("devtools.hud.loglimit"), 1),
     }),
     filters: new FilterState({
       error: Services.prefs.getBoolPref("devtools.webconsole.filter.error"),
       warn: Services.prefs.getBoolPref("devtools.webconsole.filter.warn"),
       info: Services.prefs.getBoolPref("devtools.webconsole.filter.info"),
       log: Services.prefs.getBoolPref("devtools.webconsole.filter.log"),
       searchText: ""
     })
   };
 
   return createStore(combineReducers(reducers), initialState);
 }
 
-// Provide the single store instance for app code.
-module.exports.store = storeFactory();
 // Provide the store factory for test code so that each test is working with
 // its own instance.
-module.exports.storeFactory = storeFactory;
+module.exports.configureStore = configureStore;
 
--- a/devtools/client/webconsole/new-console-output/test/components/head.js
+++ b/devtools/client/webconsole/new-console-output/test/components/head.js
@@ -24,17 +24,17 @@ var { require: browserRequire } = Browse
   baseURI: "resource://devtools/client/webconsole/",
   window: this
 });
 
 let ReactDOM = browserRequire("devtools/client/shared/vendor/react-dom");
 let React = browserRequire("devtools/client/shared/vendor/react");
 var TestUtils = React.addons.TestUtils;
 
-const { stubConsoleMessages } = require("devtools/client/webconsole/new-console-output/test/stubs");
+const { stubConsoleMessages } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs");
 
 // @TODO Remove this.
 let testCommands = new Map();
 testCommands.set("console.log()", {
   command: "console.log('foobar', 'test')",
   commandType: "consoleAPICall",
   // @TODO should output: foobar test
   expectedText: "\"foobar\"\"test\""
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/fixtures/Services.js
@@ -0,0 +1,21 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+module.exports = {
+  prefs: {
+    getIntPref: pref => {
+      switch (pref) {
+        case "devtools.hud.loglimit":
+          return 1000;
+      }
+    },
+    getBoolPref: pref => {
+      switch (pref) {
+        default:
+          return true;
+      }
+    }
+  }
+};
copy from devtools/client/webconsole/new-console-output/test/moz.build
copy to devtools/client/webconsole/new-console-output/test/fixtures/moz.build
rename from devtools/client/webconsole/new-console-output/test/stubs.js
rename to devtools/client/webconsole/new-console-output/test/fixtures/stubs.js
--- a/devtools/client/webconsole/new-console-output/test/moz.build
+++ b/devtools/client/webconsole/new-console-output/test/moz.build
@@ -1,8 +1,9 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-DevToolsModules(
-    'stubs.js',
-)
+DIRS += [
+    'fixtures'
+]
+
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/new-console-output/test/store/filters.test.js
@@ -0,0 +1,39 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const expect = require("expect");
+
+const actions = require("devtools/client/webconsole/new-console-output/actions/messages");
+const { getAllMessages } = require("devtools/client/webconsole/new-console-output/selectors/messages");
+const { configureStore } = require("devtools/client/webconsole/new-console-output/store");
+const { stubConsoleMessages } = require("devtools/client/webconsole/new-console-output/test/fixtures/stubs");
+const Services = require("devtools/client/webconsole/new-console-output/test/fixtures/Services");
+
+describe("Search", () => {
+  it("matches on value grips", () => {
+    const store = setupStore([
+      "console.log('foobar', 'test')",
+      "console.warn('danger, will robinson!')",
+      "console.log(undefined)"
+    ]);
+    store.dispatch(actions.messagesSearch("danger"));
+
+    let messages = getAllMessages(store.getState());
+    expect(messages.size).toEqual(1);
+  });
+});
+
+function setupStore(input) {
+  const store = configureStore(Services);
+  addMessages(input, store.dispatch);
+  return store;
+}
+
+function addMessages(input, dispatch) {
+  input.forEach((cmd) => {
+    dispatch(actions.messageAdd(stubConsoleMessages.get(cmd)));
+  });
+}
+
--- a/devtools/client/webconsole/new-console-output/test/store/head.js
+++ b/devtools/client/webconsole/new-console-output/test/store/head.js
@@ -1,26 +1,26 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
-/* exported storeFactory */
+/* exported configureStore */
 
 "use strict";
 
 var { utils: Cu } = Components;
 var { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
 const Services = require("Services");
 
 var DevToolsUtils = require("devtools/shared/DevToolsUtils");
 var flags = require("devtools/shared/flags");
 flags.testing = true;
 flags.wantLogging = true;
 flags.wantVerbose = false;
 
-const { storeFactory } = require("devtools/client/webconsole/new-console-output/store");
+const { configureStore } = require("devtools/client/webconsole/new-console-output/store");
 
 const testPackets = new Map();
 testPackets.set("console.log", {
   "from": "server1.conn4.child1/consoleActor2",
   "type": "consoleAPICall",
   "message": {
     "arguments": [
       "foobar",
--- a/devtools/client/webconsole/new-console-output/test/store/test_messages.js
+++ b/devtools/client/webconsole/new-console-output/test/store/test_messages.js
@@ -14,17 +14,17 @@ const { getAllMessages } = require("devt
 function run_test() {
   run_next_test();
 }
 
 /**
  * Test adding a message to the store.
  */
 add_task(function* () {
-  const { getState, dispatch } = storeFactory();
+  const { getState, dispatch } = configureStore();
 
   dispatch(actions.messageAdd(packet));
 
   const expectedMessage = prepareMessage(packet);
 
   const messages = getAllMessages(getState());
   equal(messages.size, 1, "We added exactly one message.")
 
@@ -34,17 +34,17 @@ add_task(function* () {
   deepEqual(message.remove('id'), expectedMessage.remove('id'),
       "MESSAGE_ADD action adds a message");
 });
 
 /**
  * Test repeating messages in the store.
  */
 add_task(function* () {
-  const { getState, dispatch } = storeFactory();
+  const { getState, dispatch } = configureStore();
 
   dispatch(actions.messageAdd(packet));
   dispatch(actions.messageAdd(packet));
   dispatch(actions.messageAdd(packet));
 
   const messages = getAllMessages(getState());
   equal(messages.size, 1,
     "Repeated messages don't increase message list size");
@@ -57,17 +57,17 @@ add_task(function* () {
   equal(getAllMessages(getState()).size, 2,
     "Non-repeated messages aren't clobbered");
 });
 
 /**
  * Test adding a console.clear message to the store.
  */
 add_task(function*() {
-  const { getState, dispatch } = storeFactory();
+  const { getState, dispatch } = configureStore();
 
   dispatch(actions.messageAdd(packet));
 
   let messages = getAllMessages(getState());
   equal(messages.size, 1,
     "MESSAGE_ADD action adds a message");
 
   dispatch(actions.messageAdd(clearPacket));
@@ -76,17 +76,17 @@ add_task(function*() {
   deepEqual(messages.first().remove('id'), prepareMessage(clearPacket).remove('id'),
     "console.clear clears existing messages and add a new one");
 });
 
 /**
  * Test message limit on the store.
  */
 add_task(function* () {
-  const { getState, dispatch } = storeFactory();
+  const { getState, dispatch } = configureStore();
   const logLimit = 1000;
   const messageNumber = logLimit + 1;
 
   let newPacket = Object.assign({}, packet);
   for (let i = 1; i <= messageNumber; i++) {
     newPacket.message.arguments = [i];
     dispatch(actions.messageAdd(newPacket));
   }
@@ -99,17 +99,17 @@ add_task(function* () {
 
 /**
  * Test message limit on the store with user set prefs.
  */
 add_task(function* () {
   const userSetLimit = 10;
   Services.prefs.setIntPref("devtools.hud.loglimit", userSetLimit);
 
-  const { getState, dispatch } = storeFactory();
+  const { getState, dispatch } = configureStore();
 
   let newPacket = Object.assign({}, packet);
   for (let i = 1; i <= userSetLimit + 1; i++) {
     newPacket.message.arguments = [i];
     dispatch(actions.messageAdd(newPacket));
   }
 
   let messages = getAllMessages(getState());
--- a/devtools/client/webconsole/new-console-output/test/utils/test_render_perf.html
+++ b/devtools/client/webconsole/new-console-output/test/utils/test_render_perf.html
@@ -52,21 +52,23 @@ function timeit(cb) {
     let start = performance.now();
     cb();
     let elapsed = performance.now() - start;
     resolve(elapsed / 1000);
   });
 }
 
 window.onload = Task.async(function* () {
-  const { store } = browserRequire("devtools/client/webconsole/new-console-output/store");
+  const { configureStore } = browserRequire("devtools/client/webconsole/new-console-output/store");
   const { messagesSearch, filtersClear } = browserRequire("devtools/client/webconsole/new-console-output/actions/messages");
   const NewConsoleOutputWrapper = browserRequire("devtools/client/webconsole/new-console-output/new-console-output-wrapper");
   const wrapper = new NewConsoleOutputWrapper(document.querySelector("#output"), {});
 
+  const store = configureStore();
+
   let time = yield timeit(() => {
     testPackets.forEach((message) => {
       wrapper.dispatchMessageAdd(message);
     });
   });
   info("took " + time + " seconds to render messages");
 
   time = yield timeit(() => {
--- a/devtools/client/webconsole/new-console-output/utils/messages.js
+++ b/devtools/client/webconsole/new-console-output/utils/messages.js
@@ -1,30 +1,36 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
+let l10n;
+try {
+  const WebConsoleUtils = require("devtools/shared/webconsole/utils").Utils;
+  const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
+  l10n = new WebConsoleUtils.L10n(STRINGS_URI);
+} catch (e) {
+  l10n = {};
+}
+
 const {
   MESSAGE_SOURCE,
   MESSAGE_TYPE,
   MESSAGE_LEVEL,
   // Legacy
   CATEGORY_JS,
   CATEGORY_OUTPUT,
   CATEGORY_WEBDEV,
   LEVELS,
   SEVERITY_LOG,
 } = require("../constants");
-const WebConsoleUtils = require("devtools/client/webconsole/utils").Utils;
-const STRINGS_URI = "chrome://devtools/locale/webconsole.properties";
-const l10n = new WebConsoleUtils.L10n(STRINGS_URI);
 const { ConsoleMessage } = require("../types");
 
 let messageId = 0;
 function getNextMessageId() {
   // Return the next message id, as a string.
   return "" + messageId++;
 }
 
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/package.json
@@ -0,0 +1,13 @@
+{
+  "name": "webconsole",
+  "version": "0.0.1",
+  "devDependencies": {
+    "babel-preset-es2015": "^6.6.0",
+    "babel-register": "^6.7.2",
+    "expect": "^1.16.0",
+    "mocha": "^2.5.3"
+  },
+  "scripts": {
+    "test": "NODE_PATH=`pwd`/../../../ mocha new-console-output/test/**/*.test.js --compilers js:babel-register"
+  }
+}