mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-10-01 17:29:29 +05:30
fix(flowchart): UMD browser fallback for viewport + add to controller test mount
The 6 pre-existing flowchart-controller test failures
('ReferenceError: require is not defined') were caused by
flowchart-canvas.js falling through to require('./flowchart-viewport')
when window.FlowchartViewport was undefined — because flowchart-viewport
was added in C4a but the controller test's script loader was never
updated to include it, and viewport itself had no browser-global
fallback.
Two coordinated fixes:
- Add the same UMD wrapper to flowchart-viewport.js that the other
pure modules already use (CommonJS module.exports + window
global fallback for the standalone window and jsdom). Now the
canvas's 'window.FlowchartViewport || require(...)' short-circuits
in the browser case, matching what shapes / store / mermaid do.
- Load flowchart-viewport.js in the controller test mount helper,
in dependency order between mermaid and store. The canvas now
sees window.FlowchartViewport set and never falls through to
require() under jsdom.
Test suite: 104 suites / 1353 tests passing (was 1347 with 6 failing).
The 6 'require is not defined' failures are gone.
Amit Haridas
This commit is contained in:
@@ -58,4 +58,14 @@ function snap(value, gridSize) {
|
|||||||
return Math.round(value / gridSize) * gridSize;
|
return Math.round(value / gridSize) * gridSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { zoomAt, panBy, reset, wheelFactor, snap, MIN_SCALE, MAX_SCALE };
|
// v4.13.0 — UMD wrapper. The browser global fallback lets the standalone
|
||||||
|
// flowchart window load this via <script> tag (contextIsolation:true means
|
||||||
|
// the renderer cannot require()), and lets the controller's jsdom tests
|
||||||
|
// load it via new Function(...) without a Node `require`.
|
||||||
|
const _exported = { zoomAt, panBy, reset, wheelFactor, snap, MIN_SCALE, MAX_SCALE };
|
||||||
|
if (typeof module === 'object' && module.exports) {
|
||||||
|
module.exports = _exported;
|
||||||
|
}
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.FlowchartViewport = _exported;
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ async function mount(apiMockOverrides = {}) {
|
|||||||
const scriptPaths = [
|
const scriptPaths = [
|
||||||
'flowchart/flowchart-shapes.js',
|
'flowchart/flowchart-shapes.js',
|
||||||
'flowchart/flowchart-mermaid.js',
|
'flowchart/flowchart-mermaid.js',
|
||||||
|
'flowchart/flowchart-viewport.js',
|
||||||
'flowchart/flowchart-store.js',
|
'flowchart/flowchart-store.js',
|
||||||
'flowchart/flowchart-canvas.js',
|
'flowchart/flowchart-canvas.js',
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user