refactor: optimize memory usage during testing (#5745)

* refactor(registry): register same object won't log error

* chore: set --max-old-space-size to 1024

* refactor: adjust demo export
This commit is contained in:
Aaron 2024-05-16 16:34:27 +08:00 committed by GitHub
parent 2109e25895
commit e907819be0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 118 additions and 119 deletions

View File

@ -1,111 +1,111 @@
export * from './animation-element-edge-cubic';
export * from './animation-element-edge-line';
export * from './animation-element-edge-quadratic';
export * from './animation-element-position';
export * from './animation-element-state';
export * from './animation-element-state-switch';
export * from './animation-element-style-position';
export * from './behavior-brush-select';
export * from './behavior-click-element';
export * from './behavior-create-edge';
export * from './behavior-drag-canvas';
export * from './behavior-drag-element';
export * from './behavior-focus-element';
export * from './behavior-hover-element';
export * from './behavior-lasso-select';
export * from './behavior-scroll-canvas';
export * from './behavior-zoom-canvas';
export * from './combo';
export * from './combo-expand-collapse';
export * from './common-graph';
export * from './controller-viewport';
export * from './element-change-type';
export * from './element-edge-arrow';
export * from './element-edge-cubic';
export * from './element-edge-cubic-horizontal';
export * from './element-edge-cubic-vertical';
export * from './element-edge-custom-arrow';
export * from './element-edge-line';
export * from './element-edge-loop-curve';
export * from './element-edge-loop-polyline';
export * from './element-edge-polyline';
export * from './element-edge-polyline-animation';
export * from './element-edge-port';
export * from './element-edge-quadratic';
export * from './element-label-background';
export * from './element-label-oversized';
export * from './element-node-badges';
export * from './element-node-circle';
export * from './element-node-diamond';
export * from './element-node-donut';
export * from './element-node-ellipse';
export * from './element-node-hexagon';
export * from './element-node-html';
export * from './element-node-image';
export * from './element-node-rect';
export * from './element-node-star';
export * from './element-node-svg-icon';
export * from './element-node-triangle';
export * from './element-port';
export * from './element-position';
export * from './element-position-combo';
export * from './element-state';
export * from './element-visibility';
export * from './element-z-index';
export * from './graph-to-data-url';
export * from './layout-antv-dagre-flow';
export * from './layout-antv-dagre-flow-combo';
export * from './layout-circular-basic';
export * from './layout-circular-configuration-translate';
export * from './layout-circular-degree';
export * from './layout-circular-division';
export * from './layout-circular-spiral';
export * from './layout-combo-combined';
export * from './layout-compact-box-basic';
export * from './layout-compact-box-left-align';
export * from './layout-compact-box-top-to-bottom';
export * from './layout-concentric';
export * from './layout-custom-horizontal';
export * from './layout-custom-iterative';
export * from './layout-d3-force';
export * from './layout-dagre';
export * from './layout-dendrogram-basic';
export * from './layout-dendrogram-tb';
export * from './layout-force';
export * from './layout-force-collision';
export * from './layout-force-lattice';
export * from './layout-forceatlas2-wasm';
export * from './layout-fruchterman-basic';
export * from './layout-fruchterman-cluster';
export * from './layout-fruchterman-fix';
export * from './layout-fruchterman-gpu';
export * from './layout-fruchterman-wasm';
export * from './layout-grid';
export * from './layout-indented';
export * from './layout-mds';
export * from './layout-mindmap-h';
export * from './layout-mindmap-h-custom-side';
export * from './layout-mindmap-h-left';
export * from './layout-mindmap-h-right';
export * from './layout-radial-basic';
export * from './layout-radial-configuration-translate';
export * from './layout-radial-prevent-overlap';
export * from './layout-radial-prevent-overlap-unstrict';
export * from './layout-radial-sort';
export * from './perf-fcp';
export * from './plugin-bubble-sets';
export * from './plugin-camera-setting';
export * from './plugin-contextmenu';
export * from './plugin-grid-line';
export * from './plugin-history';
export * from './plugin-hull';
export * from './plugin-legend';
export * from './plugin-timebar';
export * from './plugin-toolbar-build-in';
export * from './plugin-toolbar-iconfont';
export * from './plugin-tooltip';
export * from './plugin-watermark';
export * from './plugin-watermark-image';
export * from './theme';
export * from './transform-process-parallel-edges';
export * from './viewport-fit';
export { animationElementEdgeCubic } from './animation-element-edge-cubic';
export { animationEdgeLine } from './animation-element-edge-line';
export { animationElementEdgeQuadratic } from './animation-element-edge-quadratic';
export { animationElementPosition } from './animation-element-position';
export { animationElementState } from './animation-element-state';
export { animationElementStateSwitch } from './animation-element-state-switch';
export { animationElementStylePosition } from './animation-element-style-position';
export { behaviorBrushSelect } from './behavior-brush-select';
export { behaviorClickElement } from './behavior-click-element';
export { behaviorCreateEdge } from './behavior-create-edge';
export { behaviorDragCanvas } from './behavior-drag-canvas';
export { behaviorDragNode } from './behavior-drag-element';
export { behaviorFocusElement } from './behavior-focus-element';
export { behaviorHoverElement } from './behavior-hover-element';
export { behaviorLassoSelect } from './behavior-lasso-select';
export { behaviorScrollCanvas } from './behavior-scroll-canvas';
export { behaviorZoomCanvas } from './behavior-zoom-canvas';
export { combo } from './combo';
export { comboExpandCollapse } from './combo-expand-collapse';
export { commonGraph } from './common-graph';
export { controllerViewport } from './controller-viewport';
export { elementChangeType } from './element-change-type';
export { elementEdgeArrow } from './element-edge-arrow';
export { elementEdgeCubic } from './element-edge-cubic';
export { elementEdgeCubicHorizontal } from './element-edge-cubic-horizontal';
export { elementEdgeCubicVertical } from './element-edge-cubic-vertical';
export { elementEdgeCustomArrow } from './element-edge-custom-arrow';
export { elementEdgeLine } from './element-edge-line';
export { elementEdgeLoopCurve } from './element-edge-loop-curve';
export { elementEdgeLoopPolyline } from './element-edge-loop-polyline';
export { elementEdgePolyline } from './element-edge-polyline';
export { elementEdgePolylineAnimation } from './element-edge-polyline-animation';
export { elementEdgePort } from './element-edge-port';
export { elementEdgeQuadratic } from './element-edge-quadratic';
export { elementLabelBackground } from './element-label-background';
export { elementLabelOversized } from './element-label-oversized';
export { elementNodeBadges } from './element-node-badges';
export { elementNodeCircle } from './element-node-circle';
export { elementNodeDiamond } from './element-node-diamond';
export { elementNodeDonut } from './element-node-donut';
export { elementNodeEllipse } from './element-node-ellipse';
export { elementNodeHexagon } from './element-node-hexagon';
export { elementNodeHTML } from './element-node-html';
export { elementNodeImage } from './element-node-image';
export { elementNodeRect } from './element-node-rect';
export { elementNodeStar } from './element-node-star';
export { elementNodeSVGIcon } from './element-node-svg-icon';
export { elementNodeTriangle } from './element-node-triangle';
export { elementPort } from './element-port';
export { elementPosition } from './element-position';
export { elementPositionCombo } from './element-position-combo';
export { elementState } from './element-state';
export { elementVisibility } from './element-visibility';
export { elementZIndex } from './element-z-index';
export { graphToDataURL } from './graph-to-data-url';
export { layoutAntVDagreFlow } from './layout-antv-dagre-flow';
export { layoutAntVDagreFlowCombo } from './layout-antv-dagre-flow-combo';
export { layoutCircularBasic } from './layout-circular-basic';
export { layoutCircularConfigurationTranslate } from './layout-circular-configuration-translate';
export { layoutCircularDegree } from './layout-circular-degree';
export { layoutCircularDivision } from './layout-circular-division';
export { layoutCircularSpiral } from './layout-circular-spiral';
export { layoutComboCombined } from './layout-combo-combined';
export { layoutCompactBoxBasic } from './layout-compact-box-basic';
export { layoutCompactBoxTopToBottom } from './layout-compact-box-left-align';
export { layoutCompactBoxLeftAlign } from './layout-compact-box-top-to-bottom';
export { layoutConcentric } from './layout-concentric';
export { layoutCustomHorizontal } from './layout-custom-horizontal';
export { layoutCustomIterative } from './layout-custom-iterative';
export { layoutD3Force } from './layout-d3-force';
export { layoutDagre } from './layout-dagre';
export { layoutDendrogramBasic } from './layout-dendrogram-basic';
export { layoutDendrogramTb } from './layout-dendrogram-tb';
export { layoutForce } from './layout-force';
export { layoutForceCollision } from './layout-force-collision';
export { layoutForceLattice } from './layout-force-lattice';
export { layoutForceatlas2WASM } from './layout-forceatlas2-wasm';
export { layoutFruchtermanBasic } from './layout-fruchterman-basic';
export { layoutFruchtermanCluster } from './layout-fruchterman-cluster';
export { layoutFruchtermanFix } from './layout-fruchterman-fix';
export { layoutFruchtermanGPU } from './layout-fruchterman-gpu';
export { layoutFruchtermanWASM } from './layout-fruchterman-wasm';
export { layoutGrid } from './layout-grid';
export { layoutIndented } from './layout-indented';
export { layoutMDS } from './layout-mds';
export { layoutMindmapH } from './layout-mindmap-h';
export { layoutMindmapHCustomSide } from './layout-mindmap-h-custom-side';
export { layoutMindmapHLeft } from './layout-mindmap-h-left';
export { layoutMindmapHRight } from './layout-mindmap-h-right';
export { layoutRadialBasic } from './layout-radial-basic';
export { layoutRadialConfigurationTranslate } from './layout-radial-configuration-translate';
export { layoutRadialPreventOverlap } from './layout-radial-prevent-overlap';
export { layoutRadialPreventOverlapUnstrict } from './layout-radial-prevent-overlap-unstrict';
export { layoutRadialSort } from './layout-radial-sort';
export { perfFCP } from './perf-fcp';
export { pluginBubbleSets } from './plugin-bubble-sets';
export { pluginCameraSetting } from './plugin-camera-setting';
export { pluginContextmenu } from './plugin-contextmenu';
export { pluginGridLine } from './plugin-grid-line';
export { pluginHistory } from './plugin-history';
export { pluginHull } from './plugin-hull';
export { pluginLegend } from './plugin-legend';
export { pluginTimebar } from './plugin-timebar';
export { pluginToolbarBuildIn } from './plugin-toolbar-build-in';
export { pluginToolbarIconfont } from './plugin-toolbar-iconfont';
export { pluginTooltip } from './plugin-tooltip';
export { pluginWatermark } from './plugin-watermark';
export { pluginWatermarkImage } from './plugin-watermark-image';
export { theme } from './theme';
export { transformProcessParallelEdges } from './transform-process-parallel-edges';
export { viewportFit } from './viewport-fit';

View File

@ -71,7 +71,7 @@ describe('registry', () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
register('node', 'circle-node', CircleNode as any);
expect(consoleErrorSpy.mock.calls[0][0]).toBe('The extension circle-node of node has been registered before.');
expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
consoleErrorSpy.mockRestore();

View File

@ -42,8 +42,8 @@
"coverage:open": "open coverage/lcov-report/index.html",
"dev": "vite",
"fix": "eslint ./src ./__tests__ --fix && prettier ./src __tests__ --write ",
"jest": "node --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict --experimental-vm-modules ../../node_modules/jest/bin/jest --coverage --logHeapUsage --detectOpenHandles",
"jest:inspect": "node --inspect --expose-gc --max-old-space-size=4096 --unhandled-rejections=strict --experimental-vm-modules ../../node_modules/jest/bin/jest --coverage --logHeapUsage --detectOpenHandles --runInBand",
"jest": "node --expose-gc --max-old-space-size=1024 --unhandled-rejections=strict --experimental-vm-modules ../../node_modules/jest/bin/jest --coverage --logHeapUsage --detectOpenHandles",
"jest:inspect": "node --inspect --expose-gc --max-old-space-size=1024 --unhandled-rejections=strict --experimental-vm-modules ../../node_modules/jest/bin/jest --coverage --logHeapUsage --detectOpenHandles --runInBand",
"lint": "eslint ./src __tests__ --quiet && prettier ./src __tests__ --check",
"prepublishOnly": "npm run ci",
"size": "limit-size",

View File

@ -56,11 +56,10 @@ export function register<T extends ExtensionCategory>(
type: string,
Ctor: ExtensionRegistry[T][string],
) {
if (EXTENSION_REGISTRY[category]![type]) {
console.error(`The extension ${type} of ${category} has been registered before.`);
return;
}
Object.assign(EXTENSION_REGISTRY[category]!, { [type]: Ctor });
const ext = EXTENSION_REGISTRY[category][type];
if (ext) {
if (ext !== Ctor) console.error(`The extension ${type} of ${category} has been registered before.`);
} else Object.assign(EXTENSION_REGISTRY[category]!, { [type]: Ctor });
}
/**