From e539dfe168a6cb3fdd2637542e7c28833cc76d94 Mon Sep 17 00:00:00 2001 From: dojyorin Date: Tue, 30 Jan 2024 19:29:17 +0900 Subject: [PATCH] test improved. --- deps.test.ts | 5 ++++- test/deno_ext/smtp.test.ts | 35 ++++++++++++++++++++++++----------- test/pure/fetch.test.ts | 4 ++-- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/deps.test.ts b/deps.test.ts index f80a193..74e243c 100644 --- a/deps.test.ts +++ b/deps.test.ts @@ -1,5 +1,8 @@ export {assertEquals} from "https://deno.land/std@0.213.0/assert/mod.ts"; export {dirname, fromFileUrl} from "https://deno.land/std@0.213.0/path/mod.ts"; export {exists} from "https://deno.land/std@0.213.0/fs/mod.ts"; +export {delay} from "https://deno.land/std@0.213.0/async/mod.ts"; -export {DOMParser} from "https://deno.land/x/deno_dom@v0.1.43/deno-dom-wasm.ts"; \ No newline at end of file +export {DOMParser} from "https://deno.land/x/deno_dom@v0.1.43/deno-dom-wasm.ts"; + +export {init as smtpTest} from "npm:smtp-tester@2.1.0"; \ No newline at end of file diff --git a/test/deno_ext/smtp.test.ts b/test/deno_ext/smtp.test.ts index 66e2ce3..0b40f93 100644 --- a/test/deno_ext/smtp.test.ts +++ b/test/deno_ext/smtp.test.ts @@ -1,20 +1,33 @@ -import {assertEquals} from "../../deps.test.ts"; -import {smtpSend} from "../../src/deno_ext/smtp.ts"; +import {assertEquals, delay, smtpTest} from "../../deps.test.ts"; +import {type MailMessage, smtpSend} from "../../src/deno_ext/smtp.ts"; -const cs = ""; -const em = ""; +const sample:MailMessage = { + from: "from@example.com", + to: ["to@example.com"], + title: "Test title", + body: "Test body" +}; Deno.test({ - ignore: true, name: "SMTP: Send", async fn(){ - await smtpSend(cs, { - from: em, - to: [em], - title: "CI Test", - body: "CI Test" + const server = smtpTest(10025); + const result = new Promise((res)=>{ + server.bind((_, __, {headers, body})=>{ + res({ + from: headers.from, + to: [headers.to], + title: headers.subject, + body: body ?? "" + }); + }); }); - assertEquals(true, true); + await smtpSend("smtp://127.0.0.1:10025", sample); + await new Promise(done => server.stop(done)); + + assertEquals(await result, sample); + + await delay(1000); } }); \ No newline at end of file diff --git a/test/pure/fetch.test.ts b/test/pure/fetch.test.ts index 9bdaa98..4d5990f 100644 --- a/test/pure/fetch.test.ts +++ b/test/pure/fetch.test.ts @@ -13,10 +13,10 @@ Deno.test({ async fn(){ const server = Deno.serve({ hostname: "127.0.0.1", - port: 62000, + port: 10080, }, () => new Response(sample)); - const result = await fetchExtend("http://127.0.0.1:62000", "byte"); + const result = await fetchExtend("http://127.0.0.1:10080", "byte"); await server.shutdown(); assertEquals(result, sample);