@tryghost/email-mock-receiver 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/email-mock-receiver.js +28 -3
- package/package.json +3 -3
|
@@ -33,7 +33,13 @@ class EmailMockReceiver {
|
|
|
33
33
|
assert.equal(this.#snapshots.length, count, 'Email count does not match');
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param {Replacement[]} replacements replacement patterns
|
|
39
|
+
* @param {Number} snapshotIndex index of snapshot to match
|
|
40
|
+
* @returns {EmailMockReceiver} current instance
|
|
41
|
+
*/
|
|
42
|
+
matchHTMLSnapshot(replacements = [], snapshotIndex = 0) {
|
|
37
43
|
const error = new AssertionError({});
|
|
38
44
|
|
|
39
45
|
let assertion = {
|
|
@@ -43,14 +49,27 @@ class EmailMockReceiver {
|
|
|
43
49
|
error
|
|
44
50
|
};
|
|
45
51
|
|
|
52
|
+
let html = this.#snapshots[snapshotIndex].html;
|
|
53
|
+
if (replacements.length) {
|
|
54
|
+
for (const [, {pattern, replacement}] of Object.entries(replacements)) {
|
|
55
|
+
html = html.replaceAll(pattern, replacement);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
46
59
|
this.#snapshotManager.assertSnapshot({
|
|
47
|
-
html:
|
|
60
|
+
html: html
|
|
48
61
|
}, assertion);
|
|
49
62
|
|
|
50
63
|
return this;
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param {Object} [properties] - properties to match
|
|
69
|
+
* @param {Number} [snapshotIndex] - index of snapshot to match
|
|
70
|
+
* @returns {EmailMockReceiver} current instance
|
|
71
|
+
*/
|
|
72
|
+
matchMetadataSnapshot(properties = {}, snapshotIndex = 0) {
|
|
54
73
|
const error = new AssertionError({});
|
|
55
74
|
let assertion = {
|
|
56
75
|
properties: properties,
|
|
@@ -75,3 +94,9 @@ class EmailMockReceiver {
|
|
|
75
94
|
}
|
|
76
95
|
|
|
77
96
|
module.exports = EmailMockReceiver;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @typedef {Object} Replacement
|
|
100
|
+
* @prop {String|RegExp} [pattern] - pattern to match the dynamic content
|
|
101
|
+
* @prop {String} [replacement] - replacement for the matched pattern
|
|
102
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/email-mock-receiver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/framework/tree/main/packages/email-mock-receiver",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"c8": "7.13.0",
|
|
25
25
|
"mocha": "10.2.0",
|
|
26
|
-
"sinon": "15.0.
|
|
26
|
+
"sinon": "15.0.3"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "ef4fed43a97573417f518409af0bfe957b3a1564"
|
|
29
29
|
}
|