workers.ts 875 B

123456789101112131415161718192021222324252627282930313233
  1. const { layout } = jest.requireActual('../../app/plugins/panel/nodeGraph/layout.worker.js');
  2. class LayoutMockWorker {
  3. timeout: number | undefined;
  4. constructor() {}
  5. postMessage(data: any) {
  6. const { nodes, edges, config } = data;
  7. this.timeout = setTimeout(() => {
  8. this.timeout = undefined;
  9. layout(nodes, edges, config);
  10. // @ts-ignore
  11. this.onmessage({ data: { nodes, edges } });
  12. }, 1) as any;
  13. }
  14. terminate() {
  15. if (this.timeout) {
  16. clearTimeout(this.timeout);
  17. }
  18. }
  19. }
  20. jest.mock('../../app/plugins/panel/nodeGraph/createLayoutWorker', () => ({
  21. createWorker: () => new LayoutMockWorker(),
  22. }));
  23. class BasicMockWorker {
  24. postMessage() {}
  25. }
  26. const mockCreateWorker = {
  27. createWorker: () => new BasicMockWorker(),
  28. };
  29. jest.mock('../../app/features/live/centrifuge/createCentrifugeServiceWorker', () => mockCreateWorker);