0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-04 13:50:13 -05:00

feat(e2e): add screenshots ENV variable

This commit is contained in:
Juanfran 2024-09-23 10:25:09 +02:00
parent ade39eebe2
commit 9292bf286b
13 changed files with 446 additions and 410 deletions

View file

@ -1,2 +1,3 @@
E2E_LOGIN_EMAIL="" E2E_LOGIN_EMAIL=""
E2E_LOGIN_PASSWORD="" E2E_LOGIN_PASSWORD=""
E2E_SCREENSHOTS= "false"

3
.gitignore vendored
View file

@ -47,3 +47,6 @@ Thumbs.db
**/assets/plugin.js **/assets/plugin.js
docs/api docs/api
apps/e2e/screenshots/*.png

View file

File diff suppressed because it is too large Load diff

View file

@ -11,31 +11,41 @@ import { Agent } from './utils/agent';
describe('Plugins', () => { describe('Plugins', () => {
it('create board - text - rectable', async () => { it('create board - text - rectable', async () => {
const agent = await Agent(); 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(); expect(result).toMatchSnapshot();
}); });
it('create flex layout', async () => { it('create flex layout', async () => {
const agent = await Agent(); const agent = await Agent();
const result = await agent.runCode(flex.toString()); const result = await agent.runCode(flex.toString(), {
screenshot: 'create-flexlayout',
});
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
it('create grid layout', async () => { it('create grid layout', async () => {
const agent = await Agent(); const agent = await Agent();
const result = await agent.runCode(grid.toString()); const result = await agent.runCode(grid.toString(), {
screenshot: 'create-gridlayout',
});
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
it('group and ungroup', async () => { it('group and ungroup', async () => {
const agent = await Agent(); const agent = await Agent();
const result = await agent.runCode(group.toString()); const result = await agent.runCode(group.toString(), {
screenshot: 'group-ungroup',
});
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
it('insert svg', async () => { it('insert svg', async () => {
const agent = await Agent(); const agent = await Agent();
const result = await agent.runCode(insertSvg.toString()); const result = await agent.runCode(insertSvg.toString(), {
screenshot: 'insert-svg',
});
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
@ -47,13 +57,17 @@ describe('Plugins', () => {
it('component library', async () => { it('component library', async () => {
const agent = await Agent(); const agent = await Agent();
const result = await agent.runCode(componentLibrary.toString()); const result = await agent.runCode(componentLibrary.toString(), {
screenshot: 'component-library',
});
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
it('text and textrange', async () => { it('text and textrange', async () => {
const agent = await Agent(); const agent = await Agent();
const result = await agent.runCode(createText.toString()); const result = await agent.runCode(createText.toString(), {
screenshot: 'create-text',
});
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
}); });

View file

@ -1,7 +1,10 @@
export default function () { export default function () {
const rectangle = penpot.createRectangle(); const rectangle = penpot.createRectangle();
rectangle.x = penpot.viewport.center.x;
rectangle.y = penpot.viewport.center.y;
const shape = penpot.getPage()?.getShapeById(rectangle.id); const shape = penpot.getPage()?.getShapeById(rectangle.id);
if (shape) { if (shape) {
penpot.library.local.createComponent(shape); penpot.library.local.createComponent([shape]);
} }
} }

View file

@ -32,8 +32,6 @@ export default function () {
board.name = 'Board name'; board.name = 'Board name';
console.log(penpot.viewport.center.x);
board.x = penpot.viewport.center.x; board.x = penpot.viewport.center.x;
board.y = penpot.viewport.center.y; board.y = penpot.viewport.center.y;
@ -54,7 +52,7 @@ export default function () {
return board; return board;
} }
createText('Hello from plugin');
createRectangle();
createBoard(); createBoard();
createRectangle();
createText('Hello from plugin');
} }

View file

@ -4,6 +4,9 @@ export default function () {
board.horizontalSizing = 'auto'; board.horizontalSizing = 'auto';
board.verticalSizing = 'auto'; board.verticalSizing = 'auto';
board.x = penpot.viewport.center.x;
board.y = penpot.viewport.center.y;
const flex = board.addFlexLayout(); const flex = board.addFlexLayout();
flex.dir = 'column'; flex.dir = 'column';

View file

@ -1,6 +1,8 @@
export default function () { export default function () {
function createGridLayout(): void { function createGridLayout(): void {
const board = penpot.createBoard(); const board = penpot.createBoard();
board.x = penpot.viewport.center.x;
board.y = penpot.viewport.center.y;
const grid = board.addGridLayout(); const grid = board.addGridLayout();

View file

@ -1,22 +1,23 @@
export default function () { export default function () {
function createText(): void { function createText(): void {
const text = penpot.createText('Hello World!'); const text = penpot.createText('Hello World!');
if (text) { if (text) {
text.growType = 'auto-width'; text.x = penpot.viewport.center.x;
text.textTransform = 'uppercase'; text.y = penpot.viewport.center.y;
text.textDecoration = 'underline'; text.growType = 'auto-width';
text.fontId = 'gfont-work-sans'; text.textTransform = 'uppercase';
text.fontStyle = 'italic'; text.textDecoration = 'underline';
text.fontSize = '20'; text.fontId = 'gfont-work-sans';
text.fontWeight = '500'; text.fontStyle = 'italic';
text.fontSize = '20';
const textRange = text.getRange(0, 5); text.fontWeight = '500';
textRange.fontSize = '40';
textRange.fills = [{ fillColor: '#ff6fe0', fillOpacity: 1 }]; const textRange = text.getRange(0, 5);
} textRange.fontSize = '40';
textRange.fills = [{ fillColor: '#ff6fe0', fillOpacity: 1 }];
} }
createText();
} }
createText();
}

View file

@ -16,7 +16,11 @@ export default function () {
} }
const rectangle = penpot.createRectangle(); const rectangle = penpot.createRectangle();
rectangle.x = penpot.viewport.center.x;
rectangle.y = penpot.viewport.center.y;
const rectangle2 = penpot.createRectangle(); const rectangle2 = penpot.createRectangle();
rectangle2.x = penpot.viewport.center.x + 100;
rectangle2.y = penpot.viewport.center.y + 100;
penpot.selection = [rectangle, rectangle2]; penpot.selection = [rectangle, rectangle2];

View file

@ -4,6 +4,8 @@ import { getFileUrl } from './get-file-url';
import { idObjectToArray } from './clean-id'; import { idObjectToArray } from './clean-id';
import { Shape } from '../models/shape.model'; import { Shape } from '../models/shape.model';
const screenshotsEnable = process.env['E2E_SCREENSHOTS'] === 'true';
function replaceIds(shapes: Shape[]) { function replaceIds(shapes: Shape[]) {
let id = 1; let id = 1;
@ -96,6 +98,8 @@ export async function Agent() {
autoFinish: true, autoFinish: true,
} }
) { ) {
const autoFinish = options.autoFinish ?? true;
console.log('Running plugin code...'); console.log('Running plugin code...');
await page.evaluate((testingPlugin) => { await page.evaluate((testingPlugin) => {
(globalThis as any).ɵloadPlugin({ (globalThis as any).ɵloadPlugin({
@ -119,9 +123,11 @@ export async function Agent() {
); );
console.log('Save status found.'); console.log('Save status found.');
if (options.screenshot) { if (options.screenshot && screenshotsEnable) {
console.log('Taking screenshot:', options.screenshot); console.log('Taking screenshot:', options.screenshot);
await page.screenshot({ path: options.screenshot }); await page.screenshot({
path: 'screenshots/' + options.screenshot + '.png',
});
} }
return new Promise((resolve) => { return new Promise((resolve) => {
@ -137,7 +143,7 @@ export async function Agent() {
resolve(result); resolve(result);
if (options.autoFinish) { if (autoFinish) {
console.log('Auto finish enabled. Cleaning up...'); console.log('Auto finish enabled. Cleaning up...');
finish(); finish();
} }

View file

@ -9,6 +9,7 @@
```env ```env
E2E_LOGIN_EMAIL="test@penpot.app" E2E_LOGIN_EMAIL="test@penpot.app"
E2E_LOGIN_PASSWORD="123123123" E2E_LOGIN_PASSWORD="123123123"
E2E_SCREENSHOTS= "true"
``` ```
2. **Run E2E Tests** 2. **Run E2E Tests**
@ -57,7 +58,7 @@
```ts ```ts
const result = await agent.runCode(testingPlugin.toString(), { const result = await agent.runCode(testingPlugin.toString(), {
autoFinish: false, // default: true autoFinish: false, // default: true
screenshot: 'capture.png', // default: '' screenshot: 'test-name', // default: ''
}); });
// Finish will close the browser & delete the file // Finish will close the browser & delete the file