https://github.com/anton-johansson/smtp-mock-server
Provides a mock SMTP server that can be used to verify and look at e-mails in end-to-end test. It provides a JSON API to await received e-mails.
https://github.com/anton-johansson/smtp-mock-server
e2e-testing end-to-end-testing mock-server nodejs smtp
Last synced: 4 months ago
JSON representation
Provides a mock SMTP server that can be used to verify and look at e-mails in end-to-end test. It provides a JSON API to await received e-mails.
- Host: GitHub
- URL: https://github.com/anton-johansson/smtp-mock-server
- Owner: anton-johansson
- License: mit
- Created: 2023-08-18T09:23:18.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-19T10:13:44.000Z (almost 2 years ago)
- Last Synced: 2024-12-26T23:43:49.203Z (6 months ago)
- Topics: e2e-testing, end-to-end-testing, mock-server, nodejs, smtp
- Language: TypeScript
- Homepage:
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SMTP mock server
Provides a mock SMTP server that can be used to verify and look at e-mails in end-to-end test. It provides a JSON API to await received e-mails.
## Running
```sh
$ npx @anton-johansson/smtp-mock-server
```#### Options
| Switch | Description |
| -------------------- | --------------------------------------------------------- |
| `--smtp-port ` | The port to serve the SMTP server on. Defaults to `3025`. |
| `--api-port ` | The port to serve the API on. Defaults to `3080`. |## Example setup
`package.json`:
```json
{
"scripts": {
"start": "node dist/index.js",
"test:e2e": "npx playwright test",
"test:e2e-ci": "start-test start 3000 'npx @anton-johansson/smtp-mock-server' 3080 test:e2e"
},
"devDependencies": {
"start-server-and-test": "2.0.0"
}
}
```Then simply run `npm run test:e2e-ci` on your continuous integration server. It will fire up your server, the SMTP mock server, run the tests and then shut down the servers again.
## API
### Await e-mail
```sh
$ curl http://localhost:3080/await-email?subject=Hello
```#### Parameters
| Query parameter key | Description |
| ------------------- | ---------------------------------------------------------------------------------------- |
| `subject` | Optional subject to filter by when awaiting e-mail. |
| `timeout` | The number of milliseconds to wait for the e-mail. Defaults to `5000`. |
| `remove` | Whether or not to remove the email from the list after receiving it. Defaults to `true`. |### Clear e-mails
This one is not really useful during the actual end-to-end tests, but it can be useful to clear the e-mails before starting the tests when running tests locally.
```shell
$ curl -XPOST http://localhost:3080/clear-emails
```