1.1.0 • Published 3 years ago
testcontainers-mailhog v1.1.0
Testcontainers-Mailhog
A testcontainers for mailhog
Install
https://www.npmjs.com/package/testcontainers-mailhog
npm i -D testcontainers-mailhogConfiguration
Logs
DEBUG=testcontainersEnable testcontainers logsDEBUG=testcontainers:containersEnable container logsDEBUG=testcontainers*Enable all logs
Testcontainers
TESTCONTAINERS_RYUK_DISABLED=trueDisable ryukRYUK_CONTAINER_IMAGE=registry.mycompany.com/mirror/ryuk:0.3.0Custom image for ryuk
Utility Methods of StartedMailhogContainer
.getAllMessages()Lists all messages excluding message content.getMessage(messageId)Returns an individual message including message content.deleteAllMessages()Deletes all messages.deleteMessage(messageId)Delete an individual message.getMappedSmtpPort()Get mapped smtp port, for configure smtp client.getMappedApiPort()Get mapped api port, if u want to invoke api manually
Usage
Test with vitest
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest'
import {
MailhogContainer,
StartedMailhogContainer
} from 'testcontainers-mailhog'
describe('Mailing test', () => {
let mailhogContainer: StartedMailhogContainer
beforeAll(async () => {
const imageName = 'harbor.yourcompany.com/mailhog'
mailhogContainer = await new MailhogContainer(imageName).start()
})
afterAll(async () => {
await mailhogContainer.stop()
})
afterEach(async () => {
await mailhogContainer.deleteAllMessages()
})
test('some case with mailing', async () => {
// const smtpUrl = `${mailhogContainer.getHost()}:${mailhogContainer.getMappedSmtpPort()}`
// ...
})
})See test cases for the example with nodemailer