@tryghost/express-test 0.13.17 → 0.14.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/Request.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const {default: reqresnext} = require('reqresnext');
2
2
  const {CookieAccessInfo} = require('cookiejar');
3
3
  const {parse} = require('url');
4
- const {isJSON} = require('./utils');
4
+ const {isJSON, attachFile} = require('./utils');
5
5
  const {Readable} = require('stream');
6
6
 
7
7
  class RequestOptions {
@@ -22,6 +22,15 @@ class Request {
22
22
  this.app = app;
23
23
  this.reqOptions = reqOptions instanceof RequestOptions ? reqOptions : new RequestOptions(reqOptions);
24
24
  this.cookieJar = cookieJar;
25
+ this._formData = null; // Track FormData instance for multiple attachments
26
+ }
27
+
28
+ attach(name, filePath) {
29
+ // Use the utility to create or append to FormData
30
+ this._formData = attachFile(name, filePath, this._formData);
31
+
32
+ // Set the body to the FormData instance
33
+ return this.body(this._formData);
25
34
  }
26
35
 
27
36
  /**
@@ -86,7 +95,7 @@ class Request {
86
95
  readableStream.pause();
87
96
  },
88
97
  read: () => {
89
- readableStream.read(...arguments);
98
+ return readableStream.read(...arguments);
90
99
  }
91
100
  };
92
101
  return this;
package/lib/utils.js CHANGED
@@ -1,7 +1,12 @@
1
- module.exports.isJSON = function isJSON(mime) {
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const mime = require('mime-types');
4
+ const FormData = require('form-data');
5
+
6
+ module.exports.isJSON = function isJSON(mimeType) {
2
7
  // should match /json or +json
3
8
  // but not /json-seq
4
- return /[/+]json($|[^-\w])/i.test(mime);
9
+ return /[/+]json($|[^-\w])/i.test(mimeType);
5
10
  };
6
11
 
7
12
  module.exports.normalizeURL = function normalizeURL(toNormalize) {
@@ -15,3 +20,17 @@ module.exports.normalizeURL = function normalizeURL(toNormalize) {
15
20
 
16
21
  return normalized;
17
22
  };
23
+
24
+ module.exports.attachFile = function attachFile(name, filePath, existingFormData = null) {
25
+ const formData = existingFormData || new FormData();
26
+ const fileContent = fs.readFileSync(filePath);
27
+ const filename = path.basename(filePath);
28
+ const contentType = mime.lookup(filePath) || 'application/octet-stream';
29
+
30
+ formData.append(name, fileContent, {
31
+ filename,
32
+ contentType
33
+ });
34
+
35
+ return formData;
36
+ };
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@tryghost/express-test",
3
- "version": "0.13.17",
4
- "repository": "https://github.com/TryGhost/framework/tree/main/packages/express-test",
3
+ "version": "0.14.1",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/TryGhost/framework.git",
7
+ "directory": "packages/express-test"
8
+ },
5
9
  "author": "Ghost Foundation",
6
10
  "license": "MIT",
7
11
  "main": "index.js",
@@ -22,15 +26,16 @@
22
26
  "c8": "10.1.3",
23
27
  "express": "4.21.1",
24
28
  "express-session": "1.18.1",
25
- "form-data": "^4.0.0",
26
29
  "mocha": "10.7.3",
27
- "multer": "^1.4.5-lts.1",
30
+ "multer": "^2.0.0",
28
31
  "sinon": "18.0.0"
29
32
  },
30
33
  "dependencies": {
31
- "@tryghost/jest-snapshot": "^0.5.17",
34
+ "@tryghost/jest-snapshot": "^0.5.18",
32
35
  "cookiejar": "^2.1.3",
36
+ "form-data": "^4.0.2",
37
+ "mime-types": "^3.0.1",
33
38
  "reqresnext": "^1.7.0"
34
39
  },
35
- "gitHead": "b169bd1734b749c3abdaac134f030756b9a282bb"
40
+ "gitHead": "5c1f8f8e850900331ba28e6816efb1d347d3c68c"
36
41
  }