diff --git a/.env.example b/.env.example index b934687..f5705bb 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,3 @@ E2E_LOGIN_EMAIL="" E2E_LOGIN_PASSWORD="" +E2E_SCREENSHOTS= "false" diff --git a/.gitignore b/.gitignore index 3a68d40..25a4f2e 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ Thumbs.db **/assets/plugin.js docs/api + + +apps/e2e/screenshots/*.png diff --git a/apps/e2e/screenshots/.gitkeep b/apps/e2e/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/e2e/src/__snapshots__/plugins.spec.ts.snap b/apps/e2e/src/__snapshots__/plugins.spec.ts.snap index 6aacaf6..ea39ba3 100644 --- a/apps/e2e/src/__snapshots__/plugins.spec.ts.snap +++ b/apps/e2e/src/__snapshots__/plugins.spec.ts.snap @@ -89,20 +89,20 @@ exports[`Plugins > component library 1`] = ` "parentId": "1", "points": [ { - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { - "x": 100, - "y": 0, + "x": 784, + "y": 540, }, { - "x": 100, - "y": 100, + "x": 784, + "y": 640, }, { - "x": 0, - "y": 100, + "x": 684, + "y": 640, }, ], "proportion": 1, @@ -113,12 +113,12 @@ exports[`Plugins > component library 1`] = ` "selrect": { "height": 100, "width": 100, - "x": 0, - "x1": 0, - "x2": 100, - "y": 0, - "y1": 0, - "y2": 100, + "x": 684, + "x1": 684, + "x2": 784, + "y": 540, + "y1": 540, + "y2": 640, }, "strokes": [], "transform": { @@ -139,8 +139,8 @@ exports[`Plugins > component library 1`] = ` }, "type": "rect", "width": 100, - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, ] `; @@ -195,8 +195,8 @@ exports[`Plugins > create board - text - rectable 1`] = ` }, "shapes": [ "2", - "3", "4", + "5", ], "strokes": [], "transform": { @@ -220,222 +220,6 @@ exports[`Plugins > create board - text - rectable 1`] = ` "x": 0, "y": 0, }, - { - "content": { - "children": [ - { - "children": [ - { - "children": [ - { - "fills": [ - { - "fillColor": "#000000", - "fillOpacity": 1, - }, - ], - "fontFamily": "sourcesanspro", - "fontId": "sourcesanspro", - "fontSize": "14", - "fontStyle": "normal", - "fontVariantId": "regular", - "fontWeight": "400", - "letterSpacing": "0", - "lineHeight": "1.2", - "text": "Hello from plugin", - "textAlign": "left", - "textDecoration": "none", - "textTransform": "none", - "typographyRefFile": null, - "typographyRefId": null, - }, - ], - "fills": [ - { - "fillColor": "#000000", - "fillOpacity": 1, - }, - ], - "fontFamily": "sourcesanspro", - "fontId": "sourcesanspro", - "fontSize": "14", - "fontStyle": "normal", - "fontVariantId": "regular", - "fontWeight": "400", - "letterSpacing": "0", - "lineHeight": "1.2", - "textAlign": "left", - "textDecoration": "none", - "textTransform": "none", - "type": "paragraph", - "typographyRefFile": null, - "typographyRefId": null, - }, - ], - "type": "paragraph-set", - }, - ], - "type": "root", - }, - "flipX": null, - "flipY": null, - "frameId": "1", - "growType": "auto-width", - "height": 17, - "id": "2", - "name": "Text", - "parentId": "1", - "points": [ - { - "x": 684, - "y": 540, - }, - { - "x": 786, - "y": 540, - }, - { - "x": 786, - "y": 557, - }, - { - "x": 684, - "y": 557, - }, - ], - "positionData": [ - { - "direction": "ltr", - "fills": [ - { - "fillColor": "#000000", - "fillOpacity": 1, - }, - ], - "fontFamily": "sourcesanspro", - "fontSize": "14px", - "fontStyle": "normal", - "fontWeight": "400", - "height": 18, - "letterSpacing": "normal", - "text": "Hello from plugin", - "textDecoration": "none solid rgb(0, 0, 0)", - "textTransform": "none", - "width": 101.53125, - "x": 684, - "x1": 0, - "x2": 101.53125, - "y": 557, - "y1": -1, - "y2": 17, - }, - ], - "rotation": 0, - "selrect": { - "height": 17, - "width": 102, - "x": 684, - "x1": 684, - "x2": 786, - "y": 540, - "y1": 540, - "y2": 557, - }, - "transform": { - "a": 1, - "b": 0, - "c": 0, - "d": 1, - "e": 0, - "f": 0, - }, - "transformInverse": { - "a": 1, - "b": 0, - "c": 0, - "d": 1, - "e": 0, - "f": 0, - }, - "type": "text", - "width": 102, - "x": 684, - "y": 540, - }, - { - "fills": [ - { - "fillColor": "#B1B2B5", - "fillOpacity": 1, - }, - ], - "flipX": null, - "flipY": null, - "frameId": "1", - "height": 200, - "id": "3", - "name": "Rectangle", - "parentId": "1", - "pluginData": { - "TEST": { - "customKey": "customValue", - }, - }, - "points": [ - { - "x": 684, - "y": 540, - }, - { - "x": 884, - "y": 540, - }, - { - "x": 884, - "y": 740, - }, - { - "x": 684, - "y": 740, - }, - ], - "proportion": 1, - "proportionLock": false, - "rotation": 0, - "rx": 0, - "ry": 0, - "selrect": { - "height": 200, - "width": 200, - "x": 684, - "x1": 684, - "x2": 884, - "y": 540, - "y1": 540, - "y2": 740, - }, - "strokes": [], - "transform": { - "a": 1, - "b": 0, - "c": 0, - "d": 1, - "e": 0, - "f": 0, - }, - "transformInverse": { - "a": 1, - "b": 0, - "c": 0, - "d": 1, - "e": 0, - "f": 0, - }, - "type": "rect", - "width": 200, - "x": 684, - "y": 540, - }, { "fills": [ { @@ -448,7 +232,7 @@ exports[`Plugins > create board - text - rectable 1`] = ` "frameId": "1", "height": 300, "hideFillOnExport": false, - "id": "4", + "id": "2", "name": "Board name", "parentId": "1", "points": [ @@ -485,7 +269,7 @@ exports[`Plugins > create board - text - rectable 1`] = ` "y2": 840, }, "shapes": [ - "5", + "3", ], "strokes": [], "transform": { @@ -570,12 +354,12 @@ exports[`Plugins > create board - text - rectable 1`] = ` }, "flipX": null, "flipY": null, - "frameId": "4", + "frameId": "2", "growType": "auto-width", "height": 17, - "id": "5", + "id": "3", "name": "Text", - "parentId": "4", + "parentId": "2", "points": [ { "x": 10, @@ -653,6 +437,222 @@ exports[`Plugins > create board - text - rectable 1`] = ` "x": 10, "y": 10, }, + { + "fills": [ + { + "fillColor": "#B1B2B5", + "fillOpacity": 1, + }, + ], + "flipX": null, + "flipY": null, + "frameId": "1", + "height": 200, + "id": "4", + "name": "Rectangle", + "parentId": "1", + "pluginData": { + "TEST": { + "customKey": "customValue", + }, + }, + "points": [ + { + "x": 684, + "y": 540, + }, + { + "x": 884, + "y": 540, + }, + { + "x": 884, + "y": 740, + }, + { + "x": 684, + "y": 740, + }, + ], + "proportion": 1, + "proportionLock": false, + "rotation": 0, + "rx": 0, + "ry": 0, + "selrect": { + "height": 200, + "width": 200, + "x": 684, + "x1": 684, + "x2": 884, + "y": 540, + "y1": 540, + "y2": 740, + }, + "strokes": [], + "transform": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transformInverse": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "type": "rect", + "width": 200, + "x": 684, + "y": 540, + }, + { + "content": { + "children": [ + { + "children": [ + { + "children": [ + { + "fills": [ + { + "fillColor": "#000000", + "fillOpacity": 1, + }, + ], + "fontFamily": "sourcesanspro", + "fontId": "sourcesanspro", + "fontSize": "14", + "fontStyle": "normal", + "fontVariantId": "regular", + "fontWeight": "400", + "letterSpacing": "0", + "lineHeight": "1.2", + "text": "Hello from plugin", + "textAlign": "left", + "textDecoration": "none", + "textTransform": "none", + "typographyRefFile": null, + "typographyRefId": null, + }, + ], + "fills": [ + { + "fillColor": "#000000", + "fillOpacity": 1, + }, + ], + "fontFamily": "sourcesanspro", + "fontId": "sourcesanspro", + "fontSize": "14", + "fontStyle": "normal", + "fontVariantId": "regular", + "fontWeight": "400", + "letterSpacing": "0", + "lineHeight": "1.2", + "textAlign": "left", + "textDecoration": "none", + "textTransform": "none", + "type": "paragraph", + "typographyRefFile": null, + "typographyRefId": null, + }, + ], + "type": "paragraph-set", + }, + ], + "type": "root", + }, + "flipX": null, + "flipY": null, + "frameId": "1", + "growType": "auto-width", + "height": 17, + "id": "5", + "name": "Text", + "parentId": "1", + "points": [ + { + "x": 684, + "y": 540, + }, + { + "x": 786, + "y": 540, + }, + { + "x": 786, + "y": 557, + }, + { + "x": 684, + "y": 557, + }, + ], + "positionData": [ + { + "direction": "ltr", + "fills": [ + { + "fillColor": "#000000", + "fillOpacity": 1, + }, + ], + "fontFamily": "sourcesanspro", + "fontSize": "14px", + "fontStyle": "normal", + "fontWeight": "400", + "height": 18, + "letterSpacing": "normal", + "text": "Hello from plugin", + "textDecoration": "none solid rgb(0, 0, 0)", + "textTransform": "none", + "width": 101.53125, + "x": 684, + "x1": 0, + "x2": 101.53125, + "y": 557, + "y1": -1, + "y2": 17, + }, + ], + "rotation": 0, + "selrect": { + "height": 17, + "width": 102, + "x": 684, + "x1": 684, + "x2": 786, + "y": 540, + "y1": 540, + "y2": 557, + }, + "transform": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "transformInverse": { + "a": 1, + "b": 0, + "c": 0, + "d": 1, + "e": 0, + "f": 0, + }, + "type": "text", + "width": 102, + "x": 684, + "y": 540, + }, ] `; @@ -739,7 +739,7 @@ exports[`Plugins > create flex layout 1`] = ` "flipX": null, "flipY": null, "frameId": "1", - "height": 110.00000000000001, + "height": 110, "hideFillOnExport": false, "id": "2", "layout": "flex", @@ -767,34 +767,34 @@ exports[`Plugins > create flex layout 1`] = ` "parentId": "1", "points": [ { - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { - "x": 210, - "y": 0, + "x": 894, + "y": 540, }, { - "x": 210, - "y": 110.00000000000001, + "x": 894, + "y": 650, }, { - "x": 0, - "y": 110.00000000000001, + "x": 684, + "y": 650, }, ], "proportion": 1, "proportionLock": false, "rotation": 0, "selrect": { - "height": 110.00000000000001, + "height": 110, "width": 210, - "x": 0, - "x1": 0, - "x2": 210, - "y": 0, - "y1": 0, - "y2": 110.00000000000001, + "x": 684, + "x1": 684, + "x2": 894, + "y": 540, + "y1": 540, + "y2": 650, }, "shapes": [ "4", @@ -819,8 +819,8 @@ exports[`Plugins > create flex layout 1`] = ` }, "type": "frame", "width": 210, - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { "constraintsH": "left", @@ -840,20 +840,20 @@ exports[`Plugins > create flex layout 1`] = ` "parentId": "2", "points": [ { - "x": 5, - "y": 5.000000000000007, + "x": 689, + "y": 545, }, { - "x": 105, - "y": 5.000000000000007, + "x": 789, + "y": 545, }, { - "x": 105, - "y": 105, + "x": 789, + "y": 645, }, { - "x": 5, - "y": 105, + "x": 689, + "y": 645, }, ], "proportion": 1, @@ -864,12 +864,12 @@ exports[`Plugins > create flex layout 1`] = ` "selrect": { "height": 100, "width": 100, - "x": 5, - "x1": 5, - "x2": 105, - "y": 5.000000000000007, - "y1": 5.000000000000007, - "y2": 105, + "x": 689, + "x1": 689, + "x2": 789, + "y": 545, + "y1": 545, + "y2": 645, }, "strokes": [], "transform": { @@ -890,8 +890,8 @@ exports[`Plugins > create flex layout 1`] = ` }, "type": "rect", "width": 100, - "x": 5, - "y": 5.000000000000007, + "x": 689, + "y": 545, }, { "constraintsH": "left", @@ -911,20 +911,20 @@ exports[`Plugins > create flex layout 1`] = ` "parentId": "2", "points": [ { - "x": 105, - "y": 5.000000000000007, + "x": 789, + "y": 545, }, { - "x": 205, - "y": 5.000000000000007, + "x": 889, + "y": 545, }, { - "x": 205, - "y": 105, + "x": 889, + "y": 645, }, { - "x": 105, - "y": 105, + "x": 789, + "y": 645, }, ], "proportion": 1, @@ -933,12 +933,12 @@ exports[`Plugins > create flex layout 1`] = ` "selrect": { "height": 100, "width": 100, - "x": 105, - "x1": 105, - "x2": 205, - "y": 5.000000000000007, - "y1": 5.000000000000007, - "y2": 105, + "x": 789, + "x1": 789, + "x2": 889, + "y": 545, + "y1": 545, + "y2": 645, }, "strokes": [], "transform": { @@ -959,8 +959,8 @@ exports[`Plugins > create flex layout 1`] = ` }, "type": "circle", "width": 100, - "x": 105, - "y": 5.000000000000007, + "x": 789, + "y": 545, }, ] `; @@ -1139,20 +1139,20 @@ exports[`Plugins > create grid layout 1`] = ` "parentId": "1", "points": [ { - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { - "x": 100, - "y": 0, + "x": 784, + "y": 540, }, { - "x": 100, - "y": 100, + "x": 784, + "y": 640, }, { - "x": 0, - "y": 100, + "x": 684, + "y": 640, }, ], "proportion": 1, @@ -1161,12 +1161,12 @@ exports[`Plugins > create grid layout 1`] = ` "selrect": { "height": 100, "width": 100, - "x": 0, - "x1": 0, - "x2": 100, - "y": 0, - "y1": 0, - "y2": 100, + "x": 684, + "x1": 684, + "x2": 784, + "y": 540, + "y1": 540, + "y2": 640, }, "shapes": [], "strokes": [], @@ -1188,8 +1188,8 @@ exports[`Plugins > create grid layout 1`] = ` }, "type": "frame", "width": 100, - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, ] `; @@ -1283,20 +1283,20 @@ exports[`Plugins > group and ungroup 1`] = ` "parentId": "4", "points": [ { - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { - "x": 100, - "y": 0, + "x": 784, + "y": 540, }, { - "x": 100, - "y": 100, + "x": 784, + "y": 640, }, { - "x": 0, - "y": 100, + "x": 684, + "y": 640, }, ], "proportion": 1, @@ -1307,12 +1307,12 @@ exports[`Plugins > group and ungroup 1`] = ` "selrect": { "height": 100, "width": 100, - "x": 0, - "x1": 0, - "x2": 100, - "y": 0, - "y1": 0, - "y2": 100, + "x": 684, + "x1": 684, + "x2": 784, + "y": 540, + "y1": 540, + "y2": 640, }, "strokes": [], "transform": { @@ -1333,8 +1333,8 @@ exports[`Plugins > group and ungroup 1`] = ` }, "type": "rect", "width": 100, - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { "fills": [ @@ -1352,20 +1352,20 @@ exports[`Plugins > group and ungroup 1`] = ` "parentId": "4", "points": [ { - "x": 0, - "y": 0, + "x": 784, + "y": 640, }, { - "x": 100, - "y": 0, + "x": 884, + "y": 640, }, { - "x": 100, - "y": 100, + "x": 884, + "y": 740, }, { - "x": 0, - "y": 100, + "x": 784, + "y": 740, }, ], "proportion": 1, @@ -1376,12 +1376,12 @@ exports[`Plugins > group and ungroup 1`] = ` "selrect": { "height": 100, "width": 100, - "x": 0, - "x1": 0, - "x2": 100, - "y": 0, - "y1": 0, - "y2": 100, + "x": 784, + "x1": 784, + "x2": 884, + "y": 640, + "y1": 640, + "y2": 740, }, "strokes": [], "transform": { @@ -1402,49 +1402,49 @@ exports[`Plugins > group and ungroup 1`] = ` }, "type": "rect", "width": 100, - "x": 0, - "y": 0, + "x": 784, + "y": 640, }, { "fills": [], "flipX": null, "flipY": null, "frameId": "1", - "height": 100, + "height": 200, "id": "4", "index": 2, "name": "Group", "parentId": "1", "points": [ { - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { - "x": 100, - "y": 0, + "x": 884, + "y": 540, }, { - "x": 100, - "y": 100, + "x": 884, + "y": 740, }, { - "x": 0, - "y": 100, + "x": 684, + "y": 740, }, ], "proportion": 1, "proportionLock": false, "rotation": 0, "selrect": { - "height": 100, - "width": 100, - "x": 0, - "x1": 0, - "x2": 100, - "y": 0, - "y1": 0, - "y2": 100, + "height": 200, + "width": 200, + "x": 684, + "x1": 684, + "x2": 884, + "y": 540, + "y1": 540, + "y2": 740, }, "shapes": [ "2", @@ -1468,9 +1468,9 @@ exports[`Plugins > group and ungroup 1`] = ` "f": 0, }, "type": "group", - "width": 100, - "x": 0, - "y": 0, + "width": 200, + "x": 684, + "y": 540, }, ] `; @@ -2169,20 +2169,20 @@ exports[`Plugins > text and textrange 1`] = ` "parentId": "1", "points": [ { - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, { - "x": 214, - "y": 0, + "x": 898, + "y": 540, }, { - "x": 214, - "y": 48, + "x": 898, + "y": 588, }, { - "x": 0, - "y": 48, + "x": 684, + "y": 588, }, ], "positionData": [ @@ -2204,10 +2204,10 @@ exports[`Plugins > text and textrange 1`] = ` "textDecoration": "underline solid rgb(255, 111, 224)", "textTransform": "uppercase", "width": 129.03125, - "x": 0, + "x": 684, "x1": 0, "x2": 129.03125, - "y": 47, + "y": 587, "y1": 0, "y2": 47, }, @@ -2229,10 +2229,10 @@ exports[`Plugins > text and textrange 1`] = ` "textDecoration": "underline solid rgb(0, 0, 0)", "textTransform": "uppercase", "width": 84.375, - "x": 129.03125, + "x": 813.03125, "x1": 129.03125, "x2": 213.40625, - "y": 42, + "y": 582, "y1": 18, "y2": 42, }, @@ -2241,12 +2241,12 @@ exports[`Plugins > text and textrange 1`] = ` "selrect": { "height": 48, "width": 214, - "x": 0, - "x1": 0, - "x2": 214, - "y": 0, - "y1": 0, - "y2": 48, + "x": 684, + "x1": 684, + "x2": 898, + "y": 540, + "y1": 540, + "y2": 588, }, "transform": { "a": 1, @@ -2266,8 +2266,8 @@ exports[`Plugins > text and textrange 1`] = ` }, "type": "text", "width": 214, - "x": 0, - "y": 0, + "x": 684, + "y": 540, }, ] `; diff --git a/apps/e2e/src/plugins.spec.ts b/apps/e2e/src/plugins.spec.ts index ba42e06..979ac8e 100644 --- a/apps/e2e/src/plugins.spec.ts +++ b/apps/e2e/src/plugins.spec.ts @@ -11,31 +11,41 @@ import { Agent } from './utils/agent'; describe('Plugins', () => { it('create board - text - rectable', async () => { const agent = await Agent(); - const result = await agent.runCode(testingPlugin.toString()); + const result = await agent.runCode(testingPlugin.toString(), { + screenshot: 'create-board-text-rect', + }); expect(result).toMatchSnapshot(); }); it('create flex layout', async () => { const agent = await Agent(); - const result = await agent.runCode(flex.toString()); + const result = await agent.runCode(flex.toString(), { + screenshot: 'create-flexlayout', + }); expect(result).toMatchSnapshot(); }); it('create grid layout', async () => { const agent = await Agent(); - const result = await agent.runCode(grid.toString()); + const result = await agent.runCode(grid.toString(), { + screenshot: 'create-gridlayout', + }); expect(result).toMatchSnapshot(); }); it('group and ungroup', async () => { const agent = await Agent(); - const result = await agent.runCode(group.toString()); + const result = await agent.runCode(group.toString(), { + screenshot: 'group-ungroup', + }); expect(result).toMatchSnapshot(); }); it('insert svg', async () => { const agent = await Agent(); - const result = await agent.runCode(insertSvg.toString()); + const result = await agent.runCode(insertSvg.toString(), { + screenshot: 'insert-svg', + }); expect(result).toMatchSnapshot(); }); @@ -47,13 +57,17 @@ describe('Plugins', () => { it('component library', async () => { const agent = await Agent(); - const result = await agent.runCode(componentLibrary.toString()); + const result = await agent.runCode(componentLibrary.toString(), { + screenshot: 'component-library', + }); expect(result).toMatchSnapshot(); }); it('text and textrange', async () => { const agent = await Agent(); - const result = await agent.runCode(createText.toString()); + const result = await agent.runCode(createText.toString(), { + screenshot: 'create-text', + }); expect(result).toMatchSnapshot(); }); }); diff --git a/apps/e2e/src/plugins/component-library.ts b/apps/e2e/src/plugins/component-library.ts index b7429f0..02fa483 100644 --- a/apps/e2e/src/plugins/component-library.ts +++ b/apps/e2e/src/plugins/component-library.ts @@ -1,7 +1,10 @@ export default function () { const rectangle = penpot.createRectangle(); + rectangle.x = penpot.viewport.center.x; + rectangle.y = penpot.viewport.center.y; + const shape = penpot.getPage()?.getShapeById(rectangle.id); if (shape) { - penpot.library.local.createComponent(shape); + penpot.library.local.createComponent([shape]); } } diff --git a/apps/e2e/src/plugins/create-board-text-rect.ts b/apps/e2e/src/plugins/create-board-text-rect.ts index 1dd2e67..62d34a7 100644 --- a/apps/e2e/src/plugins/create-board-text-rect.ts +++ b/apps/e2e/src/plugins/create-board-text-rect.ts @@ -32,8 +32,6 @@ export default function () { board.name = 'Board name'; - console.log(penpot.viewport.center.x); - board.x = penpot.viewport.center.x; board.y = penpot.viewport.center.y; @@ -54,7 +52,7 @@ export default function () { return board; } - createText('Hello from plugin'); - createRectangle(); createBoard(); + createRectangle(); + createText('Hello from plugin'); } diff --git a/apps/e2e/src/plugins/create-flexlayout.ts b/apps/e2e/src/plugins/create-flexlayout.ts index 46abbc1..c24b48e 100644 --- a/apps/e2e/src/plugins/create-flexlayout.ts +++ b/apps/e2e/src/plugins/create-flexlayout.ts @@ -4,6 +4,9 @@ export default function () { board.horizontalSizing = 'auto'; board.verticalSizing = 'auto'; + board.x = penpot.viewport.center.x; + board.y = penpot.viewport.center.y; + const flex = board.addFlexLayout(); flex.dir = 'column'; diff --git a/apps/e2e/src/plugins/create-gridlayout.ts b/apps/e2e/src/plugins/create-gridlayout.ts index c31ef4c..41205ee 100644 --- a/apps/e2e/src/plugins/create-gridlayout.ts +++ b/apps/e2e/src/plugins/create-gridlayout.ts @@ -1,6 +1,8 @@ export default function () { function createGridLayout(): void { const board = penpot.createBoard(); + board.x = penpot.viewport.center.x; + board.y = penpot.viewport.center.y; const grid = board.addGridLayout(); diff --git a/apps/e2e/src/plugins/create-text.ts b/apps/e2e/src/plugins/create-text.ts index d6c68d4..ccd2069 100644 --- a/apps/e2e/src/plugins/create-text.ts +++ b/apps/e2e/src/plugins/create-text.ts @@ -1,22 +1,23 @@ export default function () { - function createText(): void { - const text = penpot.createText('Hello World!'); + function createText(): void { + const text = penpot.createText('Hello World!'); - if (text) { - text.growType = 'auto-width'; - text.textTransform = 'uppercase'; - text.textDecoration = 'underline'; - text.fontId = 'gfont-work-sans'; - text.fontStyle = 'italic'; - text.fontSize = '20'; - text.fontWeight = '500'; - - const textRange = text.getRange(0, 5); - textRange.fontSize = '40'; - textRange.fills = [{ fillColor: '#ff6fe0', fillOpacity: 1 }]; - } + if (text) { + text.x = penpot.viewport.center.x; + text.y = penpot.viewport.center.y; + text.growType = 'auto-width'; + text.textTransform = 'uppercase'; + text.textDecoration = 'underline'; + text.fontId = 'gfont-work-sans'; + text.fontStyle = 'italic'; + text.fontSize = '20'; + text.fontWeight = '500'; + + const textRange = text.getRange(0, 5); + textRange.fontSize = '40'; + textRange.fills = [{ fillColor: '#ff6fe0', fillOpacity: 1 }]; } - - createText(); } - \ No newline at end of file + + createText(); +} diff --git a/apps/e2e/src/plugins/group.ts b/apps/e2e/src/plugins/group.ts index 8c6be37..a8e189d 100644 --- a/apps/e2e/src/plugins/group.ts +++ b/apps/e2e/src/plugins/group.ts @@ -16,7 +16,11 @@ export default function () { } const rectangle = penpot.createRectangle(); + rectangle.x = penpot.viewport.center.x; + rectangle.y = penpot.viewport.center.y; const rectangle2 = penpot.createRectangle(); + rectangle2.x = penpot.viewport.center.x + 100; + rectangle2.y = penpot.viewport.center.y + 100; penpot.selection = [rectangle, rectangle2]; diff --git a/apps/e2e/src/utils/agent.ts b/apps/e2e/src/utils/agent.ts index 5a34438..83244d4 100644 --- a/apps/e2e/src/utils/agent.ts +++ b/apps/e2e/src/utils/agent.ts @@ -4,6 +4,8 @@ import { getFileUrl } from './get-file-url'; import { idObjectToArray } from './clean-id'; import { Shape } from '../models/shape.model'; +const screenshotsEnable = process.env['E2E_SCREENSHOTS'] === 'true'; + function replaceIds(shapes: Shape[]) { let id = 1; @@ -96,6 +98,8 @@ export async function Agent() { autoFinish: true, } ) { + const autoFinish = options.autoFinish ?? true; + console.log('Running plugin code...'); await page.evaluate((testingPlugin) => { (globalThis as any).ɵloadPlugin({ @@ -119,9 +123,11 @@ export async function Agent() { ); console.log('Save status found.'); - if (options.screenshot) { + if (options.screenshot && screenshotsEnable) { console.log('Taking screenshot:', options.screenshot); - await page.screenshot({ path: options.screenshot }); + await page.screenshot({ + path: 'screenshots/' + options.screenshot + '.png', + }); } return new Promise((resolve) => { @@ -137,7 +143,7 @@ export async function Agent() { resolve(result); - if (options.autoFinish) { + if (autoFinish) { console.log('Auto finish enabled. Cleaning up...'); finish(); } diff --git a/docs/test-e2e.md b/docs/test-e2e.md index 1a16d2f..692e862 100644 --- a/docs/test-e2e.md +++ b/docs/test-e2e.md @@ -9,6 +9,7 @@ ```env E2E_LOGIN_EMAIL="test@penpot.app" E2E_LOGIN_PASSWORD="123123123" + E2E_SCREENSHOTS= "true" ``` 2. **Run E2E Tests** @@ -57,7 +58,7 @@ ```ts const result = await agent.runCode(testingPlugin.toString(), { autoFinish: false, // default: true - screenshot: 'capture.png', // default: '' + screenshot: 'test-name', // default: '' }); // Finish will close the browser & delete the file