From 764ebb8616130798114eb1fa873c2cd888c03558 Mon Sep 17 00:00:00 2001 From: Tomer Ohana Date: Thu, 5 Oct 2017 19:47:50 +0300 Subject: [PATCH] Support framework frames for Preact (#4296) --- assets/images/Svg.js | 1 + assets/images/preact.svg | 9 +++++++++ src/utils/frame.js | 9 +++++++++ src/utils/tests/frame.spec.js | 21 ++++++++++++++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 assets/images/preact.svg diff --git a/assets/images/Svg.js b/assets/images/Svg.js index 0b99e414d8..47ea4e2549 100644 --- a/assets/images/Svg.js +++ b/assets/images/Svg.js @@ -28,6 +28,7 @@ const svg = { pause: require("./pause.svg"), "pause-exceptions": require("./pause-exceptions.svg"), plus: require("./plus.svg"), + preact: require("./preact.svg"), prettyPrint: require("./prettyPrint.svg"), react: require("./react.svg"), "regex-match": require("./regex-match.svg"), diff --git a/assets/images/preact.svg b/assets/images/preact.svg new file mode 100644 index 0000000000..dd2015dfe5 --- /dev/null +++ b/assets/images/preact.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/utils/frame.js b/src/utils/frame.js index 7a0c77b3df..546ac9be6b 100644 --- a/src/utils/frame.js +++ b/src/utils/frame.js @@ -83,6 +83,10 @@ function isDojo(frame) { return getFrameUrl(frame).match(/dojo/i); } +function isPreact(frame) { + return getFrameUrl(frame).match(/preact/i); +} + export function getLibraryFromUrl(frame: Frame) { // @TODO each of these fns calls getFrameUrl, just call it once // (assuming there's not more complex logic to identify a lib) @@ -95,6 +99,11 @@ export function getLibraryFromUrl(frame: Frame) { return "jQuery"; } + // Needs to remain before "react", otherwise "react" can also match "preact" + if (isPreact(frame)) { + return "Preact"; + } + if (isReact(frame)) { return "React"; } diff --git a/src/utils/tests/frame.spec.js b/src/utils/tests/frame.spec.js index e58b35dc19..8261477dc2 100644 --- a/src/utils/tests/frame.spec.js +++ b/src/utils/tests/frame.spec.js @@ -3,7 +3,8 @@ import { simplifyDisplayName, formatDisplayName, - formatCopyName + formatCopyName, + getLibraryFromUrl } from "../frame"; const cases = { @@ -99,4 +100,22 @@ describe("function names", () => { expect(formatCopyName(frame)).toEqual("child (todo-view.js#12)"); }); }); + + describe("getLibraryFromUrl", () => { + describe("When Preact is on the frame", () => { + it("should return Preact and not React", () => { + const frame = { + displayName: "name", + location: { + line: 12 + }, + source: { + url: "https://cdnjs.cloudflare.com/ajax/libs/preact/8.2.5/preact.js" + } + }; + + expect(getLibraryFromUrl(frame)).toEqual("Preact"); + }); + }); + }); });