mirror of
https://github.com/Mail-0/Zero.git
synced 2026-06-30 07:46:15 +00:00
1. Get both the better auth session tokens from appliations/cookies in .env <img width="852" height="316" alt="image" src="https://github.com/user-attachments/assets/0177c496-103c-4111-8a80-089d1f4a6f94" /> 2. Enter the email you wish to send to in .env 3. `cd packages/testing` 3. run `npm test:e2e:headed` thats it tbh https://github.com/user-attachments/assets/b703e78c-2373-40a2-b431-f9ba53d5d871 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Added Playwright end-to-end tests for the mail inbox flow, including authentication setup and email send/reply actions. - **New Features** - Added Playwright config, test scripts, and environment variables for E2E testing. - Implemented tests to sign in, send an email, and reply within the same session. <!-- End of auto-generated description by cubic. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **New Features** * Introduced a comprehensive testing package with support for unit, UI, and end-to-end tests. * Added Playwright-based authentication setup and mail inbox end-to-end test scripts. * Provided a dedicated test configuration and TypeScript setup for robust test execution. * **Chores** * Updated environment variable examples to support Playwright testing. * Enhanced main project scripts to facilitate various testing modes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
78 lines
2.4 KiB
TypeScript
78 lines
2.4 KiB
TypeScript
import { test as setup } from '@playwright/test';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const authFile = path.join(__dirname, '../playwright/.auth/user.json');
|
|
|
|
setup('inject real authentication session', async ({ page }) => {
|
|
console.log('Injecting real authentication session...');
|
|
|
|
const SessionToken = process.env.PLAYWRIGHT_SESSION_TOKEN;
|
|
const SessionData = process.env.PLAYWRIGHT_SESSION_DATA;
|
|
|
|
if (!SessionToken || !SessionData) {
|
|
throw new Error('PLAYWRIGHT_SESSION_TOKEN and PLAYWRIGHT_SESSION_DATA environment variables must be set.');
|
|
}
|
|
|
|
await page.goto('/', { waitUntil: 'domcontentloaded', timeout: 60000 });
|
|
|
|
console.log('Page loaded, setting up authentication...');
|
|
|
|
// sets better auth session cookies
|
|
await page.context().addCookies([
|
|
{
|
|
name: 'better-auth-dev.session_token',
|
|
value: SessionToken,
|
|
domain: 'localhost',
|
|
path: '/',
|
|
httpOnly: true,
|
|
secure: false,
|
|
sameSite: 'Lax'
|
|
},
|
|
{
|
|
name: 'better-auth-dev.session_data',
|
|
value: SessionData,
|
|
domain: 'localhost',
|
|
path: '/',
|
|
httpOnly: true,
|
|
secure: false,
|
|
sameSite: 'Lax'
|
|
}
|
|
]);
|
|
|
|
console.log('Real session cookies injected');
|
|
|
|
try {
|
|
const decodedSessionData = JSON.parse(atob(SessionData));
|
|
|
|
await page.addInitScript((sessionData) => {
|
|
if (sessionData.session) {
|
|
localStorage.setItem('better-auth.session', JSON.stringify(sessionData.session.session));
|
|
localStorage.setItem('better-auth.user', JSON.stringify(sessionData.session.user));
|
|
}
|
|
}, decodedSessionData);
|
|
|
|
console.log('Session data set in localStorage');
|
|
} catch (error) {
|
|
console.log('Could not decode session data for localStorage:', error);
|
|
}
|
|
|
|
await page.goto('/mail/inbox');
|
|
await page.waitForLoadState('domcontentloaded');
|
|
|
|
const currentUrl = page.url();
|
|
console.log('Current URL after clicking Get Started:', currentUrl);
|
|
|
|
if (currentUrl.includes('/mail')) {
|
|
console.log('Successfully reached mail app! On:', currentUrl);
|
|
} else {
|
|
console.log('Did not reach mail app. Current URL:', currentUrl);
|
|
await page.screenshot({ path: 'debug-auth-failed.png' });
|
|
}
|
|
|
|
await page.context().storageState({ path: authFile });
|
|
|
|
console.log('Real authentication session injected and saved!');
|
|
});
|