@tryghost/express-test 0.6.0 → 0.7.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 +10 -5
- package/lib/expect-request.js +8 -4
- package/lib/utils.js +14 -0
- package/package.json +4 -4
package/lib/agent.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const {CookieJar} = require('cookiejar');
|
|
2
2
|
const ExpectRequest = require('./expect-request');
|
|
3
3
|
const {RequestOptions} = require('./request');
|
|
4
|
+
const {normalizeURL} = require('./utils');
|
|
4
5
|
|
|
5
6
|
class Agent {
|
|
6
7
|
/**
|
|
@@ -19,10 +20,14 @@ class Agent {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
_makeUrl(url) {
|
|
23
|
+
let processedURL = url;
|
|
24
|
+
|
|
22
25
|
if (this.defaults.baseUrl) {
|
|
23
|
-
|
|
26
|
+
processedURL = `/${this.defaults.baseUrl}/${processedURL}`.replace(/(^|[^:])\/\/+/g, '$1/');
|
|
24
27
|
}
|
|
25
28
|
|
|
29
|
+
processedURL = normalizeURL(processedURL);
|
|
30
|
+
|
|
26
31
|
if (this.defaults.queryParams) {
|
|
27
32
|
const searchParams = new URLSearchParams();
|
|
28
33
|
|
|
@@ -30,14 +35,14 @@ class Agent {
|
|
|
30
35
|
searchParams.append(key, this.defaults.queryParams[key]);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
38
|
+
if (processedURL.includes('?')) {
|
|
39
|
+
processedURL = `${processedURL}&${searchParams.toString()}`;
|
|
35
40
|
} else {
|
|
36
|
-
|
|
41
|
+
processedURL = `${processedURL}?${searchParams.toString()}`;
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
return
|
|
45
|
+
return processedURL;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
_mergeOptions(method, url, options = {}) {
|
package/lib/expect-request.js
CHANGED
|
@@ -8,7 +8,7 @@ const {makeMessageFromMatchMessage} = require('./utils');
|
|
|
8
8
|
* @prop {function} fn - Wrapped assertion with response context
|
|
9
9
|
* @prop {string} [message] - The message to display if the assertion fails
|
|
10
10
|
* @prop {string} [method] - The method to call on the assertion object
|
|
11
|
-
* @prop {'header' | 'status'}
|
|
11
|
+
* @prop {'body' | 'header' | 'status'} type - The type of assertion, with following priority: body > header > status
|
|
12
12
|
* @prop {import('assert').AssertionError} [error] - The error to throw if the assertion fails
|
|
13
13
|
* @prop {any} [expected]
|
|
14
14
|
* @prop {any} [expectedValue]
|
|
@@ -43,7 +43,8 @@ class ExpectRequest extends Request {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
const assertion = {
|
|
46
|
-
fn: wrapperFn
|
|
46
|
+
fn: wrapperFn,
|
|
47
|
+
type: 'body'
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
this._addAssertion(assertion);
|
|
@@ -80,7 +81,8 @@ class ExpectRequest extends Request {
|
|
|
80
81
|
let assertion = {
|
|
81
82
|
fn: this._assertSnapshot,
|
|
82
83
|
properties: properties,
|
|
83
|
-
field: 'body'
|
|
84
|
+
field: 'body',
|
|
85
|
+
type: 'body'
|
|
84
86
|
};
|
|
85
87
|
|
|
86
88
|
this._addAssertion(assertion);
|
|
@@ -139,12 +141,14 @@ class ExpectRequest extends Request {
|
|
|
139
141
|
const headerAssertions = [];
|
|
140
142
|
|
|
141
143
|
for (const assertion of this.assertions) {
|
|
142
|
-
if (
|
|
144
|
+
if (assertion.type === 'body') {
|
|
143
145
|
assertion.fn(response, assertion);
|
|
144
146
|
} else if (assertion.type === 'status') {
|
|
145
147
|
statusCodeAssertions.push(assertion);
|
|
146
148
|
} else if (assertion.type === 'header') {
|
|
147
149
|
headerAssertions.push(assertion);
|
|
150
|
+
} else {
|
|
151
|
+
headerAssertions.push(assertion);
|
|
148
152
|
}
|
|
149
153
|
}
|
|
150
154
|
|
package/lib/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// const url = require('url');
|
|
2
|
+
|
|
1
3
|
module.exports.isJSON = function isJSON(mime) {
|
|
2
4
|
// should match /json or +json
|
|
3
5
|
// but not /json-seq
|
|
@@ -9,3 +11,15 @@ module.exports.makeMessageFromMatchMessage = function makeMessageFromMatchMessag
|
|
|
9
11
|
messageLines.splice(0, 1, errorMessage);
|
|
10
12
|
return messageLines.join('\n');
|
|
11
13
|
};
|
|
14
|
+
|
|
15
|
+
module.exports.normalizeURL = function normalizeURL(toNormalize) {
|
|
16
|
+
const split = toNormalize.split('?');
|
|
17
|
+
const pathname = split[0];
|
|
18
|
+
let normalized = pathname + (pathname.endsWith('/') ? '' : '/');
|
|
19
|
+
|
|
20
|
+
if (split.length === 2) {
|
|
21
|
+
normalized += `?${split[1]}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return normalized;
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/express-test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/framework/tree/main/packages/express-test",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"c8": "7.11.0",
|
|
23
23
|
"express": "4.17.3",
|
|
24
24
|
"express-session": "1.17.2",
|
|
25
|
-
"mocha": "9.2.
|
|
25
|
+
"mocha": "9.2.2",
|
|
26
26
|
"sinon": "13.0.1"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@tryghost/jest-snapshot": "^0.3.
|
|
29
|
+
"@tryghost/jest-snapshot": "^0.3.6",
|
|
30
30
|
"cookiejar": "^2.1.3",
|
|
31
31
|
"reqresnext": "^1.7.0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "b71a3cb711cae3a1981e925d29780c9bfaacf3c3"
|
|
34
34
|
}
|