Skip to content

Commit a41f1dc

Browse files
author
jackmahoney
committed
add-examples
1 parent 9b9b9d7 commit a41f1dc

File tree

8 files changed

+224
-68
lines changed

8 files changed

+224
-68
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ copy:
1212
deploy: build copy
1313
git push ci master
1414

15+
template-readme:
16+
DEBUG=script* npm run readme
17+
1518
build-shortcodes:
1619
DEBUG=script* npm run shortcodes
1720

1821
sync-shortcodes:
1922
aws s3 sync shortcodes/ s3://api-spec.mailslurp.com/shortcodes-github --exact-timestamps
2023

21-
publish: build-shortcodes sync-shortcodes
24+
publish: build-shortcodes sync-shortcodes template-readme

README.md

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,49 @@ This repository contains examples of [MailSlurp](https://www.mailslurp.com) usag
66

77
See developer page for [more guides and documentation](https://www.mailslurp.com/developers/). If you notice an issue in the examples please open an issue, pull request, or [contact support](https://www.mailslurp.com/support/).
88

9-
### Featured projects
10-
11-
| Project |
12-
| --- |
13-
| [Cypress JS Email Test](./javascript-cypress-js) |
14-
| [Cypress Mailslurp Plugin Email Test](./javascript-cypress-mailslurp-plugin) |
15-
| [Jest Puppeteer Email Test](./javascript-jest-puppeteer) |
16-
| [Testcafe Email Test](./javascript-testcafe) |
17-
| [Webdriver WDIO Email Test](./javascript-webdriver-io) |
18-
19-
## Example projects
20-
21-
### Golang
22-
23-
|---------|
24-
| Project |
25-
| --- |
26-
| [Golang Email Test](./golang-email-test) |
27-
28-
29-
### C\# (DotNet)
30-
31-
|---------|
32-
| Project |
33-
| --- |
34-
| [.NET 2.1 Selenium](./csharp-dotnet-core2-selenium) |
35-
| [.NET Core 3](./csharp-dotnet-core3) |
36-
| [.NET Core 5 Specflow Selenium](./csharp-specflow-mstest-selenium) |
37-
38-
### Javascript / Typescript
39-
40-
|---------|
41-
| Project |
42-
| --- |
43-
| [Axios Email Test](./javascript-axios) |
44-
| [Codecept JS Email Test](./javascript-codecept-js) |
45-
| [Cypress JS Email Test](./javascript-cypress-js) |
46-
| [Cypress Mailslurp Plugin Email Test](./javascript-cypress-mailslurp-plugin) |
47-
| [Jest Puppeteer Email Test](./javascript-jest-puppeteer) |
48-
| [Testcafe Email Test](./javascript-testcafe) |
49-
| [Webdriver WDIO Email Test](./javascript-webdriver-io) |
50-
51-
### PHP
52-
53-
|---------|
54-
| Project | Test status |
55-
| --- | --- |
56-
| [PHP Composer PHPUnit](./php-composer-phpunit) | ![php-composer-phpunit](https://github.com/mailslurp/examples/actions/workflows/php-composer-phpunit.yml/badge.svg?branch=master) |
57-
58-
### Python
59-
60-
|---------|
61-
| Project |
62-
| --- |
63-
| [Python2 PyTest](./python2-pytest) |
64-
| [Python3 Robot Framework](./python3-robotframework) |
65-
66-
### Ruby
67-
68-
|---------|
69-
| Project |
70-
| --- |
71-
| [Ruby RSpec email test](./ruby-rspec) |
9+
## Projects
10+
11+
- [csharp-dotnet-core2-selenium](/csharp-dotnet-core2-selenium)
12+
- [csharp-dotnet-core3](/csharp-dotnet-core3)
13+
- [csharp-smtp-client-xunit](/csharp-smtp-client-xunit)
14+
- [csharp-specflow-mstest-selenium](/csharp-specflow-mstest-selenium)
15+
- [dart-email-testing](/dart-email-testing)
16+
- [deno-email-api](/deno-email-api)
17+
- [elixir-phoenix-hound](/elixir-phoenix-hound)
18+
- [fsharp-email-mstest](/fsharp-email-mstest)
19+
- [golang-email-test](/golang-email-test)
20+
- [java-gradle-junit5](/java-gradle-junit5)
21+
- [java-maven-junit4](/java-maven-junit4)
22+
- [java-maven-selenium](/java-maven-selenium)
23+
- [java-serenity-jbehave](/java-serenity-jbehave)
24+
- [java-spring-boot](/java-spring-boot)
25+
- [java-testng-selenium](/java-testng-selenium)
26+
- [javascript-axios](/javascript-axios)
27+
- [javascript-codecept-js](/javascript-codecept-js)
28+
- [javascript-cypress-js](/javascript-cypress-js)
29+
- [javascript-cypress-mailslurp-plugin](/javascript-cypress-mailslurp-plugin)
30+
- [javascript-jest-puppeteer](/javascript-jest-puppeteer)
31+
- [javascript-testcafe](/javascript-testcafe)
32+
- [javascript-webdriver-io](/javascript-webdriver-io)
33+
- [kotlin-email-test-example](/kotlin-email-test-example)
34+
- [nim-unittests](/nim-unittests)
35+
- [nodejs-nodemailer-smtp-example](/nodejs-nodemailer-smtp-example)
36+
- [nodejs-smtp-email-attachments-test](/nodejs-smtp-email-attachments-test)
37+
- [php-codeception-acceptance](/php-codeception-acceptance)
38+
- [php-composer-phpunit](/php-composer-phpunit)
39+
- [php-laravel-email-examples](/php-laravel-email-examples)
40+
- [playwright-email-testing](/playwright-email-testing)
41+
- [playwright-sms-testing](/playwright-sms-testing)
42+
- [python2-pytest](/python2-pytest)
43+
- [python3-robotframework](/python3-robotframework)
44+
- [ruby-capybara-cucumber-selenium](/ruby-capybara-cucumber-selenium)
45+
- [ruby-cucumber-test](/ruby-cucumber-test)
46+
- [ruby-rspec](/ruby-rspec)
47+
- [rust-selenium-email-testing](/rust-selenium-email-testing)
48+
- [sendgrid](/sendgrid)
49+
- [shortcodes](/shortcodes)
50+
- [swift-email-smtp-examples](/swift-email-smtp-examples)
51+
- [visualbasic](/visualbasic)
7252

7353
## Running locally
7454
If you wish to run these examples yourself:

README.tpl.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# MailSlurp Examples 📨
2+
3+
> Create email addresses on demand then send and receive emails in code and tests. Test apps end-to-end with *real* email addresses
4+
5+
This repository contains examples of [MailSlurp](https://www.mailslurp.com) usage with a range of different languages and frameworks. See the `README.md` or `Makefile` in each module for more information.
6+
7+
See developer page for [more guides and documentation](https://www.mailslurp.com/developers/). If you notice an issue in the examples please open an issue, pull request, or [contact support](https://www.mailslurp.com/support/).
8+
9+
## Projects
10+
11+
{{#topLevelDirs}}
12+
- [{{.}}](/{{.}})
13+
{{/topLevelDirs}}
14+
15+
## Running locally
16+
If you wish to run these examples yourself:
17+
- clone the repository.
18+
- create an `.env` file in the root directory containing `API_KEY=your-mailslurp-api-key`.
19+
- to run an example `cd` into the directory and run `make test` or `API_KEY=your-api-key make test`.
20+
21+
## CI
22+
Examples are tested with each major release and on a schedule using Github actions and CircleCI.

javascript-cypress-mailslurp-plugin/README.md

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,80 @@
22
How to use MailSlurp with Cypress JS. Loads a demonstration app, signs up with a new email address, receives confirmation code, extracts code and submits. Sees welcome screen.
33

44
## Run
5-
`API_KEY=your-api-key make test`
5+
`API_KEY=your-api-key make test`
6+
7+
## Example test
8+
9+
```typescript
10+
/// <reference types="cypress-mailslurp" />
11+
12+
describe("user sign up test with mailslurp plugin", function () {
13+
//<gen>cypress_plugin_before
14+
// use cypress-mailslurp plugin to create an email address before test
15+
before(function () {
16+
cy.log("Wrap inbox before test")
17+
return cy.mailslurp()
18+
.then(mailslurp => mailslurp.createInbox())
19+
.then(inbox => {
20+
cy.log(`Inbox id ${inbox.id}`)
21+
// save inbox id and email address to this (make sure you use function and not arrow syntax)
22+
cy.wrap(inbox.id).as('inboxId')
23+
cy.wrap(inbox.emailAddress).as('emailAddress')
24+
})
25+
});
26+
//</gen>
27+
//<gen>cypress_plugin_01
28+
it("01 - can load the demo application", function () {
29+
// get wrapped email address and assert contains a mailslurp email address
30+
expect(this.emailAddress).to.contain("@mailslurp");
31+
// visit the demo application
32+
cy.visit("https://playground.mailslurp.com")
33+
cy.title().should('contain', 'React App');
34+
});
35+
//</gen>
36+
//<gen>cypress_plugin_02
37+
// use function instead of arrow syntax to access aliased values on this
38+
it("02 - can sign up using email address", function () {
39+
// click sign up and fill out the form
40+
cy.get("[data-test=sign-in-create-account-link]").click()
41+
// use the email address and a test password
42+
cy.get("[name=email]").type(this.emailAddress).trigger('change');
43+
cy.get("[name=password]").type('test-password').trigger('change');
44+
// click the submit button
45+
cy.get("[data-test=sign-up-create-account-button]").click();
46+
});
47+
//</gen>
48+
//<gen>cypress_plugin_03
49+
it("03 - can receive confirmation code by email", function () {
50+
// app will send user an email containing a code, use mailslurp to wait for the latest email
51+
cy.mailslurp()
52+
// use inbox id and a timeout of 30 seconds
53+
.then(mailslurp => mailslurp.waitForLatestEmail(this.inboxId, 30000, true))
54+
// extract the confirmation code from the email body
55+
.then(email => /.*verification code is (\d{6}).*/.exec(email.body!!)!![1])
56+
// fill out the confirmation form and submit
57+
.then(code => {
58+
cy.get("[name=code]").type(code).trigger('change');
59+
cy.get("[data-test=confirm-sign-up-confirm-button]").click();
60+
})
61+
});
62+
//</gen>
63+
//<gen>cypress_plugin_04
64+
// fill out sign in form
65+
it("04 - can sign in with confirmed account", function () {
66+
// use the email address and a test password
67+
cy.get("[data-test=username-input]").type(this.emailAddress).trigger('change');
68+
cy.get("[data-test=sign-in-password-input]").type('test-password').trigger('change');
69+
// click the submit button
70+
cy.get("[data-test=sign-in-sign-in-button]").click();
71+
});
72+
//</gen>
73+
//<gen>cypress_plugin_05
74+
// can see authorized welcome screen
75+
it("05 - can see welcome screen", function () {
76+
// click sign up and fill out the form
77+
cy.get("h1").should("contain", "Welcome");
78+
});
79+
//</gen>
80+
});
81+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Cypress MailSlurp plugin example
2+
How to use MailSlurp with Cypress JS. Loads a demonstration app, signs up with a new email address, receives confirmation code, extracts code and submits. Sees welcome screen.
3+
4+
## Run
5+
`API_KEY=your-api-key make test`
6+
7+
## Example test
8+
9+
{{{<gen_typescript_cypress_plugin_full>}}}

package-lock.json

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
"ts-node": "^10.9.1"
66
},
77
"scripts": {
8-
"shortcodes": "node --loader ts-node/esm shortcodes.ts"
8+
"shortcodes": "node --loader ts-node/esm shortcodes.ts",
9+
"readme": "node --loader ts-node/esm readme.ts"
910
},
1011
"devDependencies": {
11-
"@types/debug": "^4.1.7"
12+
"@types/debug": "^4.1.7",
13+
"@types/mustache": "^4.2.1",
14+
"mustache": "^4.2.0"
1215
}
1316
}

readme.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import debug from "debug";
2+
import * as fs from "fs";
3+
import {join} from "path";
4+
import glob from "fast-glob";
5+
import Mustache from "mustache";
6+
const log = debug("scripts/readme");
7+
8+
(async function() {
9+
log("Run readme")
10+
const gitignoreLines = (await fs.promises.readFile(join(__dirname, "/.gitignore"))).toString().split("\n").filter(it => it).sort()
11+
const topLevelDirs = await glob([join(__dirname,'/*')], {onlyDirectories:true, ignore: gitignoreLines})
12+
const readmes = await glob([join(__dirname, "/**/README.tpl.md")])
13+
const data: {[key:string]: any} = {
14+
topLevelDirs: topLevelDirs.map(it => it.split('/').slice(-1)[0])
15+
}
16+
const shortcodes = await glob([join(__dirname, '/shortcodes/gen*.html')])
17+
for (const shortcode of shortcodes) {
18+
const endpart = shortcode.split("/").slice(-1)[0]
19+
const key = '<' + endpart.replace('.html','') + '>';
20+
data[key] = (await fs.promises.readFile(shortcode)).toString()
21+
}
22+
for (const readme of readmes) {
23+
const readmeContent = (await fs.promises.readFile(readme)).toString()
24+
const content = Mustache.render(readmeContent, data);
25+
const newPath = readme.replace('.tpl', '')
26+
log("Writing new template " + newPath)
27+
await fs.promises.writeFile(newPath, content)
28+
}
29+
})().catch((err) => {
30+
log(`ERROR: ${err}`, err);
31+
process.exit(1);
32+
});
33+
34+
export {};

0 commit comments

Comments
 (0)