Skip to content

Commit

Permalink
Fix most of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lordofthelake committed Jan 22, 2020
1 parent 435bce2 commit 9e0744f
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions __tests__/jest/components/nodeImpl/Svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jest.mock('../../../../src/jsonUtils/models', () => ({
}));

describe('node <Svg />', () => {
it('generates the json for an svg', () => {
it('generates the json for an svg', async () => {
class SVGElement extends React.Component {
render() {
return (
Expand All @@ -26,6 +26,6 @@ describe('node <Svg />', () => {
}
}

expect(ReactSketch.renderToJSON(<SVGElement />)).toMatchSnapshot();
expect(await ReactSketch.renderToJSON(<SVGElement />)).toMatchSnapshot();
});
});
6 changes: 1 addition & 5 deletions __tests__/jest/index.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/jest/jsonUtils/computeYogaNode.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions __tests__/jest/jsonUtils/computeYogaTree.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion __tests__/jest/reactTreeToFlexTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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());

Expand Down
10 changes: 5 additions & 5 deletions __tests__/jest/sharedStyles/TextStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/jsonUtils/makeSvgLayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/jsonUtils/makeSvgLayer/makeSvgLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default async function makeSvgLayer(
svg: string,
): Promise<FileFormat.Group> {
// 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 },
Expand Down

0 comments on commit 9e0744f

Please sign in to comment.