Skip to content

Commit

Permalink
Bug 1289258 - Part 2 - Add mocha test for search. r=bgrins
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: RoAVWKb0qC
  • Loading branch information
linclark committed Jul 26, 2016
1 parent 5ad8fb7 commit 42d9ffa
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ python/psutil/build/
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
Expand Down
3 changes: 3 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ _OPT\.OBJ/
^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$

Expand Down
3 changes: 3 additions & 0 deletions devtools/client/webconsole/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ 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,
Expand Down
11 changes: 6 additions & 5 deletions devtools/client/webconsole/new-console-output/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* 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),
Expand All @@ -26,9 +29,7 @@ function storeFactory() {
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;

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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',
)
7 changes: 4 additions & 3 deletions devtools/client/webconsole/new-console-output/test/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# 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'
]

Original file line number Diff line number Diff line change
@@ -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)));
});
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

/* exported storeFactory */
/* exported configureStore */

"use strict";

Expand All @@ -15,7 +15,7 @@ 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", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function run_test() {
* Test adding a message to the store.
*/
add_task(function* () {
const { getState, dispatch } = storeFactory();
const { getState, dispatch } = configureStore();

dispatch(actions.messageAdd(packet));

Expand All @@ -39,7 +39,7 @@ add_task(function* () {
* 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));
Expand All @@ -62,7 +62,7 @@ add_task(function* () {
* Test adding a console.clear message to the store.
*/
add_task(function*() {
const { getState, dispatch } = storeFactory();
const { getState, dispatch } = configureStore();

dispatch(actions.messageAdd(packet));

Expand All @@ -81,7 +81,7 @@ add_task(function*() {
* Test message limit on the store.
*/
add_task(function* () {
const { getState, dispatch } = storeFactory();
const { getState, dispatch } = configureStore();
const logLimit = 1000;
const messageNumber = logLimit + 1;

Expand All @@ -104,7 +104,7 @@ 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@
}

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);
Expand Down
12 changes: 9 additions & 3 deletions devtools/client/webconsole/new-console-output/utils/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

"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,
Expand All @@ -17,9 +26,6 @@ const {
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;
Expand Down
13 changes: 13 additions & 0 deletions devtools/client/webconsole/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 42d9ffa

Please sign in to comment.