All files / lib jsdom-canvas-setup.ts

68.75% Statements 11/16
0% Branches 0/2
100% Functions 0/0
68.75% Lines 11/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  1x 1x   1x 1x 1x   1x 1x 1x 1x 1x       1x        
/* eslint-disable no-console */
import { JSDOM } from 'jsdom';
import { Canvas } from 'canvas'; // You can use node-canvas for most complete server-side canvas
 
if (globalThis.process?.release?.name) {
  console.log('We are running in NodeJS');
  const dom = new JSDOM(`<!DOCTYPE html>`);
 
  globalThis.window = dom.window;
  globalThis.document = dom.window.document;
  globalThis.XMLSerializer = dom.window.XMLSerializer;
  globalThis.self = dom.window.self;
  if (!globalThis.navigator) {
    globalThis.navigator = dom.window.navigator;
  }
 
  globalThis.window.HTMLCanvasElement = Canvas as any; // You can use node-canvas for most complete server-side canvas
} else {
  console.log('Unknown runtime!');
}