devtools-reps
Advanced tools
Comparing version 0.16.0 to 0.17.0
{ | ||
"name": "devtools-reps", | ||
"version": "0.16.0", | ||
"version": "0.17.0", | ||
"description": "Devtools Reps", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -21,2 +21,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const IGNORED_SOURCE_URLS = ["debugger eval code"]; | ||
/** | ||
@@ -38,3 +40,7 @@ * This component represents a template for Function objects. | ||
let jumpToDefinitionButton; | ||
if (onViewSourceInDebugger && grip.location && grip.location.url) { | ||
if (onViewSourceInDebugger && | ||
grip.location && | ||
grip.location.url && | ||
!IGNORED_SOURCE_URLS.includes(grip.location.url) | ||
) { | ||
jumpToDefinitionButton = Svg("jump-definition", { | ||
@@ -41,0 +47,0 @@ element: "a", |
@@ -46,16 +46,33 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
let isEmpty = objectLength === 0; | ||
if (isEmpty) { | ||
items = []; | ||
} else { | ||
items = [span({ | ||
let ellipsis; | ||
if (!isEmpty) { | ||
ellipsis = span({ | ||
className: "more-ellipsis", | ||
title: "more…" | ||
}, "…")]; | ||
}, "…"); | ||
} | ||
let title; | ||
if (object.class != "Array") { | ||
title = object.class + " "; | ||
} | ||
brackets = needSpace(false); | ||
} else { | ||
let max = maxLengthMap.get(mode); | ||
items = arrayIterator(props, object, max); | ||
brackets = needSpace(items.length > 0); | ||
return ( | ||
span({ | ||
"data-link-actor-id": object.actor, | ||
className: "objectBox objectBox-array"}, | ||
title, | ||
span({ | ||
className: "arrayLeftBracket", | ||
}, brackets.left), | ||
ellipsis, | ||
span({ | ||
className: "arrayRightBracket", | ||
}, brackets.right) | ||
) | ||
); | ||
} | ||
let max = maxLengthMap.get(mode); | ||
items = arrayIterator(props, object, max); | ||
brackets = needSpace(items.length > 0); | ||
@@ -62,0 +79,0 @@ let title = getTitle(props, object); |
@@ -14,2 +14,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const String = require("./string").rep; | ||
const dom = require("react-dom-factories"); | ||
@@ -28,7 +30,10 @@ const { span } = dom; | ||
return ( | ||
span({ | ||
"data-link-actor-id": grip.actor, | ||
className: "objectBox objectBox-" + getType(grip) | ||
}, | ||
span({className: "objectPropValue"}, getDescription(grip)) | ||
span( | ||
{ | ||
"data-link-actor-id": grip.actor, | ||
className: "objectTitle objectBox objectBox-" + getType(grip) | ||
}, | ||
getType(grip), | ||
" ", | ||
getDescription(grip) | ||
) | ||
@@ -43,3 +48,5 @@ ); | ||
function getDescription(grip) { | ||
return "\"" + grip.preview.text + "\""; | ||
return String({ | ||
object: grip.preview.text, | ||
}); | ||
} | ||
@@ -46,0 +53,0 @@ |
@@ -90,4 +90,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const halfLimit = Math.ceil((cropLimit - ELLIPSIS.length) / 2); | ||
const startCropIndex = halfLimit; | ||
const endCropIndex = text.length - halfLimit; | ||
const startCropIndex = cropLimit ? halfLimit : null; | ||
const endCropIndex = cropLimit ? text.length - halfLimit : null; | ||
@@ -155,9 +155,13 @@ // As we walk through the tokens of the source string, we make sure to preserve | ||
* is in the parent string. | ||
* @param {Integer} startCropIndex: the index where the start of the crop should happen | ||
* in the parent string | ||
* @param {Integer} endCropIndex: the index where the end of the crop should happen | ||
* in the parent string | ||
* @param {Integer|null} startCropIndex: the index where the start of the crop should | ||
* happen in the parent string. | ||
* @param {Integer|null} endCropIndex: the index where the end of the crop should happen | ||
* in the parent string | ||
* @returns {String|null} The cropped substring, or null if the text is completly cropped. | ||
*/ | ||
function getCroppedString(text, offset = 0, startCropIndex, endCropIndex) { | ||
if (!startCropIndex) { | ||
return text; | ||
} | ||
const start = offset; | ||
@@ -164,0 +168,0 @@ const end = offset + text.length; |
@@ -155,2 +155,34 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
stubs.set("getRandom", { | ||
"type": "object", | ||
"actor": "server1.conn7.child1/obj984", | ||
"class": "Function", | ||
"extensible": true, | ||
"frozen": false, | ||
"sealed": false, | ||
"ownPropertyLength": 3, | ||
"name": "getRandom", | ||
"displayName": "getRandom", | ||
"location": { | ||
"url": "https://nchevobbe.github.io/demo/console-test-app.html", | ||
"line": 314 | ||
} | ||
}); | ||
stubs.set("EvaledInDebuggerFunction", { | ||
"type": "object", | ||
"actor": "server1.conn2.child1/obj29", | ||
"class": "Function", | ||
"extensible": true, | ||
"frozen": false, | ||
"sealed": false, | ||
"ownPropertyLength": 3, | ||
"name": "evaledInDebugger", | ||
"displayName": "evaledInDebugger", | ||
"location": { | ||
"url": "debugger eval code", | ||
"line": 1 | ||
} | ||
}); | ||
module.exports = stubs; |
@@ -24,2 +24,17 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
stubs.set("DOMTokenList", { | ||
"type": "object", | ||
"actor": "server2.conn4.child12/obj39", | ||
"class": "DOMTokenList", | ||
"extensible": true, | ||
"frozen": false, | ||
"sealed": false, | ||
"ownPropertyLength": 0, | ||
"preview": { | ||
"kind": "ArrayLike", | ||
"length": 0, | ||
"items": [] | ||
} | ||
}); | ||
stubs.set("testMaxProps", { | ||
@@ -26,0 +41,0 @@ "type": "object", |
@@ -6,3 +6,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const stubs = new Map(); | ||
stubs.set("ObjectWithText", { | ||
stubs.set("ShadowRule", { | ||
"type": "object", | ||
@@ -21,2 +21,17 @@ "class": "CSSStyleRule", | ||
stubs.set("CSSMediaRule", { | ||
"type": "object", | ||
"actor": "server2.conn8.child17/obj30", | ||
"class": "CSSMediaRule", | ||
"extensible": true, | ||
"frozen": false, | ||
"sealed": false, | ||
"ownPropertyLength": 0, | ||
"preview": { | ||
"kind": "ObjectWithText", | ||
"text": "(min-height: 680px), screen and (orientation: portrait)" | ||
} | ||
}); | ||
module.exports = stubs; |
@@ -242,3 +242,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const onViewSourceInDebugger = jest.fn(); | ||
const object = stubs.get("Named"); | ||
const object = stubs.get("getRandom"); | ||
const renderedComponent = renderRep(object, { | ||
@@ -260,3 +260,3 @@ onViewSourceInDebugger | ||
it("does not render an icon when onViewSourceInDebugger props is not provided", () => { | ||
const object = stubs.get("Named"); | ||
const object = stubs.get("getRandom"); | ||
const renderedComponent = renderRep(object); | ||
@@ -269,3 +269,3 @@ | ||
it("does not render an icon when the object has no location", () => { | ||
const object = Object.assign({}, stubs.get("Named")); | ||
const object = Object.assign({}, stubs.get("getRandom")); | ||
delete object.location; | ||
@@ -281,3 +281,3 @@ const renderedComponent = renderRep(object, { | ||
it("does not render an icon when the object has no url location", () => { | ||
const object = Object.assign({}, stubs.get("Named")); | ||
const object = Object.assign({}, stubs.get("getRandom")); | ||
object.location.url = null; | ||
@@ -291,2 +291,12 @@ const renderedComponent = renderRep(object, { | ||
}); | ||
it("does not render an icon when function was declared in console input", () => { | ||
const object = Object.assign({}, stubs.get("EvaledInDebuggerFunction")); | ||
const renderedComponent = renderRep(object, { | ||
onViewSourceInDebugger: () => {} | ||
}); | ||
const node = renderedComponent.find(".jump-definition"); | ||
expect(node.exists()).toBeFalsy(); | ||
}); | ||
}); | ||
@@ -293,0 +303,0 @@ |
@@ -273,3 +273,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput); | ||
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]"); | ||
expect(renderRep({ mode: MODE.TINY }).text()).toBe("NamedNodeMap […]"); | ||
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput); | ||
@@ -290,3 +290,3 @@ expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput); | ||
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput); | ||
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]"); | ||
expect(renderRep({ mode: MODE.TINY }).text()).toBe("NodeList […]"); | ||
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput); | ||
@@ -364,3 +364,3 @@ expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput); | ||
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput); | ||
expect(renderRep({ mode: MODE.TINY }).text()).toBe("[…]"); | ||
expect(renderRep({ mode: MODE.TINY }).text()).toBe("DocumentFragment […]"); | ||
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput); | ||
@@ -418,3 +418,3 @@ expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput); | ||
// See LINKTOGITHUBISSUE | ||
expect(component.text()).toBe("[…]"); | ||
expect(component.text()).toBe("Set […]"); | ||
expectActorAttribute(component, object.actor); | ||
@@ -443,3 +443,3 @@ | ||
// See LINKTOGITHUBISSUE | ||
expect(component.text()).toBe("[…]"); | ||
expect(component.text()).toBe("Set […]"); | ||
expectActorAttribute(component, object.actor); | ||
@@ -478,3 +478,3 @@ | ||
// See LINKTOGITHUBISSUE | ||
expect(component.text()).toBe("[…]"); | ||
expect(component.text()).toBe("WeakSet […]"); | ||
expectActorAttribute(component, object.actor); | ||
@@ -503,3 +503,3 @@ | ||
// See LINKTOGITHUBISSUE | ||
expect(component.text()).toBe("[…]"); | ||
expect(component.text()).toBe("WeakSet […]"); | ||
expectActorAttribute(component, object.actor); | ||
@@ -516,1 +516,30 @@ | ||
}); | ||
describe("GripArray - DOMTokenList", () => { | ||
const object = stubs.get("DOMTokenList"); | ||
it("correctly selects GripArray Rep", () => { | ||
expect(getRep(object)).toBe(GripArray.rep); | ||
}); | ||
it("renders as expected", () => { | ||
const renderRep = (props) => shallowRenderRep(object, props); | ||
const defaultOutput = "DOMTokenList []"; | ||
let component = renderRep({ mode: undefined }); | ||
expect(component.text()).toBe(defaultOutput); | ||
expectActorAttribute(component, object.actor); | ||
component = renderRep({ mode: MODE.TINY }); | ||
expect(component.text()).toBe("DOMTokenList []"); | ||
expectActorAttribute(component, object.actor); | ||
component = renderRep({ mode: MODE.SHORT }); | ||
expect(component.text()).toBe(defaultOutput); | ||
expectActorAttribute(component, object.actor); | ||
component = renderRep({ mode: MODE.LONG }); | ||
expect(component.text()).toBe(defaultOutput); | ||
expectActorAttribute(component, object.actor); | ||
}); | ||
}); |
@@ -190,3 +190,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
"onerror: null, onnoupdate: null, ondownloading: null, onprogress: null, " + | ||
"onupdateready: null, oncached: null, onobsolete: null, mozItems: [] }"; | ||
"onupdateready: null, oncached: null, onobsolete: null, " + | ||
"mozItems: DOMStringList [] }"; | ||
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput); | ||
@@ -193,0 +194,0 @@ }); |
@@ -18,4 +18,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
describe("Object with text", () => { | ||
const gripStub = stubs.get("ObjectWithText"); | ||
describe("Object with text - CSSStyleRule", () => { | ||
const gripStub = stubs.get("ShadowRule"); | ||
@@ -33,5 +33,26 @@ // Test that correct rep is chosen | ||
expect(renderedComponent.text()).toEqual("\".Shadow\""); | ||
expect(renderedComponent.text()).toEqual("CSSStyleRule \".Shadow\""); | ||
expectActorAttribute(renderedComponent, gripStub.actor); | ||
}); | ||
}); | ||
describe("Object with text - CSSMediaRule", () => { | ||
const gripStub = stubs.get("CSSMediaRule"); | ||
// Test that correct rep is chosen | ||
it("selects ObjectsWithText Rep", () => { | ||
expect(getRep(gripStub)).toEqual(ObjectWithText.rep); | ||
}); | ||
// Test rendering | ||
it("renders with the correct text content", () => { | ||
const renderedComponent = shallow(Rep({ | ||
object: gripStub | ||
})); | ||
const text = `CSSMediaRule "(min-height: 680px), screen and (orientation: portrait)"`; | ||
expect(renderedComponent.text()).toEqual(text); | ||
expectActorAttribute(renderedComponent, gripStub.actor); | ||
}); | ||
}); | ||
@@ -256,3 +256,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const stubs = require("../stubs/object-with-text"); | ||
expect(getRep(stubs.get("ObjectWithText"), undefined, true)).toBe(Obj.rep); | ||
expect(getRep(stubs.get("ShadowRule"), undefined, true)).toBe(Obj.rep); | ||
}); | ||
@@ -259,0 +259,0 @@ |
@@ -205,2 +205,22 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
it("renders URL on an open string", () => { | ||
const url = "http://example.com"; | ||
const openLink = jest.fn(); | ||
const element = renderRep(url, { | ||
openLink, | ||
useQuotes: false, | ||
member: { | ||
open: true | ||
} | ||
}); | ||
expect(element.text()).toEqual(url); | ||
const link = element.find("a"); | ||
expect(link.prop("href")).toBe(url); | ||
expect(link.prop("title")).toBe(url); | ||
link.simulate("click"); | ||
expect(openLink).toBeCalledWith(url); | ||
}); | ||
it("renders URLs with a stripped string between", () => { | ||
@@ -207,0 +227,0 @@ const text = "- http://example.fr --- http://example.us -"; |
1095287
18242