summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/test/tests-setup.js
blob: c376f51d00497b4f8c99386a48308c582890512a (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
/* 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/index";
import { ParserDispatcher } from "../workers/parser";
import { SearchDispatcher } from "../workers/search/index";

import { clearDocuments } from "../utils/editor/index";

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 () => {
  clearDocuments();
  prefs.projectDirectoryRoot = "";
  prefs.projectDirectoryRootName = "";
  prefs.expressions = [];

  // Ensures window.dbg is there to track telemetry
  setupHelper({ selectors: {} });
});