diff --git a/js/widgets/__tests__/oscilloscope.test.js b/js/widgets/__tests__/oscilloscope.test.js index 7118166555..453aca9072 100644 --- a/js/widgets/__tests__/oscilloscope.test.js +++ b/js/widgets/__tests__/oscilloscope.test.js @@ -80,11 +80,7 @@ function createMockWidgetWindow() { }; } -// Load the Oscilloscope class by reading the source and wrapping it -// so the class is assigned to global (class declarations are block-scoped) -const fs = require("fs"); -const path = require("path"); -const oscilloscopeSource = fs.readFileSync(path.resolve(__dirname, "../oscilloscope.js"), "utf-8"); +const Oscilloscope = require("../oscilloscope.js"); let mockWidgetWindow; @@ -96,10 +92,6 @@ window.widgetWindows = { windowFor: jest.fn(() => mockWidgetWindow) }; -// Wrap source: execute the class definition and assign to global -const wrappedSource = oscilloscopeSource + "\nglobal.Oscilloscope = Oscilloscope;\n"; -new Function(wrappedSource)(); - beforeEach(() => { mockWidgetWindow = createMockWidgetWindow(); diff --git a/js/widgets/oscilloscope.js b/js/widgets/oscilloscope.js index 3e3299b48c..94c1827faa 100644 --- a/js/widgets/oscilloscope.js +++ b/js/widgets/oscilloscope.js @@ -326,3 +326,7 @@ class Oscilloscope { } } } + +if (typeof module !== "undefined") { + module.exports = Oscilloscope; +}