Skip to content

Commit 2dee717

Browse files
Fix module export for oscilloscope.js to enable proper Jest coverage (#5956)
1 parent 172113e commit 2dee717

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

js/widgets/__tests__/oscilloscope.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ function createMockWidgetWindow() {
8888
};
8989
}
9090

91-
// Load the Oscilloscope class by reading the source and wrapping it
92-
// so the class is assigned to global (class declarations are block-scoped)
93-
const fs = require("fs");
94-
const path = require("path");
95-
const oscilloscopeSource = fs.readFileSync(path.resolve(__dirname, "../oscilloscope.js"), "utf-8");
91+
const Oscilloscope = require("../oscilloscope.js");
9692

9793
let mockWidgetWindow;
9894

@@ -104,10 +100,6 @@ window.widgetWindows = {
104100
windowFor: jest.fn(() => mockWidgetWindow)
105101
};
106102

107-
// Wrap source: execute the class definition and assign to global
108-
const wrappedSource = oscilloscopeSource + "\nglobal.Oscilloscope = Oscilloscope;\n";
109-
new Function(wrappedSource)();
110-
111103
beforeEach(() => {
112104
mockWidgetWindow = createMockWidgetWindow();
113105

js/widgets/oscilloscope.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,7 @@ class Oscilloscope {
327327
}
328328
}
329329
}
330+
331+
if (typeof module !== "undefined") {
332+
module.exports = Oscilloscope;
333+
}

0 commit comments

Comments
 (0)