mirror of https://github.com/penpot/penpot.git
1.9 KiB
1.9 KiB
End-to-End (E2E) Testing Guide
Setting Up
-
Configure Environment Variables
Create and populate the
.envfile with a valid user mail & password:E2E_LOGIN_EMAIL="test@penpot.app" E2E_LOGIN_PASSWORD="123123123" E2E_SCREENSHOTS= "true" -
Run E2E Tests
Use the following command to execute the E2E tests:
npm run test:e2e
Writing Tests
-
Adding Tests
Place your test files in the
/apps/e2e/src/**/*.spec.tsdirectory. Below is an example of a test file:import testingPlugin from './plugins/create-board-text-rect'; import { Agent } from './utils/agent'; describe('Plugins', () => { it('create board - text - rectangle', async () => { const agent = await Agent(); const result = await agent.runCode(testingPlugin.toString()); expect(result).toMatchSnapshot(); }); });Explanation:
Agentopens a browser, logs into Penpot, and creates a file.runCodeexecutes the plugin code and returns the file state after execution.
-
Using
runCodeMethodThe
runCodemethod takes the plugin code as a string:const result = await agent.runCode(testingPlugin.toString());It can also accept an options object:
const result = await agent.runCode(testingPlugin.toString(), { autoFinish: false, // default: true screenshot: 'test-name', // default: '' }); // Finish will close the browser & delete the file agent.finish(); -
Snapshot Testing
The
toMatchSnapshotmethod stores the result and throws an error if the content does not match the previous result:expect(result).toMatchSnapshot();Snapshots are stored in the
apps/e2e/src/__snapshots__/*.spec.ts.snapdirectory.If you need to refresh all the snapshopts run the test with the update option:
npm run test:e2e -- --update