diff --git a/configuration.local.js b/configuration.local.js index 4151754..1efcd1f 100644 --- a/configuration.local.js +++ b/configuration.local.js @@ -6,9 +6,7 @@ module.exports = (require) => { console.log(`Web server started at ${webApplication.get("url")}`); }); - emailApplication.listen(webApplication.get("email port"), () => { - console.log( - `Email server started on port ${webApplication.get("email port")}` - ); + emailApplication.listen(new URL(webApplication.get("email")).port, () => { + console.log(`Email server started at port ${webApplication.get("email")}`); }); }; diff --git a/src/index.test.ts b/src/index.test.ts index 8c063e1..4aa7fcb 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,8 +1,33 @@ -import { webServer, emailServer, BASE_URL, EMAIL_DOMAIN, EMAIL_PORT } from "."; +import { beforeAll, afterAll, describe, test, expect } from "@jest/globals"; +import os from "os"; +import path from "path"; +import http from "http"; +import net from "net"; +import fs from "fs"; +import * as got from "got"; import nodemailer from "nodemailer"; -import axios from "axios"; -import qs from "qs"; -import { JSDOM } from "jsdom"; +import killTheNewsletter from "."; + +let webServer: http.Server; +let emailServer: net.Server; +let webClient: got.Got; +let emailClient: nodemailer.Transporter; +beforeAll(() => { + const rootDirectory = fs.mkdtempSync( + path.join(os.tmpdir(), "kill-the-newsletter--test--") + ); + const { webApplication, emailApplication } = killTheNewsletter(rootDirectory); + webServer = webApplication.listen(new URL(webApplication.get("url")).port); + emailServer = emailApplication.listen( + new URL(webApplication.get("email")).port + ); + webClient = got.default.extend({ prefixUrl: webApplication.get("url") }); + emailClient = nodemailer.createTransport(webApplication.get("email")); +}); +afterAll(() => { + webServer.close(); + emailServer.close(); +}); test("create feed", async () => { const identifier = await createFeed(); @@ -235,12 +260,6 @@ test("‘noindex’ header", async () => { ); }); -const webClient = axios.create({ - baseURL: BASE_URL, -}); -const emailClient = nodemailer.createTransport( - `smtp://${EMAIL_DOMAIN}:${EMAIL_PORT}` -); afterAll(() => { webServer.close(); emailServer.close(); diff --git a/src/index.ts b/src/index.ts index faea50c..5fc37ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,8 +20,7 @@ export default function killTheNewsletter( const webApplication = express(); webApplication.set("url", "http://localhost:4000"); - webApplication.set("email port", 2525); - webApplication.set("email host", "localhost"); + webApplication.set("email", "smtp://localhost:2525"); webApplication.set("administrator", "mailto:kill-the-newsletter@leafac.com"); fs.ensureDirSync(rootDirectory); @@ -287,7 +286,8 @@ export default function killTheNewsletter(
Sign up for the newsletter with
${feedReference}@${webApplication.get("email host")}
${feedReference}@${new URL(webApplication.get("email"))
+ .hostname}
@@ -376,7 +376,7 @@ export default function killTheNewsletter(