Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MIME Normalizer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
JS Toolbox
MIME Normalizer
Commits
8f57a3f2
Commit
8f57a3f2
authored
4 years ago
by
Igor Markin
Browse files
Options
Downloads
Patches
Plain Diff
Add option to hash attachment
parent
7b6f8b60
No related branches found
No related tags found
1 merge request
!19
Add readme and improve tests usage
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
__tests__/utils.ts
+46
-22
46 additions, 22 deletions
__tests__/utils.ts
yarn.lock
+1
-1
1 addition, 1 deletion
yarn.lock
with
47 additions
and
23 deletions
__tests__/utils.ts
+
46
−
22
View file @
8f57a3f2
import
{
JSDOM
}
from
"
jsdom
"
;
import
{
JSDOM
}
from
"
jsdom
"
;
const
fs
=
require
(
"
fs
"
);
const
fs
=
require
(
"
fs
"
);
const
crypto
=
require
(
"
crypto
"
);
import
MIMEParser
from
"
@vereign/mime-parser
"
;
import
MIMEParser
from
"
@vereign/mime-parser
"
;
import
{
expect
,
test
}
from
"
@jest/globals
"
;
import
{
expect
,
test
}
from
"
@jest/globals
"
;
import
{
DOM
}
from
"
@vereign/dom
"
;
import
{
DOM
}
from
"
@vereign/dom
"
;
...
@@ -10,7 +11,14 @@ import { PlainNormalizer, HTMLNormalizer } from "../src";
...
@@ -10,7 +11,14 @@ import { PlainNormalizer, HTMLNormalizer } from "../src";
const
SENT_EML_NAME
=
"
sent.eml
"
;
const
SENT_EML_NAME
=
"
sent.eml
"
;
const
RECEIVED_EML_NAME
=
"
received.eml
"
;
const
RECEIVED_EML_NAME
=
"
received.eml
"
;
const
populateAttachments
=
false
;
const
populateAttachments
=
true
;
const
hashAttachment
=
(
base64
:
string
)
=>
{
return
crypto
.
createHash
(
"
sha256
"
)
.
update
(
Buffer
.
from
(
base64
,
"
base64
"
))
.
digest
()
.
toString
(
"
base64
"
);
};
expect
.
extend
({
expect
.
extend
({
toEqualWithDiff
(
target
,
source
)
{
toEqualWithDiff
(
target
,
source
)
{
...
@@ -38,20 +46,26 @@ const getMime = (path: string): MIMEParser => {
...
@@ -38,20 +46,26 @@ const getMime = (path: string): MIMEParser => {
return
mimeCache
[
path
];
return
mimeCache
[
path
];
};
};
export
const
getNormalizedPlain
=
(
export
const
getNormalizedPlain
=
async
(
testCasePath
:
string
testCasePath
:
string
):
{
):
Promise
<
{
sentPlain
:
string
;
sentPlain
:
string
;
receivedPlain
:
string
;
receivedPlain
:
string
;
}
=>
{
}
>
=>
{
const
sentMime
=
getMime
(
`
${
testCasePath
}
/
${
SENT_EML_NAME
}
`
);
const
sentMime
=
getMime
(
`
${
testCasePath
}
/
${
SENT_EML_NAME
}
`
);
const
receivedMime
=
getMime
(
`
${
testCasePath
}
/
${
RECEIVED_EML_NAME
}
`
);
const
receivedMime
=
getMime
(
`
${
testCasePath
}
/
${
RECEIVED_EML_NAME
}
`
);
const
sentNormalizedPlain
=
PlainNormalizer
.
normalizePlain
(
const
sentNormalizedPlain
=
PlainNormalizer
.
normalizePlain
(
sentMime
.
getPlain
(
populateAttachments
)
await
sentMime
.
getPlain
({
populateAttachments
,
hashAttachment
,
})
);
);
const
receivedNormalizedPlain
=
PlainNormalizer
.
normalizePlain
(
const
receivedNormalizedPlain
=
PlainNormalizer
.
normalizePlain
(
receivedMime
.
getPlain
(
populateAttachments
)
await
receivedMime
.
getPlain
({
populateAttachments
,
hashAttachment
,
})
);
);
return
{
return
{
...
@@ -66,18 +80,24 @@ export const getTestCasesDirs = (testCasesPath: string): Array<string> => {
...
@@ -66,18 +80,24 @@ export const getTestCasesDirs = (testCasesPath: string): Array<string> => {
});
});
};
};
export
const
getNormalizedHtml
=
(
export
const
getNormalizedHtml
=
async
(
testCasePath
:
string
,
testCasePath
:
string
,
vendor
:
string
vendor
:
string
):
{
):
Promise
<
{
sentHtml
:
string
;
sentHtml
:
string
;
receivedHtml
:
string
;
receivedHtml
:
string
;
}
=>
{
}
>
=>
{
const
sentMime
=
getMime
(
`
${
testCasePath
}
/
${
SENT_EML_NAME
}
`
);
const
sentMime
=
getMime
(
`
${
testCasePath
}
/
${
SENT_EML_NAME
}
`
);
const
receivedMime
=
getMime
(
`
${
testCasePath
}
/
${
RECEIVED_EML_NAME
}
`
);
const
receivedMime
=
getMime
(
`
${
testCasePath
}
/
${
RECEIVED_EML_NAME
}
`
);
const
sentHtml
=
sentMime
.
getHTML
(
populateAttachments
);
const
sentHtml
=
await
sentMime
.
getHTML
({
const
receivedHtml
=
receivedMime
.
getHTML
(
populateAttachments
);
populateAttachments
,
hashAttachment
,
});
const
receivedHtml
=
await
receivedMime
.
getHTML
({
populateAttachments
,
hashAttachment
,
});
const
sentDOM
=
new
DOM
(
sentHtml
);
const
sentDOM
=
new
DOM
(
sentHtml
);
const
receivedDOM
=
new
JSDOM
(
receivedHtml
);
const
receivedDOM
=
new
JSDOM
(
receivedHtml
);
...
@@ -126,9 +146,9 @@ export const createDescribeHtmlTestCases = (
...
@@ -126,9 +146,9 @@ export const createDescribeHtmlTestCases = (
);
);
}
}
test
.
each
(
testCasesDirs
)(
"
Case %s
"
,
(
dirName
:
string
)
=>
{
test
.
each
(
testCasesDirs
)(
"
Case %s
"
,
async
(
dirName
:
string
)
=>
{
const
testCasePath
=
testsCasesPath
+
"
/
"
+
dirName
;
const
testCasePath
=
testsCasesPath
+
"
/
"
+
dirName
;
const
normalizedHtmls
=
getNormalizedHtml
(
testCasePath
,
vendor
);
const
normalizedHtmls
=
await
getNormalizedHtml
(
testCasePath
,
vendor
);
const
{
sentHtml
,
receivedHtml
}
=
normalizedHtmls
;
const
{
sentHtml
,
receivedHtml
}
=
normalizedHtmls
;
// expect(receivedHtml.length).toBeGreaterThan(0);
// expect(receivedHtml.length).toBeGreaterThan(0);
...
@@ -159,9 +179,9 @@ export const createDescribePlainTestCases = (testsPath: string) => (
...
@@ -159,9 +179,9 @@ export const createDescribePlainTestCases = (testsPath: string) => (
testCasesDirs
=
testCasesDirs
.
filter
((
dir
)
=>
!
failingCases
.
includes
(
dir
));
testCasesDirs
=
testCasesDirs
.
filter
((
dir
)
=>
!
failingCases
.
includes
(
dir
));
}
}
test
.
each
(
testCasesDirs
)(
"
Case %s
"
,
(
dirName
:
string
)
=>
{
test
.
each
(
testCasesDirs
)(
"
Case %s
"
,
async
(
dirName
:
string
)
=>
{
const
testCasePath
=
testsCasesPath
+
"
/
"
+
dirName
;
const
testCasePath
=
testsCasesPath
+
"
/
"
+
dirName
;
const
normalizedPlain
=
getNormalizedPlain
(
testCasePath
);
const
normalizedPlain
=
await
getNormalizedPlain
(
testCasePath
);
const
{
sentPlain
,
receivedPlain
}
=
normalizedPlain
;
const
{
sentPlain
,
receivedPlain
}
=
normalizedPlain
;
// expect(sentPlain.length).toBeGreaterThan(0);
// expect(sentPlain.length).toBeGreaterThan(0);
...
@@ -201,9 +221,9 @@ export const createDescribePseudoPlainTestCases = (
...
@@ -201,9 +221,9 @@ export const createDescribePseudoPlainTestCases = (
);
);
}
}
test
.
each
(
testCasesDirs
)(
"
Case %s
"
,
(
dirName
:
string
)
=>
{
test
.
each
(
testCasesDirs
)(
"
Case %s
"
,
async
(
dirName
:
string
)
=>
{
const
testCasePath
=
testsCasesPath
+
"
/
"
+
dirName
;
const
testCasePath
=
testsCasesPath
+
"
/
"
+
dirName
;
const
{
sentHtmlDocument
,
receivedHtmlDocument
}
=
getDOMDocuments
(
const
{
sentHtmlDocument
,
receivedHtmlDocument
}
=
await
getDOMDocuments
(
testCasePath
testCasePath
);
);
...
@@ -226,17 +246,21 @@ export const createDescribePseudoPlainTestCases = (
...
@@ -226,17 +246,21 @@ export const createDescribePseudoPlainTestCases = (
});
});
};
};
export
const
getDOMDocuments
=
(
export
const
getDOMDocuments
=
async
(
testCasePath
:
string
testCasePath
:
string
):
{
):
Promise
<
{
sentHtmlDocument
:
HTMLDocument
;
sentHtmlDocument
:
HTMLDocument
;
receivedHtmlDocument
:
HTMLDocument
;
receivedHtmlDocument
:
HTMLDocument
;
}
=>
{
}
>
=>
{
const
sentMime
=
getMime
(
`
${
testCasePath
}
/
${
SENT_EML_NAME
}
`
);
const
sentMime
=
getMime
(
`
${
testCasePath
}
/
${
SENT_EML_NAME
}
`
);
const
receivedMime
=
getMime
(
`
${
testCasePath
}
/
${
RECEIVED_EML_NAME
}
`
);
const
receivedMime
=
getMime
(
`
${
testCasePath
}
/
${
RECEIVED_EML_NAME
}
`
);
const
sentDOM
=
new
DOM
(
sentMime
.
getHTML
(
populateAttachments
));
const
sentDOM
=
new
DOM
(
const
receivedDOM
=
new
JSDOM
(
receivedMime
.
getHTML
(
populateAttachments
));
await
sentMime
.
getHTML
({
populateAttachments
,
hashAttachment
})
);
const
receivedDOM
=
new
JSDOM
(
await
receivedMime
.
getHTML
({
populateAttachments
,
hashAttachment
})
);
return
{
return
{
sentHtmlDocument
:
sentDOM
.
window
.
document
,
sentHtmlDocument
:
sentDOM
.
window
.
document
,
...
...
This diff is collapsed.
Click to expand it.
yarn.lock
+
1
−
1
View file @
8f57a3f2
...
@@ -1264,7 +1264,7 @@
...
@@ -1264,7 +1264,7 @@
"@vereign/mime-parser@git+ssh://git@code.vereign.com:code/js-toolbox/mime-parser.git":
"@vereign/mime-parser@git+ssh://git@code.vereign.com:code/js-toolbox/mime-parser.git":
version "1.0.0"
version "1.0.0"
resolved "git+ssh://git@code.vereign.com:code/js-toolbox/mime-parser.git#
07fa6f0d595416f12baa601b9258acedf91c97c7
"
resolved "git+ssh://git@code.vereign.com:code/js-toolbox/mime-parser.git#
4b509038b448d0ce2f4e679beb5535e62ed7d6ad
"
dependencies:
dependencies:
libmime "^5.0.0"
libmime "^5.0.0"
libqp "^1.1.0"
libqp "^1.1.0"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment