From 079eed2b9eb8f0150e046a6c6d292f7611b1143e Mon Sep 17 00:00:00 2001 From: Kia Lam Date: Tue, 8 Mar 2022 10:13:47 -0800 Subject: [PATCH] Mock web worker. --- awx/ui/src/App.test.js | 1 + awx/ui/src/index.test.js | 1 + awx/ui/src/routeConfig.test.js | 1 + awx/ui/src/screens/TopologyView/MeshGraph.js | 6 ++---- awx/ui/src/screens/TopologyView/utils/webWorker.js | 3 +++ 5 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 awx/ui/src/screens/TopologyView/utils/webWorker.js diff --git a/awx/ui/src/App.test.js b/awx/ui/src/App.test.js index de080062fd..bdc71de49f 100644 --- a/awx/ui/src/App.test.js +++ b/awx/ui/src/App.test.js @@ -7,6 +7,7 @@ import { mountWithContexts } from '../testUtils/enzymeHelpers'; import App, { ProtectedRoute } from './App'; jest.mock('./api'); +jest.mock('screens/TopologyView/utils/WebWorker', () => jest.fn()); describe('', () => { beforeEach(() => { diff --git a/awx/ui/src/index.test.js b/awx/ui/src/index.test.js index 49ae9e2317..ffde7d7d9c 100644 --- a/awx/ui/src/index.test.js +++ b/awx/ui/src/index.test.js @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom'; import App from './App'; jest.mock('react-dom', () => ({ render: jest.fn() })); +jest.mock('screens/TopologyView/utils/WebWorker', () => jest.fn()); describe('index.jsx', () => { it('renders ok', () => { diff --git a/awx/ui/src/routeConfig.test.js b/awx/ui/src/routeConfig.test.js index 35e0a5eae3..643bd13dfd 100644 --- a/awx/ui/src/routeConfig.test.js +++ b/awx/ui/src/routeConfig.test.js @@ -1,4 +1,5 @@ import getRouteConfig from './routeConfig'; +jest.mock('screens/TopologyView/utils/WebWorker', () => jest.fn()); const userProfile = { isSuperUser: false, diff --git a/awx/ui/src/screens/TopologyView/MeshGraph.js b/awx/ui/src/screens/TopologyView/MeshGraph.js index a88f5d6dc4..d643044e68 100644 --- a/awx/ui/src/screens/TopologyView/MeshGraph.js +++ b/awx/ui/src/screens/TopologyView/MeshGraph.js @@ -17,6 +17,7 @@ import { // generateRandomNodes, // getRandomInt, } from './utils/helpers'; +import webWorker from './utils/webWorker'; import { DEFAULT_RADIUS, DEFAULT_NODE_COLOR, @@ -59,10 +60,7 @@ function MeshGraph({ data, showLegend, zoom, setShowZoomControls }) { const graph = data; /* WEB WORKER */ - const worker = new Worker( - new URL('./utils/workers/simulationWorker.js', import.meta.url) - ); - + const worker = webWorker(); worker.postMessage({ nodes: graph.nodes, links: graph.links, diff --git a/awx/ui/src/screens/TopologyView/utils/webWorker.js b/awx/ui/src/screens/TopologyView/utils/webWorker.js new file mode 100644 index 0000000000..7cc564b1c5 --- /dev/null +++ b/awx/ui/src/screens/TopologyView/utils/webWorker.js @@ -0,0 +1,3 @@ +export default function webWorker() { + return new Worker(new URL('./workers/simulationWorker.js', import.meta.url)); +}