Bug 1287958 - New console frontend: Add keys to messages. r=bgrins

--HG--
extra : rebase_source : c16e69da3e6c0a824316f3a97001d4b84efd1960
This commit is contained in:
Peter Elmers 2016-07-19 15:41:39 -07:00
Родитель 12b7603161
Коммит 6d74ac0231
5 изменённых файлов: 24 добавлений и 6 удалений

Просмотреть файл

@ -43,7 +43,7 @@ const ConsoleOutput = createClass({
render() {
let messageNodes = this.props.messages.map(function (message) {
return (
MessageContainer({ message })
MessageContainer({ message, key: message.id })
);
});
return (

Просмотреть файл

@ -23,6 +23,9 @@ add_task(function* () {
// Prepare message is tested independently.
message: prepareMessage(packet)
};
// Remove ID for deepEqual comparison.
action.message = action.message.remove('id');
expected.message = expected.message.remove('id');
deepEqual(action, expected,
"messageAdd action creator returns expected action object");
});

Просмотреть файл

@ -25,9 +25,14 @@ add_task(function* () {
const expectedMessage = prepareMessage(packet);
let messages = getAllMessages(getState());
deepEqual(messages.toArray(), [expectedMessage],
"MESSAGE_ADD action adds a message");
const messages = getAllMessages(getState());
equal(messages.size, 1, "We added exactly one message.")
const message = messages.first();
notEqual(message.id, expectedMessage.id, "ID should be unique.");
// Remove ID for deepEqual comparison.
deepEqual(message.remove('id'), expectedMessage.remove('id'),
"MESSAGE_ADD action adds a message");
});
/**
@ -82,7 +87,7 @@ add_task(function*() {
dispatch(actions.messageAdd(clearPacket));
messages = getAllMessages(getState());
deepEqual(messages.first(), prepareMessage(clearPacket),
deepEqual(messages.first().remove('id'), prepareMessage(clearPacket).remove('id'),
"console.clear clears existing messages and add a new one");
});

Просмотреть файл

@ -27,4 +27,5 @@ exports.ConsoleMessage = Immutable.Record({
repeatId: null,
category: "output",
severity: "log",
id: null,
});

Просмотреть файл

@ -22,6 +22,12 @@ 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++;
}
function prepareMessage(packet) {
// This packet is already in the expected packet structure. Simply return.
if (packet.source) {
@ -74,6 +80,7 @@ function transformPacket(packet) {
repeatId: getRepeatId(message),
category: CATEGORY_WEBDEV,
severity: level,
id: getNextMessageId(),
});
}
@ -93,6 +100,7 @@ function transformPacket(packet) {
repeatId: getRepeatId(pageError),
category: CATEGORY_JS,
severity: level,
id: getNextMessageId(),
});
}
@ -108,6 +116,7 @@ function transformPacket(packet) {
repeatId: getRepeatId(result),
category: CATEGORY_OUTPUT,
severity: SEVERITY_LOG,
id: getNextMessageId(),
});
}
}
@ -116,8 +125,8 @@ function transformPacket(packet) {
// Helpers
function getRepeatId(message) {
let clonedMessage = JSON.parse(JSON.stringify(message));
delete clonedMessage.id;
delete clonedMessage.timeStamp;
delete clonedMessage.uniqueID;
return JSON.stringify(clonedMessage);
}