Skip to content

Commit e9d89c7

Browse files
committed
Fix module export for oscilloscope.js to enable proper Jest coverage
1 parent f488f0b commit e9d89c7

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

js/widgets/__tests__/oscilloscope.test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ function createMockWidgetWindow() {
8080
};
8181
}
8282

83-
// Load the Oscilloscope class by reading the source and wrapping it
84-
// so the class is assigned to global (class declarations are block-scoped)
85-
const fs = require("fs");
86-
const path = require("path");
87-
const oscilloscopeSource = fs.readFileSync(path.resolve(__dirname, "../oscilloscope.js"), "utf-8");
83+
const Oscilloscope = require("../oscilloscope.js");
8884

8985
let mockWidgetWindow;
9086

@@ -96,10 +92,6 @@ window.widgetWindows = {
9692
windowFor: jest.fn(() => mockWidgetWindow)
9793
};
9894

99-
// Wrap source: execute the class definition and assign to global
100-
const wrappedSource = oscilloscopeSource + "\nglobal.Oscilloscope = Oscilloscope;\n";
101-
new Function(wrappedSource)();
102-
10395
beforeEach(() => {
10496
mockWidgetWindow = createMockWidgetWindow();
10597

js/widgets/oscilloscope.js

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

0 commit comments

Comments
 (0)