summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/debugger/src/test
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/src/test')
-rw-r--r--devtools/client/debugger/src/test/__mocks__/request-animation-frame.js8
-rw-r--r--devtools/client/debugger/src/test/fixtures/README.md3
-rw-r--r--devtools/client/debugger/src/test/fixtures/foobar.json56
-rw-r--r--devtools/client/debugger/src/test/fixtures/index.js3
-rw-r--r--devtools/client/debugger/src/test/shim.js31
-rw-r--r--devtools/client/debugger/src/test/tests-setup.js63
6 files changed, 164 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/test/__mocks__/request-animation-frame.js b/devtools/client/debugger/src/test/__mocks__/request-animation-frame.js
new file mode 100644
index 0000000000..d4441616ef
--- /dev/null
+++ b/devtools/client/debugger/src/test/__mocks__/request-animation-frame.js
@@ -0,0 +1,8 @@
+/* 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/>. */
+
+global.requestAnimationFrame = function (cb) {
+ cb();
+ return null;
+};
diff --git a/devtools/client/debugger/src/test/fixtures/README.md b/devtools/client/debugger/src/test/fixtures/README.md
new file mode 100644
index 0000000000..ea907643e3
--- /dev/null
+++ b/devtools/client/debugger/src/test/fixtures/README.md
@@ -0,0 +1,3 @@
+## Fixtures
+
+Fixtures used for unit tests
diff --git a/devtools/client/debugger/src/test/fixtures/foobar.json b/devtools/client/debugger/src/test/fixtures/foobar.json
new file mode 100644
index 0000000000..f225bf1f7a
--- /dev/null
+++ b/devtools/client/debugger/src/test/fixtures/foobar.json
@@ -0,0 +1,56 @@
+{
+ "sources": {
+ "sources": {
+ "fooSourceActor": {
+ "id": "fooSourceActor",
+ "url": "http://example.com/foo/foo.js",
+ "filename": "foo.js",
+ "pathname": "foo/foo.js"
+ },
+ "barSourceActor": {
+ "id": "barSourceActor",
+ "url": "http://example.com/bar/bar.js",
+ "filename": "bar.js",
+ "pathname": "bar/bar.js"
+ },
+ "bazzSourceActor": {
+ "id": "bazzSourceActor",
+ "url": "http://example.com/bazz/bazz.js",
+ "filename": "bazz.js",
+ "pathname": "bazz/bazz.js"
+ }
+ },
+ "sourcesText": {
+ "fooSourceActor": {
+ "contentType": "text/javascript",
+ "text": "function() {\n return foo;\n}"
+ },
+ "barSourceActor": {
+ "contentType": "text/javascript",
+ "text": "function() {\n return bar;\n}"
+ },
+ "bazzSourceActor": {
+ "contentType": "text/javascript",
+ "text": "function() {\n return bazz;\n}"
+ }
+ }
+ },
+ "breakpoints": {
+ "breakpoints": {
+ "fooBreakpointActor": {
+ "id": "fooBreakpointActor",
+ "location": {
+ "sourceId": "fooSourceActor",
+ "line": 16
+ }
+ },
+ "barBreakpointActor": {
+ "id": "barBreakpointActor",
+ "location": {
+ "sourceId": "barSourceActor",
+ "line": 18
+ }
+ }
+ }
+ }
+}
diff --git a/devtools/client/debugger/src/test/fixtures/index.js b/devtools/client/debugger/src/test/fixtures/index.js
new file mode 100644
index 0000000000..a0efc568b0
--- /dev/null
+++ b/devtools/client/debugger/src/test/fixtures/index.js
@@ -0,0 +1,3 @@
+import foobarJson from "./foobar.json";
+
+export const foobar = foobarJson;
diff --git a/devtools/client/debugger/src/test/shim.js b/devtools/client/debugger/src/test/shim.js
new file mode 100644
index 0000000000..d1ac2f549f
--- /dev/null
+++ b/devtools/client/debugger/src/test/shim.js
@@ -0,0 +1,31 @@
+/* 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/>. */
+
+const {
+ setMocksInGlobal,
+} = require("devtools/client/shared/test-helpers/shared-node-helpers");
+setMocksInGlobal();
+
+const { LocalizationHelper } = require("devtools/shared/l10n");
+global.L10N = new LocalizationHelper(
+ "devtools/client/locales/debugger.properties"
+);
+
+const { URL } = require("url");
+global.URL = URL;
+
+// JSDOM doesn't seem to have those functions that are used by codeMirror.
+// See https://github.com/jsdom/jsdom/issues/3002
+document.createRange = () => {
+ const range = new Range();
+
+ range.getBoundingClientRect = jest.fn();
+
+ range.getClientRects = jest.fn(() => ({
+ item: () => null,
+ length: 0,
+ }));
+
+ return range;
+};
diff --git a/devtools/client/debugger/src/test/tests-setup.js b/devtools/client/debugger/src/test/tests-setup.js
new file mode 100644
index 0000000000..ad9beecd49
--- /dev/null
+++ b/devtools/client/debugger/src/test/tests-setup.js
@@ -0,0 +1,63 @@
+/* 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/>. */
+
+global.Worker = require("workerjs");
+
+import path from "path";
+import Enzyme from "enzyme";
+import Adapter from "enzyme-adapter-react-16";
+import { setupHelper } from "../utils/dbg";
+import { prefs } from "../utils/prefs";
+
+import { PrettyPrintDispatcher } from "../workers/pretty-print";
+import { ParserDispatcher } from "../workers/parser";
+import { SearchDispatcher } from "../workers/search";
+
+import { clearDocuments } from "../utils/editor";
+
+const rootPath = path.join(__dirname, "../../");
+
+Enzyme.configure({ adapter: new Adapter() });
+
+jest.setTimeout(20000);
+
+function formatException(reason, p) {
+ console && console.log("Unhandled Rejection at:", p, "reason:", reason);
+}
+
+export const parserWorker = new ParserDispatcher(
+ path.join(rootPath, "src/workers/parser/worker.js")
+);
+export const prettyPrintWorker = new PrettyPrintDispatcher(
+ path.join(rootPath, "src/workers/pretty-print/worker.js")
+);
+export const searchWorker = new SearchDispatcher(
+ path.join(rootPath, "src/workers/search/worker.js")
+);
+
+beforeAll(() => {
+ process.on("unhandledRejection", formatException);
+});
+
+afterAll(() => {
+ parserWorker.stop();
+ prettyPrintWorker.stop();
+ searchWorker.stop();
+
+ process.removeListener("unhandledRejection", formatException);
+});
+
+afterEach(() => {});
+
+beforeEach(async () => {
+ parserWorker.clear();
+
+ clearDocuments();
+ prefs.projectDirectoryRoot = "";
+ prefs.projectDirectoryRootName = "";
+ prefs.expressions = [];
+
+ // Ensures window.dbg is there to track telemetry
+ setupHelper({ selectors: {} });
+});