@tryghost/express-test 0.13.16 → 0.14.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2023 Ghost Foundation
3
+ Copyright (c) 2013-2025 Ghost Foundation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -74,4 +74,4 @@ Follow the instructions for the top-level repo.
74
74
 
75
75
  # Copyright & License
76
76
 
77
- Copyright (c) 2013-2023 Ghost Foundation - Released under the [MIT license](LICENSE).
77
+ Copyright (c) 2013-2025 Ghost Foundation - Released under the [MIT license](LICENSE).
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
  /**
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.16",
4
- "repository": "https://github.com/TryGhost/framework/tree/main/packages/express-test",
3
+ "version": "0.14.0",
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",
@@ -19,18 +23,19 @@
19
23
  "access": "public"
20
24
  },
21
25
  "devDependencies": {
22
- "c8": "10.1.2",
23
- "express": "4.19.2",
24
- "express-session": "1.18.0",
25
- "form-data": "^4.0.0",
26
- "mocha": "10.7.0",
26
+ "c8": "10.1.3",
27
+ "express": "4.21.1",
28
+ "express-session": "1.18.1",
29
+ "mocha": "10.7.3",
27
30
  "multer": "^1.4.5-lts.1",
28
31
  "sinon": "18.0.0"
29
32
  },
30
33
  "dependencies": {
31
- "@tryghost/jest-snapshot": "^0.5.16",
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": "d86b1d4fb719b9fb3535a31576c06e42ad1d8476"
40
+ "gitHead": "e395f1d79edee4aecc36e572bb402016a8ba9273"
36
41
  }