Skip to content

Commit

Permalink
removed grunt, sinon, mocha, chai, converted tests to use native node…
Browse files Browse the repository at this point in the history
… test runner, added c8 for coverage
  • Loading branch information
Steven Hargrove committed Dec 24, 2023
1 parent bc46a3b commit 7bbcb75
Show file tree
Hide file tree
Showing 34 changed files with 2,842 additions and 4,515 deletions.
9 changes: 9 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"clean": true,
"check-coverage": true,
"all": true,
"temp-directory": "./coverage/.tmp",
"reporter": ["text-summary", "html"],
"include": ["lib/**/*.js", "lib/*.js"],
"lines": 87
}
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm test
- run: npm run lint
- run: npm run test:coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
coverage/
npm-debug.log
.DS_Store
test/dkim/cache/message.*
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ examples
.eslintrc
.gitignore
.travis.yml
Gruntfile.js
.c8rc.json
.github/
coverage/
26 changes: 0 additions & 26 deletions Gruntfile.js

This file was deleted.

2,825 changes: 630 additions & 2,195 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "Easy as cake e-mail sending from your Node.js applications",
"main": "lib/nodemailer.js",
"scripts": {
"test": "grunt --trace-warnings",
"test": "node --test --test-concurrency=1 'test/**/*.test.js' 'test/**/*-test.js'",
"test:coverage": "c8 node --test --test-concurrency=1 'test/**/*.test.js' 'test/**/*-test.js'",
"lint": "eslint .",
"update": "rm -rf node_modules/ package-lock.json && ncu -u && npm install"
},
"repository": {
Expand All @@ -23,21 +25,16 @@
"devDependencies": {
"@aws-sdk/client-ses": "3.433.0",
"bunyan": "1.8.15",
"chai": "4.3.10",
"c8": "^8.0.1",
"eslint": "^8.56.0",
"eslint-config-nodemailer": "1.2.0",
"eslint-config-prettier": "9.0.0",
"grunt": "1.6.1",
"grunt-cli": "1.4.3",
"grunt-eslint": "24.3.0",
"grunt-mocha-test": "0.13.3",
"libbase64": "1.2.1",
"libmime": "5.2.1",
"libqp": "2.0.1",
"mocha": "10.2.0",
"nodemailer-ntlm-auth": "1.0.4",
"proxy": "1.0.2",
"proxy-test-server": "1.0.0",
"sinon": "17.0.0",
"smtp-server": "3.13.0"
},
"engines": {
Expand Down
91 changes: 43 additions & 48 deletions test/addressparser/addressparser-test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
/* eslint no-unused-expressions:0, prefer-arrow-callback: 0, no-undefined: 0 */
/* globals describe, it */

'use strict';

const chai = require('chai');
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const addressparser = require('../../lib/addressparser');
const expect = chai.expect;

chai.config.includeStack = true;

describe('#addressparser', function () {
it('should handle single address correctly', function () {
describe('#addressparser', () => {
it('should handle single address correctly', () => {
let input = 'andris@tr.ee';
let expected = [
{
address: 'andris@tr.ee',
name: ''
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle multiple addresses correctly', function () {
it('should handle multiple addresses correctly', () => {
let input = 'andris@tr.ee, andris@example.com';
let expected = [
{
Expand All @@ -33,65 +28,65 @@ describe('#addressparser', function () {
name: ''
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle unquoted name correctly', function () {
it('should handle unquoted name correctly', () => {
let input = 'andris <andris@tr.ee>';
let expected = [
{
name: 'andris',
address: 'andris@tr.ee'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle quoted name correctly', function () {
it('should handle quoted name correctly', () => {
let input = '"reinman, andris" <andris@tr.ee>';
let expected = [
{
name: 'reinman, andris',
address: 'andris@tr.ee'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle quoted semicolons correctly', function () {
it('should handle quoted semicolons correctly', () => {
let input = '"reinman; andris" <andris@tr.ee>';
let expected = [
{
name: 'reinman; andris',
address: 'andris@tr.ee'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle unquoted name, unquoted address correctly', function () {
it('should handle unquoted name, unquoted address correctly', () => {
let input = 'andris andris@tr.ee';
let expected = [
{
name: 'andris',
address: 'andris@tr.ee'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle emtpy group correctly', function () {
it('should handle emtpy group correctly', () => {
let input = 'Undisclosed:;';
let expected = [
{
name: 'Undisclosed',
group: []
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle address group correctly', function () {
it('should handle address group correctly', () => {
let input = 'Disclosed:andris@tr.ee, andris@example.com;';
let expected = [
{
Expand All @@ -108,10 +103,10 @@ describe('#addressparser', function () {
]
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle semicolon as a delimiter', function () {
it('should handle semicolon as a delimiter', () => {
let input = 'andris@tr.ee; andris@example.com;';
let expected = [
{
Expand All @@ -123,10 +118,10 @@ describe('#addressparser', function () {
name: ''
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle mixed group correctly', function () {
it('should handle mixed group correctly', () => {
let input = 'Test User <test.user@mail.ee>, Disclosed:andris@tr.ee, andris@example.com;,,,, Undisclosed:;';
let expected = [
{
Expand All @@ -151,10 +146,10 @@ describe('#addressparser', function () {
group: []
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should flatten mixed group correctly', function () {
it('should flatten mixed group correctly', () => {
let input = 'Test User <test.user@mail.ee>, Disclosed:andris@tr.ee, andris@example.com;,,,, Undisclosed:; bob@example.com BOB;';
let expected = [
{
Expand All @@ -175,10 +170,10 @@ describe('#addressparser', function () {
name: 'BOB'
}
];
expect(addressparser(input, { flatten: true })).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input, { flatten: true }), expected);
});

it('semicolon as delimiter should not break group parsing', function () {
it('semicolon as delimiter should not break group parsing', () => {
let input = 'Test User <test.user@mail.ee>; Disclosed:andris@tr.ee, andris@example.com;,,,, Undisclosed:; bob@example.com;';
let expected = [
{
Expand Down Expand Up @@ -207,54 +202,54 @@ describe('#addressparser', function () {
name: ''
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle name from comment correctly', function () {
it('should handle name from comment correctly', () => {
let input = 'andris@tr.ee (andris)';
let expected = [
{
name: 'andris',
address: 'andris@tr.ee'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle skip comment correctly', function () {
it('should handle skip comment correctly', () => {
let input = 'andris@tr.ee (reinman) andris';
let expected = [
{
name: 'andris',
address: 'andris@tr.ee'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle missing address correctly', function () {
it('should handle missing address correctly', () => {
let input = 'andris';
let expected = [
{
name: 'andris',
address: ''
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle apostrophe in name correctly', function () {
it('should handle apostrophe in name correctly', () => {
let input = 'O\x27Neill';
let expected = [
{
name: 'O\x27Neill',
address: ''
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle particularily bad input, unescaped colon correctly', function () {
it('should handle particularily bad input, unescaped colon correctly', () => {
let input = 'FirstName Surname-WithADash :: Company <firstname@company.com>';
let expected = [
{
Expand All @@ -272,35 +267,35 @@ describe('#addressparser', function () {
]
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

// should not change an invalid email to valid email
it('should handle invalid email address correctly', function () {
it('should handle invalid email address correctly', () => {
let input = 'name@address.com@address2.com';
let expected = [
{
name: '',
address: 'name@address.com@address2.com'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle unexpected <', function () {
it('should handle unexpected <', () => {
let input = 'reinman > andris < test <andris@tr.ee>';
let expected = [
{
name: 'reinman > andris',
address: 'andris@tr.ee'
}
];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});

it('should handle escapes', function () {
it('should handle escapes', () => {
let input = '"Firstname \\" \\\\\\, Lastname \\(Test\\)" test@example.com';
let expected = [{ address: 'test@example.com', name: 'Firstname " \\, Lastname (Test)' }];
expect(addressparser(input)).to.deep.equal(expected);
assert.deepStrictEqual(addressparser(input), expected);
});
});

0 comments on commit 7bbcb75

Please sign in to comment.