From b06805c789dffad35fefd01a420aaf1d7e61f827 Mon Sep 17 00:00:00 2001 From: RickB Date: Tue, 19 Dec 2023 09:07:38 -0600 Subject: [PATCH] add prop to check instead of trying to delete, which fails in Jsdom 21+ --- src/init.js | 4 ++-- src/node/canvas.js | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/init.js b/src/init.js index 82ebf0cde3..7a4cf37414 100644 --- a/src/init.js +++ b/src/init.js @@ -30,5 +30,5 @@ // NOTE: We're not modifying the global `self` here. We receive its value passed // to the paper.js function scope, and this is the one that is modified here. self = self || require('./node/self.js'); -var window = self.window, - document = self.document; +var window = self.CANVAS_NOT_FOUND ? null : self.window; +var document = self.document; diff --git a/src/node/canvas.js b/src/node/canvas.js index ee325d7d03..5764569c5c 100644 --- a/src/node/canvas.js +++ b/src/node/canvas.js @@ -20,12 +20,11 @@ module.exports = function(self, requireName) { try { Canvas = require('canvas').Canvas; } catch(error) { - // Remove `self.window`, so we still have the global `self` reference, - // but no `window` object: + // Add/set CANVAS_NOT_FOUND=true: // - On the browser, this corresponds to a worker context. // - On Node.js, it basically means the canvas is missing or not working // which can be treated the same way. - delete self.window; + self.CANVAS_NOT_FOUND = true; // Check the required module's name to see if it contains canvas, and // only complain about its lack if the module requires it. if (/\bcanvas\b/.test(requireName)) {