@tryghost/express-test 0.7.1 → 0.8.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/agent.js +1 -0
- package/lib/expect-request.js +27 -5
- package/lib/request.js +3 -8
- package/package.json +4 -4
package/lib/agent.js
CHANGED
|
@@ -59,6 +59,7 @@ class Agent {
|
|
|
59
59
|
method,
|
|
60
60
|
url: this._makeUrl(url),
|
|
61
61
|
headers: Object.assign({}, this.defaults.headers, options.headers),
|
|
62
|
+
// Set this to an empty object for ease, as express.json will do this anyway
|
|
62
63
|
body: Object.assign({}, this.defaults.body, options.body)
|
|
63
64
|
});
|
|
64
65
|
}
|
package/lib/expect-request.js
CHANGED
|
@@ -77,6 +77,18 @@ class ExpectRequest extends Request {
|
|
|
77
77
|
return this;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
expectEmptyBody() {
|
|
81
|
+
const assertion = {
|
|
82
|
+
fn: this._assertEmptyBody,
|
|
83
|
+
expected: {},
|
|
84
|
+
type: 'body'
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
this._addAssertion(assertion);
|
|
88
|
+
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
|
|
80
92
|
matchBodySnapshot(properties = {}) {
|
|
81
93
|
let assertion = {
|
|
82
94
|
fn: this._assertSnapshot,
|
|
@@ -217,18 +229,28 @@ class ExpectRequest extends Request {
|
|
|
217
229
|
}
|
|
218
230
|
}
|
|
219
231
|
|
|
220
|
-
|
|
232
|
+
_assertEmptyBody(response, assertion) {
|
|
233
|
+
const {error, expected} = assertion;
|
|
234
|
+
const actual = response.body;
|
|
235
|
+
|
|
236
|
+
error.actual = actual;
|
|
237
|
+
error.message = `Expected body to be empty, got "${actual}" ${error.contextString}`;
|
|
238
|
+
|
|
239
|
+
assert.deepEqual(actual, expected, error);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
_assertSnapshot(response, assertion) {
|
|
221
243
|
const {properties, field, error} = assertion;
|
|
222
244
|
|
|
223
|
-
if (!
|
|
245
|
+
if (!response[field]) {
|
|
224
246
|
error.message = `Unable to match snapshot on undefined field ${field} ${error.contextString}`;
|
|
225
247
|
error.expected = field;
|
|
226
248
|
error.actual = 'undefined';
|
|
227
|
-
assert.notEqual(
|
|
249
|
+
assert.notEqual(response[field], undefined, error);
|
|
228
250
|
}
|
|
229
251
|
|
|
230
252
|
const hint = `[${field}]`;
|
|
231
|
-
const match = snapshotManager.match(
|
|
253
|
+
const match = snapshotManager.match(response[field], properties, hint);
|
|
232
254
|
|
|
233
255
|
Object.keys(properties).forEach((prop) => {
|
|
234
256
|
const errorMessage = `"response.${field}" is missing the expected property "${prop}"`;
|
|
@@ -237,7 +259,7 @@ class ExpectRequest extends Request {
|
|
|
237
259
|
error.actual = 'undefined';
|
|
238
260
|
error.showDiff = false; // Disable mocha's diff output as it's already present in match.message()
|
|
239
261
|
|
|
240
|
-
assert.notEqual(
|
|
262
|
+
assert.notEqual(response[field][prop], undefined, error);
|
|
241
263
|
});
|
|
242
264
|
|
|
243
265
|
if (match.pass !== true) {
|
package/lib/request.js
CHANGED
|
@@ -36,11 +36,11 @@ class Request {
|
|
|
36
36
|
then(resolve, reject) {
|
|
37
37
|
const self = this;
|
|
38
38
|
this._fullfilledPromise = new Promise((_resolve, _reject) => {
|
|
39
|
-
self.finalize((error,
|
|
39
|
+
self.finalize((error, response) => {
|
|
40
40
|
if (error) {
|
|
41
41
|
return _reject(error);
|
|
42
42
|
}
|
|
43
|
-
return _resolve(
|
|
43
|
+
return _resolve(response);
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -64,12 +64,7 @@ class Request {
|
|
|
64
64
|
_getReqRes() {
|
|
65
65
|
const {app, reqOptions} = this;
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// This is needed to make error handling work
|
|
70
|
-
// @TODO: remove once https://github.com/antongolub/reqresnext/issues/31 is solved
|
|
71
|
-
req.socket.destroy = () => { };
|
|
72
|
-
return {req, res};
|
|
67
|
+
return reqresnext(Object.assign({}, reqOptions, {app}), {app});
|
|
73
68
|
}
|
|
74
69
|
|
|
75
70
|
_buildResponse(res) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/express-test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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
|
|
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,9 +26,9 @@
|
|
|
26
26
|
"sinon": "13.0.1"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@tryghost/jest-snapshot": "^0.3.
|
|
29
|
+
"@tryghost/jest-snapshot": "^0.3.8",
|
|
30
30
|
"cookiejar": "^2.1.3",
|
|
31
31
|
"reqresnext": "^1.7.0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "5eac4d7d103691f639b4c2b58494c26c85f4b22a"
|
|
34
34
|
}
|