diff --git a/src/index.test.ts b/src/index.test.ts index a45ef12..b472f84 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -13,89 +13,80 @@ EOF curl smtp://localhost:2525 --mail-from publisher@example.com --mail-rcpt ru9rmeebswmcy7wx@localhost --upload-file /tmp/example-email.txt */ -import { beforeAll, afterAll, describe, test, expect } from "@jest/globals"; +import { 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 html from "@leafac/html"; import killTheNewsletter from "."; -let webServer: http.Server; -let emailServer: net.Server; -let webClient: got.Got; -let emailClient: nodemailer.Transporter; -let emailHost: string; -beforeAll(() => { +test("Kill the Newsletter!", async () => { + // Start servers 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( + const webServer = webApplication.listen( + new URL(webApplication.get("url")).port + ); + const emailServer = emailApplication.listen( new URL(webApplication.get("email")).port ); - webClient = got.default.extend({ prefixUrl: webApplication.get("url") }); - emailClient = nodemailer.createTransport(webApplication.get("email")); - emailHost = new URL(webApplication.get("url")).hostname; -}); -afterAll(() => { - webServer.close(); - emailServer.close(); -}); + const webClient = got.default.extend({ + prefixUrl: webApplication.get("url"), + }); + const emailClient = nodemailer.createTransport(webApplication.get("email")); + const emailHost = new URL(webApplication.get("url")).hostname; -test("Create feed", async () => { - const createResponseBody = ( - await webClient.post("", { form: { name: "A newsletter" } }) - ).body; - expect(createResponseBody).toMatch(`“A newsletter” inbox created`); - const feedReference = createResponseBody.match( - /\/feeds\/([a-z0-9]{16})\.xml/ - )![1]; - const feedResponse = await webClient.get(`feeds/${feedReference}.xml`); - expect(feedResponse.headers["content-type"]).toMatch("application/atom+xml"); - expect(feedResponse.headers["x-robots-tag"]).toBe("noindex"); - expect(feedResponse.body).toMatch(html`
Some HTML content
`, - }); - const feed = (await webClient.get(`feeds/${feedReference}.xml`)).body; - expect(feed.match(/Some HTML content
`}\nSome HTML content
`, }); + let feed = (await webClient.get(`feeds/${feedReference}.xml`)).body; + expect(feed.match(/Some HTML content
`}\n