summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/pause/frames/tests/getLibraryFromUrl.spec.js
blob: ff5be432851c00c120b48786958d2ce97a9e7bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* 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/>. */

import { getLibraryFromUrl } from "../getLibraryFromUrl";
import { makeMockFrameWithURL } from "../../../test-mockup";

describe("getLibraryFromUrl", () => {
  describe("When Preact is on the frame", () => {
    it("should return Preact and not React", () => {
      const frame = makeMockFrameWithURL(
        "https://cdnjs.cloudflare.com/ajax/libs/preact/8.2.5/preact.js"
      );
      expect(getLibraryFromUrl(frame)).toEqual("Preact");
    });
  });

  describe("When Vue is on the frame", () => {
    it("should return VueJS for different builds", () => {
      const buildTypeList = [
        "vue.js",
        "vue.common.js",
        "vue.esm.js",
        "vue.runtime.js",
        "vue.runtime.common.js",
        "vue.runtime.esm.js",
        "vue.min.js",
        "vue.runtime.min.js",
      ];

      buildTypeList.forEach(buildType => {
        const frame = makeMockFrameWithURL(
          `https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/${buildType}`
        );
        expect(getLibraryFromUrl(frame)).toEqual("VueJS");
      });
    });
  });

  describe("When React is in the URL", () => {
    it("should not return React if it is not part of the filename", () => {
      const notReactUrlList = [
        "https://react.js.com/test.js",
        "https://debugger-example.com/test.js",
        "https://debugger-react-example.com/test.js",
        "https://debugger-react-example.com/react/test.js",
        "https://debugger-example.com/react-contextmenu.js",
      ];
      notReactUrlList.forEach(notReactUrl => {
        const frame = makeMockFrameWithURL(notReactUrl);
        expect(getLibraryFromUrl(frame)).toBeNull();
      });
    });
    it("should return React if it is part of the filename", () => {
      const reactUrlList = [
        "https://debugger-example.com/react.js",
        "https://debugger-example.com/react.development.js",
        "https://debugger-example.com/react.production.min.js",
        "https://debugger-react-example.com/react.js",
        "https://debugger-react-example.com/react/react.js",
        "https://debugger-example.com/react-dom.js",
        "https://debugger-example.com/react-dom.development.js",
        "https://debugger-example.com/react-dom.production.min.js",
        "https://debugger-react-example.com/react-dom.js",
        "https://debugger-react-example.com/react/react-dom.js",
        "https://debugger-react-example.com/react-dom-dev.js",
        "/node_modules/react/test.js",
        "/node_modules/react-dev/test.js",
        "/node_modules/react-dom/test.js",
        "/node_modules/react-dom-dev/test.js",
      ];
      reactUrlList.forEach(reactUrl => {
        const frame = makeMockFrameWithURL(reactUrl);
        expect(getLibraryFromUrl(frame)).toEqual("React");
      });
    });
  });

  describe("When Angular is in the URL", () => {
    it("should return Angular for AngularJS (1.x)", () => {
      const frame = makeMockFrameWithURL(
        "https://cdnjs.cloudflare.com/ajax/libs/angular/angular.js"
      );
      expect(getLibraryFromUrl(frame)).toEqual("Angular");
    });

    it("should return Angular for Angular (2.x)", () => {
      const frame = makeMockFrameWithURL(
        "https://stackblitz.io/turbo_modules/@angular/core@7.2.4/bundles/core.umd.js"
      );
      expect(getLibraryFromUrl(frame)).toEqual("Angular");
    });

    it("should not return Angular for Angular components", () => {
      const frame = makeMockFrameWithURL(
        "https://firefox-devtools-angular-log.stackblitz.io/~/src/app/hello.component.ts"
      );
      expect(getLibraryFromUrl(frame)).toBeNull();
    });
  });

  describe("When zone.js is on the frame", () => {
    it("should not return Angular when no callstack", () => {
      const frame = makeMockFrameWithURL("/node_modules/zone/zone.js");
      expect(getLibraryFromUrl(frame)).toBeNull();
    });

    it("should not return Angular when stack without Angular frames", () => {
      const frame = makeMockFrameWithURL("/node_modules/zone/zone.js");
      const callstack = [frame];

      expect(getLibraryFromUrl(frame, callstack)).toBeNull();
    });

    it("should return Angular when stack with AngularJS (1.x) frames", () => {
      const frame = makeMockFrameWithURL("/node_modules/zone/zone.js");
      const callstack = [
        frame,
        makeMockFrameWithURL(
          "https://cdnjs.cloudflare.com/ajax/libs/angular/angular.js"
        ),
      ];

      expect(getLibraryFromUrl(frame, callstack)).toEqual("Angular");
    });
  });
});