diff --git a/__tests__/jest/components/nodeImpl/Svg.tsx b/__tests__/jest/components/nodeImpl/Svg.tsx index 57b32f84..4f9a7030 100644 --- a/__tests__/jest/components/nodeImpl/Svg.tsx +++ b/__tests__/jest/components/nodeImpl/Svg.tsx @@ -10,7 +10,7 @@ jest.mock('../../../../src/jsonUtils/models', () => ({ })); describe('node ', () => { - it('generates the json for an svg', () => { + it('generates the json for an svg', async () => { class SVGElement extends React.Component { render() { return ( @@ -26,6 +26,6 @@ describe('node ', () => { } } - expect(ReactSketch.renderToJSON()).toMatchSnapshot(); + expect(await ReactSketch.renderToJSON()).toMatchSnapshot(); }); }); diff --git a/__tests__/jest/index.ts b/__tests__/jest/index.ts index b85655e1..46167f68 100644 --- a/__tests__/jest/index.ts +++ b/__tests__/jest/index.ts @@ -1,9 +1,5 @@ /* eslint-disable global-require */ -import ReactSketch from '../../src'; -jest.mock('../../src/jsonUtils/sketchImpl/createStringMeasurer'); -jest.mock('../../src/jsonUtils/sketchImpl/findFontName'); -jest.mock('../../src/jsonUtils/sketchImpl/makeImageDataFromUrl'); -jest.mock('../../src/jsonUtils/sketchImpl/makeSvgLayer'); +import * as ReactSketch from '../../src'; describe('public API', () => { it('exports render', () => { diff --git a/__tests__/jest/jsonUtils/computeYogaNode.ts b/__tests__/jest/jsonUtils/computeYogaNode.ts index b6af0d83..7021f525 100644 --- a/__tests__/jest/jsonUtils/computeYogaNode.ts +++ b/__tests__/jest/jsonUtils/computeYogaNode.ts @@ -1,6 +1,7 @@ import yoga from 'yoga-layout-prebuilt'; import computeYogaNode from '../../../src/jsonUtils/computeYogaNode'; import Context from '../../../src/utils/Context'; +import NodeMacOSBridge from '../../../src/platformBridges/NodeMacOSBridge'; const widthAndHeightStylesStub = { width: 10, @@ -32,7 +33,7 @@ const createYogaNodes = ( styles.forEach(style => { const treeNode = createTreeNode(style); const ctx = new Context(); - const { node } = computeYogaNode(treeNode, ctx); + const { node } = computeYogaNode(treeNode, ctx, NodeMacOSBridge); node.calculateLayout( containerWidth || undefined, containerHeight || undefined, diff --git a/__tests__/jest/jsonUtils/computeYogaTree.ts b/__tests__/jest/jsonUtils/computeYogaTree.ts index 636ca903..6dbf91fa 100644 --- a/__tests__/jest/jsonUtils/computeYogaTree.ts +++ b/__tests__/jest/jsonUtils/computeYogaTree.ts @@ -1,6 +1,7 @@ import yoga from 'yoga-layout-prebuilt'; import computeYogaTree from '../../../src/jsonUtils/computeYogaTree'; import Context from '../../../src/utils/Context'; +import NodeMacOSBridge from '../../../src/platformBridges/NodeMacOSBridge'; const treeRootStub = { type: 'artboard', @@ -35,11 +36,11 @@ const treeRootStub = { ], }; -computeYogaTree(treeRootStub, new Context()); +computeYogaTree(treeRootStub, new Context(), NodeMacOSBridge); describe('Compute Yoga Tree', () => { it('correctly create yoga nodes into layout tree', () => { - const yogaTree = computeYogaTree(treeRootStub, new Context()); + const yogaTree = computeYogaTree(treeRootStub, new Context(), NodeMacOSBridge); yogaTree.calculateLayout(undefined, undefined, yoga.DIRECTION_LTR); expect(yogaTree.getComputedLayout()).toEqual({ bottom: 0, diff --git a/__tests__/jest/reactTreeToFlexTree.ts b/__tests__/jest/reactTreeToFlexTree.ts index 96654075..5e3b95ac 100644 --- a/__tests__/jest/reactTreeToFlexTree.ts +++ b/__tests__/jest/reactTreeToFlexTree.ts @@ -2,6 +2,7 @@ import yoga from 'yoga-layout-prebuilt'; import computeYogaTree from '../../src/jsonUtils/computeYogaTree'; import Context from '../../src/utils/Context'; import { reactTreeToFlexTree } from '../../src/buildTree'; +import NodeMacOSBridge from '../../src/platformBridges/NodeMacOSBridge'; const treeRootStub = { type: 'artboard', @@ -55,7 +56,7 @@ const treeRootStub = { describe('Compute Flex Tree', () => { it('correctly creates flex tree', () => { - const yogaNode = computeYogaTree(treeRootStub, new Context()); + const yogaNode = computeYogaTree(treeRootStub, new Context(), NodeMacOSBridge); yogaNode.calculateLayout(undefined, undefined, yoga.DIRECTION_LTR); const tree = reactTreeToFlexTree(treeRootStub, yogaNode, new Context()); diff --git a/__tests__/jest/sharedStyles/TextStyles.ts b/__tests__/jest/sharedStyles/TextStyles.ts index 5fae7c04..d1b20005 100644 --- a/__tests__/jest/sharedStyles/TextStyles.ts +++ b/__tests__/jest/sharedStyles/TextStyles.ts @@ -7,7 +7,7 @@ beforeEach(() => { jest.resetModules(); jest.mock('../../../src/utils/getSketchVersion', () => ({ - getSketchVersion: jest.fn(() => 51), + default: jest.fn(() => '51'), })); TextStyles = require('../../../src/sharedStyles/TextStyles'); @@ -16,10 +16,10 @@ beforeEach(() => { jest.mock('../../../src/utils/sharedTextStyles'); - jest.mock('../../../src/jsonUtils/sketchImpl/createStringMeasurer'); - jest.mock('../../../src/jsonUtils/sketchImpl/findFontName'); - jest.mock('../../../src/jsonUtils/sketchImpl/makeImageDataFromUrl'); - jest.mock('../../../src/jsonUtils/sketchImpl/makeSvgLayer'); + // jest.mock('../../../src/jsonUtils/sketchImpl/createStringMeasurer'); + // jest.mock('../../../src/jsonUtils/sketchImpl/findFontName'); + // jest.mock('../../../src/jsonUtils/sketchImpl/makeImageDataFromUrl'); + // jest.mock('../../../src/jsonUtils/sketchImpl/makeSvgLayer'); TextStyles = TextStyles.default; sharedTextStyles = sharedTextStyles.default; diff --git a/src/index.node.ts b/src/index.ts similarity index 100% rename from src/index.node.ts rename to src/index.ts diff --git a/src/jsonUtils/makeSvgLayer/index.ts b/src/jsonUtils/makeSvgLayer/index.ts index 31f97846..d61cb20d 100644 --- a/src/jsonUtils/makeSvgLayer/index.ts +++ b/src/jsonUtils/makeSvgLayer/index.ts @@ -2,4 +2,4 @@ import isRunningInSketch from '../../utils/isRunningInSketch'; import sketchMakeSvgLayer from './makeSvgLayer.sketch'; import pureJsSketchMakeSvgLayer from './makeSvgLayer'; -export default isRunningInSketch() ? pureJsSketchMakeSvgLayer : sketchMakeSvgLayer; +export default isRunningInSketch() ? sketchMakeSvgLayer : pureJsSketchMakeSvgLayer; diff --git a/src/jsonUtils/makeSvgLayer/makeSvgLayer.ts b/src/jsonUtils/makeSvgLayer/makeSvgLayer.ts index f6ea8a34..3d22b18b 100644 --- a/src/jsonUtils/makeSvgLayer/makeSvgLayer.ts +++ b/src/jsonUtils/makeSvgLayer/makeSvgLayer.ts @@ -83,7 +83,7 @@ export default async function makeSvgLayer( svg: string, ): Promise { // Load the module only if it has been made available through another import. - const svgModel = await import(/* webpackMode: "weak" */ '@lona/svg-model'); + const svgModel = (await import(/* webpackMode: "weak" */ '@lona/svg-model')).default; const { data: { params, children },