Skip to content

Commit 6375ebd

Browse files
committed
Merge branch 'master' into pr-389
# Conflicts: # package.json
2 parents c7d394b + 69b9c85 commit 6375ebd

11 files changed

+643
-721
lines changed

GraphQLUpload.test.mjs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
// @ts-check
22

33
import { doesNotThrow, throws } from "node:assert";
4+
import { describe, it } from "node:test";
45

56
import { parseValue } from "graphql";
67

78
import GraphQLUpload from "./GraphQLUpload.mjs";
89
import Upload from "./Upload.mjs";
910

10-
/**
11-
* Adds `GraphQLUpload` tests.
12-
* @param {import("test-director").default} tests Test director.
13-
*/
14-
export default (tests) => {
15-
tests.add("`GraphQLUpload` scalar `parseValue` with a valid value.", () => {
16-
doesNotThrow(() => {
17-
GraphQLUpload.parseValue(new Upload());
11+
describe(
12+
"GraphQL scalar `GraphQLUpload`.",
13+
{
14+
concurrency: true,
15+
},
16+
() => {
17+
it("Method `parseValue`, value valid.", () => {
18+
doesNotThrow(() => {
19+
GraphQLUpload.parseValue(new Upload());
20+
});
1821
});
19-
});
2022

21-
tests.add(
22-
"`GraphQLUpload` scalar `parseValue` with an invalid value.",
23-
() => {
23+
it("Method `parseValue`, value invalid.", () => {
2424
throws(
2525
() => {
2626
GraphQLUpload.parseValue(true);
@@ -30,33 +30,33 @@ export default (tests) => {
3030
message: "Upload value invalid.",
3131
},
3232
);
33-
},
34-
);
33+
});
3534

36-
tests.add("`GraphQLUpload` scalar `parseLiteral`.", () => {
37-
throws(
38-
() => {
39-
// The dummy value is irrelevant.
40-
GraphQLUpload.parseLiteral(parseValue('""'));
41-
},
42-
{
43-
name: "GraphQLError",
44-
message: "Upload literal unsupported.",
45-
locations: [{ line: 1, column: 1 }],
46-
},
47-
);
48-
});
35+
it("Method `parseLiteral`.", () => {
36+
throws(
37+
() => {
38+
// The dummy value is irrelevant.
39+
GraphQLUpload.parseLiteral(parseValue('""'));
40+
},
41+
{
42+
name: "GraphQLError",
43+
message: "Upload literal unsupported.",
44+
locations: [{ line: 1, column: 1 }],
45+
},
46+
);
47+
});
4948

50-
tests.add("`GraphQLUpload` scalar `serialize`.", () => {
51-
throws(
52-
() => {
53-
// The dummy value is irrelevant.
54-
GraphQLUpload.serialize("");
55-
},
56-
{
57-
name: "GraphQLError",
58-
message: "Upload serialization unsupported.",
59-
},
60-
);
61-
});
62-
};
49+
it("Method `serialize`.", () => {
50+
throws(
51+
() => {
52+
// The dummy value is irrelevant.
53+
GraphQLUpload.serialize("");
54+
},
55+
{
56+
name: "GraphQLError",
57+
message: "Upload serialization unsupported.",
58+
},
59+
);
60+
});
61+
},
62+
);

Upload.test.mjs

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
// @ts-check
22

33
import { ok, rejects, strictEqual } from "node:assert";
4+
import { describe, it } from "node:test";
45

56
import Upload from "./Upload.mjs";
67

7-
/**
8-
* Adds `Upload` tests.
9-
* @param {import("test-director").default} tests Test director.
10-
*/
11-
export default (tests) => {
12-
tests.add("`Upload` class resolving a file.", async () => {
13-
const upload = new Upload();
8+
describe(
9+
"Class `Upload`.",
10+
{
11+
concurrency: true,
12+
},
13+
() => {
14+
it("Resolving a file.", async () => {
15+
const upload = new Upload();
1416

15-
ok(upload.promise instanceof Promise);
16-
strictEqual(typeof upload.resolve, "function");
17+
ok(upload.promise instanceof Promise);
18+
strictEqual(typeof upload.resolve, "function");
1719

18-
/** @type {any} */
19-
const file = {};
20+
/** @type {any} */
21+
const file = {};
2022

21-
upload.resolve(file);
23+
upload.resolve(file);
2224

23-
const resolved = await upload.promise;
25+
const resolved = await upload.promise;
2426

25-
strictEqual(resolved, file);
26-
strictEqual(upload.file, file);
27-
});
27+
strictEqual(resolved, file);
28+
strictEqual(upload.file, file);
29+
});
2830

29-
tests.add("`Upload` class with a handled rejection.", async () => {
30-
const upload = new Upload();
31+
it("Handled rejection.", async () => {
32+
const upload = new Upload();
3133

32-
ok(upload.promise instanceof Promise);
33-
strictEqual(typeof upload.reject, "function");
34+
ok(upload.promise instanceof Promise);
35+
strictEqual(typeof upload.reject, "function");
3436

35-
const error = new Error("Message.");
37+
const error = new Error("Message.");
3638

37-
upload.reject(error);
39+
upload.reject(error);
3840

39-
// This is the safe way to check the promise status, see:
40-
// https://github.com/nodejs/node/issues/31392#issuecomment-575451230
41-
await rejects(Promise.race([upload.promise, Promise.resolve()]), error);
42-
});
41+
// This is the safe way to check the promise status, see:
42+
// https://github.com/nodejs/node/issues/31392#issuecomment-575451230
43+
await rejects(Promise.race([upload.promise, Promise.resolve()]), error);
44+
});
4345

44-
tests.add("`Upload` class with an unhandled rejection.", async () => {
45-
const upload = new Upload();
46+
it("Unhandled rejection.", async () => {
47+
const upload = new Upload();
4648

47-
ok(upload.promise instanceof Promise);
48-
strictEqual(typeof upload.reject, "function");
49+
ok(upload.promise instanceof Promise);
50+
strictEqual(typeof upload.reject, "function");
4951

50-
const error = new Error("Message.");
52+
const error = new Error("Message.");
5153

52-
upload.reject(error);
54+
upload.reject(error);
5355

54-
// Node.js CLI flag `--unhandled-rejections=throw` must be used when these
55-
// tests are run with Node.js v14 (it’s unnecessary for Node.js v15+) or the
56-
// process won’t exit with an error if the unhandled rejection is’t silenced
57-
// as intended.
58-
});
59-
};
56+
// Node.js CLI flag `--unhandled-rejections=throw` must be used when these
57+
// tests are run with Node.js v14 (it’s unnecessary for Node.js v15+) or
58+
// the process won’t exit with an error if the unhandled rejection is’t
59+
// silenced as intended.
60+
});
61+
},
62+
);

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
### Major
66

7-
- Updated Node.js support to `^18.15.0 || >=20.4.0`.
7+
- Updated Node.js support to `^18.18.0 || ^20.9.0 || >=22.0.0`.
88
- Updated dev dependencies, some of which require newer Node.js versions than previously supported.
99
- Refactored tests to use the standard `AbortController`, `fetch`, `File`, and `FormData` APIs available in modern Node.js and removed the dev dependencies [`node-abort-controller`](https://npm.im/node-abort-controller) and [`node-fetch`](https://npm.im/node-fetch).
1010
- Replaced the test utility function `streamToString` with the function `text` from `node:stream/consumers` that’s available in modern Node.js.
11+
- Use the Node.js test runner API and remove the dev dependency [`test-director`](https://npm.im/test-director).
1112

1213
### Minor
1314

graphqlUploadExpress.test.mjs

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "./test/polyfillFile.mjs";
44

55
import { deepStrictEqual, ok, strictEqual } from "node:assert";
66
import { createServer } from "node:http";
7+
import { describe, it } from "node:test";
78

89
import express from "express";
910
import createError from "http-errors";
@@ -12,14 +13,13 @@ import graphqlUploadExpress from "./graphqlUploadExpress.mjs";
1213
import processRequest from "./processRequest.mjs";
1314
import listen from "./test/listen.mjs";
1415

15-
/**
16-
* Adds `graphqlUploadExpress` tests.
17-
* @param {import("test-director").default} tests Test director.
18-
*/
19-
export default (tests) => {
20-
tests.add(
21-
"`graphqlUploadExpress` with a non multipart request.",
22-
async () => {
16+
describe(
17+
"Function `graphqlUploadExpress`.",
18+
{
19+
concurrency: true,
20+
},
21+
() => {
22+
it("Non multipart request.", async () => {
2323
let processRequestRan = false;
2424

2525
const app = express().use(
@@ -39,48 +39,48 @@ export default (tests) => {
3939
} finally {
4040
close();
4141
}
42-
},
43-
);
44-
45-
tests.add("`graphqlUploadExpress` with a multipart request.", async () => {
46-
/**
47-
* @type {{
48-
* variables: {
49-
* file: import("./Upload.mjs").default,
50-
* },
51-
* } | undefined}
52-
*/
53-
let requestBody;
54-
55-
const app = express()
56-
.use(graphqlUploadExpress())
57-
.use((request, response, next) => {
58-
requestBody = request.body;
59-
next();
60-
});
61-
62-
const { port, close } = await listen(createServer(app));
63-
64-
try {
65-
const body = new FormData();
66-
67-
body.append("operations", JSON.stringify({ variables: { file: null } }));
68-
body.append("map", JSON.stringify({ 1: ["variables.file"] }));
69-
body.append("1", new File(["a"], "a.txt", { type: "text/plain" }));
70-
71-
await fetch(`http://localhost:${port}`, { method: "POST", body });
72-
73-
ok(requestBody);
74-
ok(requestBody.variables);
75-
ok(requestBody.variables.file);
76-
} finally {
77-
close();
78-
}
79-
});
80-
81-
tests.add(
82-
"`graphqlUploadExpress` with a multipart request and option `processRequest`.",
83-
async () => {
42+
});
43+
44+
it("Multipart request.", async () => {
45+
/**
46+
* @type {{
47+
* variables: {
48+
* file: import("./Upload.mjs").default,
49+
* },
50+
* } | undefined}
51+
*/
52+
let requestBody;
53+
54+
const app = express()
55+
.use(graphqlUploadExpress())
56+
.use((request, response, next) => {
57+
requestBody = request.body;
58+
next();
59+
});
60+
61+
const { port, close } = await listen(createServer(app));
62+
63+
try {
64+
const body = new FormData();
65+
66+
body.append(
67+
"operations",
68+
JSON.stringify({ variables: { file: null } }),
69+
);
70+
body.append("map", JSON.stringify({ 1: ["variables.file"] }));
71+
body.append("1", new File(["a"], "a.txt", { type: "text/plain" }));
72+
73+
await fetch(`http://localhost:${port}`, { method: "POST", body });
74+
75+
ok(requestBody);
76+
ok(requestBody.variables);
77+
ok(requestBody.variables.file);
78+
} finally {
79+
close();
80+
}
81+
});
82+
83+
it("Multipart request and option `processRequest`.", async () => {
8484
let processRequestRan = false;
8585

8686
/**
@@ -127,12 +127,9 @@ export default (tests) => {
127127
} finally {
128128
close();
129129
}
130-
},
131-
);
130+
});
132131

133-
tests.add(
134-
"`graphqlUploadExpress` with a multipart request and option `processRequest` throwing an exposed HTTP error.",
135-
async () => {
132+
it("Multipart request and option `processRequest` throwing an exposed HTTP error.", async () => {
136133
let expressError;
137134
let requestCompleted;
138135
let responseStatusCode;
@@ -201,12 +198,9 @@ export default (tests) => {
201198
} finally {
202199
close();
203200
}
204-
},
205-
);
201+
});
206202

207-
tests.add(
208-
"`graphqlUploadExpress` with a multipart request following middleware throwing an error.",
209-
async () => {
203+
it("Multipart request following middleware throwing an error.", async () => {
210204
let expressError;
211205
let requestCompleted;
212206

@@ -268,6 +262,6 @@ export default (tests) => {
268262
} finally {
269263
close();
270264
}
271-
},
272-
);
273-
};
265+
});
266+
},
267+
);

0 commit comments

Comments
 (0)