Skip to content

Commit c77cf60

Browse files
authored
Move emailService to fixture for e2e tests (#891)
Individual tests should not need to know which email service is being used. That should be defined at the e2e test suite configuration level. This change adds an emailService fixture using Playwright fixtures with the default using MessageChecker.
1 parent 8c2f63d commit c77cf60

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { test as base } from '@playwright/test';
2+
import { EmailService } from '../lib/services/email/EmailService';
3+
import { MessageCheckerService } from '../lib/services/email/MessageCheckerService';
4+
import { MailinatorService } from '../lib/services/email/MailinatorService';
5+
6+
type EmailServiceOptions = {
7+
emailServiceType: string
8+
};
9+
10+
type EmailServiceFixtures = {
11+
emailService: EmailService;
12+
};
13+
14+
export const test = base.extend<EmailServiceOptions & EmailServiceFixtures>({
15+
emailServiceType: ['MessageChecker', { option: true }],
16+
emailService: async ({ emailServiceType, context }, use) => {
17+
let emailService: EmailService;
18+
if (emailServiceType === 'MessageChecker') {
19+
emailService = new MessageCheckerService(context);
20+
} else if (emailServiceType === 'Mailinator') {
21+
emailService = new MailinatorService(context);
22+
} else {
23+
throw new Error(`Unknown email service type: ${emailServiceType}`);
24+
}
25+
await use(emailService);
26+
}
27+
});

e2e/fixtures/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { mergeTests } from "@playwright/test";
2+
import { test as emailServiceTest } from "./email-service-fixture";
3+
4+
export const test = mergeTests(emailServiceTest);

e2e/{{app_name}}/playwright.config.js.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export default defineConfig(deepMerge(
66
baseConfig,
77
{
88
use: {
9-
baseURL: baseConfig.use.baseURL || "localhost:{{ app_local_port }}"
9+
baseURL: baseConfig.use.baseURL || "localhost:{{ app_local_port }}",
10+
// emailServiceType: "Mailinator", // Options: ["MessageChecker", "Mailinator"]. Default: "MessageChecker"
1011
},
1112
}
1213
));

0 commit comments

Comments
 (0)