@tryghost/express-test 0.6.1 → 0.7.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.
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
- url = `/${this.defaults.baseUrl}/${url}`.replace(/(^|[^:])\/\/+/g, '$1/');
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 (url.includes('?')) {
34
- url = `${url}&${searchParams.toString()}`;
38
+ if (processedURL.includes('?')) {
39
+ processedURL = `${processedURL}&${searchParams.toString()}`;
35
40
  } else {
36
- url = `${url}?${searchParams.toString()}`;
41
+ processedURL = `${processedURL}?${searchParams.toString()}`;
37
42
  }
38
43
  }
39
44
 
40
- return url;
45
+ return processedURL;
41
46
  }
42
47
 
43
48
  _mergeOptions(method, url, options = {}) {
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.6.1",
3
+ "version": "0.7.1",
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.1",
25
+ "mocha": "9.2.2",
26
26
  "sinon": "13.0.1"
27
27
  },
28
28
  "dependencies": {
29
- "@tryghost/jest-snapshot": "^0.3.4",
29
+ "@tryghost/jest-snapshot": "^0.3.7",
30
30
  "cookiejar": "^2.1.3",
31
31
  "reqresnext": "^1.7.0"
32
32
  },
33
- "gitHead": "3768b2b29fe5c2ae4e535264246bc78933eba372"
33
+ "gitHead": "782447b7c96a800387ef83ad4a2a330615918399"
34
34
  }