@tryghost/email-mock-receiver 0.1.2 → 0.2.1

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.
@@ -33,7 +33,13 @@ class EmailMockReceiver {
33
33
  assert.equal(this.#snapshots.length, count, 'Email count does not match');
34
34
  }
35
35
 
36
- matchHTMLSnapshot(snapshotIndex = 0) {
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.replace(pattern, replacement);
56
+ }
57
+ }
58
+
46
59
  this.#snapshotManager.assertSnapshot({
47
- html: this.#snapshots[snapshotIndex].html
60
+ html: html
48
61
  }, assertion);
49
62
 
50
63
  return this;
51
64
  }
52
65
 
53
- matchMetadataSnapshot(snapshotIndex = 0, properties = {}) {
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.1.2",
3
+ "version": "0.2.1",
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.2"
26
+ "sinon": "15.0.3"
27
27
  },
28
- "gitHead": "df08274c09d27c79c980989a04a030abef1eb69a"
28
+ "gitHead": "886860d772381ed643fc23251ba9dde3d605d0b0"
29
29
  }