@tryghost/express-test 0.2.0 → 0.3.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.
@@ -1,5 +1,6 @@
1
1
  const assert = require('assert');
2
2
  const {Request, RequestOptions} = require('./request');
3
+ const {snapshotManager} = require('@tryghost/jest-snapshot');
3
4
 
4
5
  class ExpectRequest extends Request {
5
6
  constructor(...args) {
@@ -54,6 +55,30 @@ class ExpectRequest extends Request {
54
55
  return this;
55
56
  }
56
57
 
58
+ matchBodySnapshot(properties) {
59
+ let assertion = {
60
+ fn: this._assertSnapshot,
61
+ properties: properties,
62
+ field: 'body'
63
+ };
64
+
65
+ this._addAssertion(assertion);
66
+
67
+ return this;
68
+ }
69
+
70
+ matchHeaderSnapshot(properties) {
71
+ let assertion = {
72
+ fn: this._assertSnapshot,
73
+ properties: properties,
74
+ field: 'headers'
75
+ };
76
+
77
+ this._addAssertion(assertion);
78
+
79
+ return this;
80
+ }
81
+
57
82
  finalize(callback) {
58
83
  super.finalize((error, response) => {
59
84
  if (error) {
@@ -123,6 +148,21 @@ class ExpectRequest extends Request {
123
148
  assert.equal(expectedHeaderString, actualHeaderString, error);
124
149
  }
125
150
  }
151
+
152
+ _assertSnapshot(result, assertion) {
153
+ const {properties, field, error} = assertion;
154
+
155
+ const match = snapshotManager.match(result[field], properties);
156
+
157
+ if (match.pass !== true) {
158
+ const snapshotName = match.message().match(/Snapshot name: `(.*)`/)[1];
159
+ error.expected = match.expected;
160
+ error.actual = match.actual;
161
+ error.message = `Expected ${field} to match in Snapshot: "${snapshotName}" ${error.contextString}`;
162
+ }
163
+
164
+ assert.equal(match.pass, true, error);
165
+ }
126
166
  }
127
167
 
128
168
  module.exports = ExpectRequest;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@tryghost/express-test",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "repository": "https://github.com/TryGhost/framework/tree/main/packages/express-test",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "dev": "echo \"Implement me!\"",
10
- "test": "NODE_ENV=testing c8 mocha './test/**/*.test.js'",
10
+ "test": "NODE_ENV=testing c8 mocha --require ./test/utils/overrides.js './test/**/*.test.js'",
11
11
  "lint": "eslint . --ext .js --cache",
12
12
  "posttest": "yarn lint"
13
13
  },
@@ -26,8 +26,9 @@
26
26
  "sinon": "13.0.1"
27
27
  },
28
28
  "dependencies": {
29
+ "@tryghost/jest-snapshot": "^0.2.0",
29
30
  "cookiejar": "^2.1.3",
30
31
  "reqresnext": "^1.6.6"
31
32
  },
32
- "gitHead": "ba2449737cd3a66d811e34b5b28b86f5d3538396"
33
+ "gitHead": "1750e2bdc5b8f659a4439490c79a8c262a74e66f"
33
34
  }