Skip to content

Commit dabdbbd

Browse files
committed
test/message: accomodate slow parsing
1 parent 01cada3 commit dabdbbd

File tree

1 file changed

+147
-121
lines changed

1 file changed

+147
-121
lines changed

test/message.ts

Lines changed: 147 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,107 @@ test.after(async (t) => {
7979
server.close(t.pass);
8080
});
8181

82-
test('simple text message', async (t) => {
82+
test.serial('message validation fails without `from` header', async (t) => {
83+
const msg = new Message({});
84+
const { isValid, validationError } = msg.checkValidity();
85+
t.false(isValid);
86+
t.is(validationError, 'Message must have a `from` header');
87+
});
88+
89+
test.serial(
90+
'message validation fails without `to`, `cc`, or `bcc` header',
91+
async (t) => {
92+
const { isValid, validationError } = new Message({
93+
94+
}).checkValidity();
95+
96+
t.false(isValid);
97+
t.is(
98+
validationError,
99+
'Message must have at least one `to`, `cc`, or `bcc` header'
100+
);
101+
}
102+
);
103+
104+
test.serial(
105+
'message validation succeeds with only `to` recipient header (string)',
106+
async (t) => {
107+
const { isValid, validationError } = new Message({
108+
109+
110+
}).checkValidity();
111+
112+
t.true(isValid);
113+
t.is(validationError, undefined);
114+
}
115+
);
116+
117+
test.serial(
118+
'message validation succeeds with only `to` recipient header (array)',
119+
async (t) => {
120+
const { isValid, validationError } = new Message({
121+
122+
123+
}).checkValidity();
124+
125+
t.true(isValid);
126+
t.is(validationError, undefined);
127+
}
128+
);
129+
130+
test.serial(
131+
'message validation succeeds with only `cc` recipient header (string)',
132+
async (t) => {
133+
const { isValid, validationError } = new Message({
134+
135+
136+
}).checkValidity();
137+
138+
t.true(isValid);
139+
t.is(validationError, undefined);
140+
}
141+
);
142+
143+
test.serial(
144+
'message validation succeeds with only `cc` recipient header (array)',
145+
async (t) => {
146+
const { isValid, validationError } = new Message({
147+
148+
149+
}).checkValidity();
150+
151+
t.true(isValid);
152+
t.is(validationError, undefined);
153+
}
154+
);
155+
156+
test.serial(
157+
'message validation succeeds with only `bcc` recipient header (string)',
158+
async (t) => {
159+
const { isValid, validationError } = new Message({
160+
161+
162+
}).checkValidity();
163+
164+
t.true(isValid);
165+
t.is(validationError, undefined);
166+
}
167+
);
168+
169+
test.serial(
170+
'message validation succeeds with only `bcc` recipient header (array)',
171+
async (t) => {
172+
const { isValid, validationError } = new Message({
173+
174+
175+
}).checkValidity();
176+
177+
t.true(isValid);
178+
t.is(validationError, undefined);
179+
}
180+
);
181+
182+
test.serial('simple text message', async (t) => {
83183
const msg = {
84184
subject: 'this is a test TEXT message from emailjs',
85185
@@ -98,7 +198,7 @@ test('simple text message', async (t) => {
98198
t.is(mail.messageId, '<' + msg['message-id'] + '>');
99199
});
100200

101-
test('null text message', async (t) => {
201+
test.serial('null text message', async (t) => {
102202
const msg = {
103203
subject: 'this is a test TEXT message from emailjs',
104204
@@ -111,7 +211,7 @@ test('null text message', async (t) => {
111211
t.is(mail.text, '\n\n\n');
112212
});
113213

114-
test('empty text message', async (t) => {
214+
test.serial('empty text message', async (t) => {
115215
const msg = {
116216
subject: 'this is a test TEXT message from emailjs',
117217
@@ -124,7 +224,7 @@ test('empty text message', async (t) => {
124224
t.is(mail.text, '\n\n\n');
125225
});
126226

127-
test('simple unicode text message', async (t) => {
227+
test.serial('simple unicode text message', async (t) => {
128228
const msg = {
129229
subject: 'this ✓ is a test ✓ TEXT message from emailjs',
130230
from: 'zelda✓ <[email protected]>',
@@ -139,45 +239,7 @@ test('simple unicode text message', async (t) => {
139239
t.is(mail.to?.text, msg.to);
140240
});
141241

142-
test('very large text message', async (t) => {
143-
// thanks to jart+loberstech for this one!
144-
const msg = {
145-
subject: 'this is a test TEXT message from emailjs',
146-
147-
148-
text: textFixture,
149-
};
150-
151-
const mail = await send(msg);
152-
t.is(mail.text, msg.text.replace(/\r/g, '') + '\n\n\n');
153-
t.is(mail.subject, msg.subject);
154-
t.is(mail.from?.text, msg.from);
155-
t.is(mail.to?.text, msg.to);
156-
});
157-
158-
test('very large text data message', async (t) => {
159-
const text = '<html><body><pre>' + textFixture + '</pre></body></html>';
160-
161-
const msg = {
162-
subject: 'this is a test TEXT+DATA message from emailjs',
163-
164-
165-
text: 'hello friend if you are seeing this, you can not view html emails. it is attached inline.',
166-
attachment: {
167-
data: text,
168-
alternative: true,
169-
},
170-
};
171-
172-
const mail = await send(msg);
173-
t.is(mail.html, text.replace(/\r/g, ''));
174-
t.is(mail.text, msg.text + '\n');
175-
t.is(mail.subject, msg.subject);
176-
t.is(mail.from?.text, msg.from);
177-
t.is(mail.to?.text, msg.to);
178-
});
179-
180-
test('html data message', async (t) => {
242+
test.serial('html data message', async (t) => {
181243
const msg = {
182244
subject: 'this is a test TEXT+HTML+DATA message from emailjs',
183245
@@ -196,7 +258,7 @@ test('html data message', async (t) => {
196258
t.is(mail.to?.text, msg.to);
197259
});
198260

199-
test('html file message', async (t) => {
261+
test.serial('html file message', async (t) => {
200262
const msg = {
201263
subject: 'this is a test TEXT+HTML+FILE message from emailjs',
202264
@@ -215,7 +277,7 @@ test('html file message', async (t) => {
215277
t.is(mail.to?.text, msg.to);
216278
});
217279

218-
test('html with image embed message', async (t) => {
280+
test.serial('html with image embed message', async (t) => {
219281
const htmlFixture2Url = new URL('attachments/smtp2.html', import.meta.url);
220282
const imageFixtureUrl = new URL('attachments/smtp.gif', import.meta.url);
221283
const msg = {
@@ -248,7 +310,7 @@ test('html with image embed message', async (t) => {
248310
t.is(mail.to?.text, msg.to);
249311
});
250312

251-
test('html data and attachment message', async (t) => {
313+
test.serial('html data and attachment message', async (t) => {
252314
const msg = {
253315
subject: 'this is a test TEXT+HTML+FILE message from emailjs',
254316
@@ -270,7 +332,7 @@ test('html data and attachment message', async (t) => {
270332
t.is(mail.to?.text, msg.to);
271333
});
272334

273-
test('attachment message', async (t) => {
335+
test.serial('attachment message', async (t) => {
274336
const msg = {
275337
subject: 'this is a test TEXT+ATTACHMENT message from emailjs',
276338
@@ -291,7 +353,7 @@ test('attachment message', async (t) => {
291353
t.is(mail.to?.text, msg.to);
292354
});
293355

294-
test('attachment sent with unicode filename message', async (t) => {
356+
test.serial('attachment sent with unicode filename message', async (t) => {
295357
const msg = {
296358
subject: 'this is a test TEXT+ATTACHMENT message from emailjs',
297359
@@ -313,7 +375,7 @@ test('attachment sent with unicode filename message', async (t) => {
313375
t.is(mail.to?.text, msg.to);
314376
});
315377

316-
test('attachments message', async (t) => {
378+
test.serial('attachments message', async (t) => {
317379
const msg = {
318380
subject: 'this is a test TEXT+2+ATTACHMENTS message from emailjs',
319381
@@ -342,7 +404,9 @@ test('attachments message', async (t) => {
342404
t.is(mail.to?.text, msg.to);
343405
});
344406

345-
test('streams message', async (t) => {
407+
test.serial('streams message', async (t) => {
408+
t.timeout(15000);
409+
346410
const msg = {
347411
subject: 'this is a test TEXT+2+STREAMED+ATTACHMENTS message from emailjs',
348412
@@ -375,81 +439,43 @@ test('streams message', async (t) => {
375439
t.is(mail.to?.text, msg.to);
376440
});
377441

378-
test('message validation fails without `from` header', async (t) => {
379-
const msg = new Message({});
380-
const { isValid, validationError } = msg.checkValidity();
381-
t.false(isValid);
382-
t.is(validationError, 'Message must have a `from` header');
383-
});
384-
385-
test('message validation fails without `to`, `cc`, or `bcc` header', async (t) => {
386-
const { isValid, validationError } = new Message({
387-
388-
}).checkValidity();
442+
// thanks to jart+loberstech for this one!
443+
test.serial('very large text message', async (t) => {
444+
t.timeout(15000);
389445

390-
t.false(isValid);
391-
t.is(
392-
validationError,
393-
'Message must have at least one `to`, `cc`, or `bcc` header'
394-
);
395-
});
396-
397-
test('message validation succeeds with only `to` recipient header (string)', async (t) => {
398-
const { isValid, validationError } = new Message({
399-
400-
401-
}).checkValidity();
402-
403-
t.true(isValid);
404-
t.is(validationError, undefined);
405-
});
406-
407-
test('message validation succeeds with only `to` recipient header (array)', async (t) => {
408-
const { isValid, validationError } = new Message({
409-
410-
411-
}).checkValidity();
412-
413-
t.true(isValid);
414-
t.is(validationError, undefined);
415-
});
416-
417-
test('message validation succeeds with only `cc` recipient header (string)', async (t) => {
418-
const { isValid, validationError } = new Message({
419-
420-
421-
}).checkValidity();
422-
423-
t.true(isValid);
424-
t.is(validationError, undefined);
425-
});
426-
427-
test('message validation succeeds with only `cc` recipient header (array)', async (t) => {
428-
const { isValid, validationError } = new Message({
429-
430-
431-
}).checkValidity();
446+
const msg = {
447+
subject: 'this is a test TEXT message from emailjs',
448+
449+
450+
text: textFixture,
451+
};
432452

433-
t.true(isValid);
434-
t.is(validationError, undefined);
453+
const mail = await send(msg);
454+
t.is(mail.text, msg.text.replace(/\r/g, '') + '\n\n\n');
455+
t.is(mail.subject, msg.subject);
456+
t.is(mail.from?.text, msg.from);
457+
t.is(mail.to?.text, msg.to);
435458
});
436459

437-
test('message validation succeeds with only `bcc` recipient header (string)', async (t) => {
438-
const { isValid, validationError } = new Message({
439-
440-
441-
}).checkValidity();
442-
443-
t.true(isValid);
444-
t.is(validationError, undefined);
445-
});
460+
test.serial('very large text data message', async (t) => {
461+
t.timeout(15000);
446462

447-
test('message validation succeeds with only `bcc` recipient header (array)', async (t) => {
448-
const { isValid, validationError } = new Message({
449-
450-
451-
}).checkValidity();
463+
const text = '<html><body><pre>' + textFixture + '</pre></body></html>';
464+
const msg = {
465+
subject: 'this is a test TEXT+DATA message from emailjs',
466+
467+
468+
text: 'hello friend if you are seeing this, you can not view html emails. it is attached inline.',
469+
attachment: {
470+
data: text,
471+
alternative: true,
472+
},
473+
};
452474

453-
t.true(isValid);
454-
t.is(validationError, undefined);
475+
const mail = await send(msg);
476+
t.is(mail.html, text.replace(/\r/g, ''));
477+
t.is(mail.text, msg.text + '\n');
478+
t.is(mail.subject, msg.subject);
479+
t.is(mail.from?.text, msg.from);
480+
t.is(mail.to?.text, msg.to);
455481
});

0 commit comments

Comments
 (0)