Source code

Revision control

Copy as Markdown

Other Tools

/* 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(
);
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(
);
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 = [
];
notReactUrlList.forEach(notReactUrl => {
const frame = makeMockFrameWithURL(notReactUrl);
expect(getLibraryFromUrl(frame)).toBeNull();
});
});
it("should return React if it is part of the filename", () => {
const reactUrlList = [
"/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(
);
expect(getLibraryFromUrl(frame)).toEqual("Angular");
});
it("should return Angular for Angular (2.x)", () => {
const frame = makeMockFrameWithURL(
);
expect(getLibraryFromUrl(frame)).toEqual("Angular");
});
it("should not return Angular for Angular components", () => {
const frame = makeMockFrameWithURL(
);
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(
),
];
expect(getLibraryFromUrl(frame, callstack)).toEqual("Angular");
});
});
});