Skip to content

Commit fb8b735

Browse files
authored
🤖 Merge PR DefinitelyTyped#72596 [node] globals.d.ts housekeeping by @Renegade334
1 parent 9835151 commit fb8b735

File tree

9 files changed

+547
-1276
lines changed

9 files changed

+547
-1276
lines changed

types/node/globals.d.ts

Lines changed: 140 additions & 280 deletions
Large diffs are not rendered by default.

types/node/node-tests.ts

Lines changed: 0 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -44,181 +44,3 @@ import "./test/vm";
4444
import "./test/wasi";
4545
import "./test/worker_threads";
4646
import "./test/zlib";
47-
48-
import * as http from "node:http";
49-
import * as http2 from "node:http2";
50-
import * as https from "node:https";
51-
import * as inspector from "node:inspector";
52-
import * as net from "node:net";
53-
import * as stream from "node:stream";
54-
import * as trace_events from "node:trace_events";
55-
import * as url from "node:url";
56-
57-
//////////////////////////////////////////////////////
58-
/// Https tests : https://nodejs.org/api/https.html ///
59-
//////////////////////////////////////////////////////
60-
61-
{
62-
let agent: https.Agent = new https.Agent({
63-
keepAlive: true,
64-
keepAliveMsecs: 10000,
65-
maxSockets: Infinity,
66-
maxFreeSockets: 256,
67-
maxCachedSessions: 100,
68-
timeout: 15000,
69-
family: 4,
70-
});
71-
72-
agent = https.globalAgent;
73-
74-
let sockets: NodeJS.ReadOnlyDict<net.Socket[]> = agent.sockets;
75-
sockets = agent.freeSockets;
76-
77-
https.request({
78-
agent: false,
79-
});
80-
https.request({
81-
agent,
82-
});
83-
https.request({
84-
agent: undefined,
85-
});
86-
87-
https.get("http://www.example.com/xyz");
88-
https.request("http://www.example.com/xyz");
89-
90-
https.get("http://www.example.com/xyz", (res: http.IncomingMessage): void => {});
91-
https.request("http://www.example.com/xyz", (res: http.IncomingMessage): void => {});
92-
93-
https.get(new url.URL("http://www.example.com/xyz"));
94-
https.request(new url.URL("http://www.example.com/xyz"));
95-
96-
https.get(new url.URL("http://www.example.com/xyz"), (res: http.IncomingMessage): void => {});
97-
https.request(new url.URL("http://www.example.com/xyz"), (res: http.IncomingMessage): void => {});
98-
99-
const opts: https.RequestOptions = {
100-
path: "/some/path",
101-
};
102-
https.get(new url.URL("http://www.example.com"), opts);
103-
https.request(new url.URL("http://www.example.com"), opts);
104-
https.get(new url.URL("http://www.example.com/xyz"), opts, (res: http.IncomingMessage): void => {});
105-
https.request(new url.URL("http://www.example.com/xyz"), opts, (res: http.IncomingMessage): void => {});
106-
107-
https.globalAgent.options.ca = [];
108-
109-
{
110-
function reqListener(req: http.IncomingMessage, res: http.ServerResponse): void {}
111-
112-
class MyIncomingMessage extends http.IncomingMessage {
113-
foo: number;
114-
}
115-
116-
class MyServerResponse<Request extends http.IncomingMessage = http.IncomingMessage>
117-
extends http.ServerResponse<Request>
118-
{
119-
foo: string;
120-
}
121-
122-
let server: https.Server;
123-
124-
server = new https.Server();
125-
server = new https.Server(reqListener);
126-
server = new https.Server({ IncomingMessage: MyIncomingMessage });
127-
128-
server = new https.Server({
129-
IncomingMessage: MyIncomingMessage,
130-
ServerResponse: MyServerResponse,
131-
}, reqListener);
132-
133-
server = https.createServer();
134-
server = https.createServer(reqListener);
135-
server = https.createServer({ IncomingMessage: MyIncomingMessage });
136-
server = https.createServer({ ServerResponse: MyServerResponse }, reqListener);
137-
138-
const timeout: number = server.timeout;
139-
const listening: boolean = server.listening;
140-
const keepAliveTimeout: number = server.keepAliveTimeout;
141-
const maxHeadersCount: number | null = server.maxHeadersCount;
142-
const headersTimeout: number = server.headersTimeout;
143-
server.setTimeout().setTimeout(1000).setTimeout(() => {}).setTimeout(100, () => {});
144-
}
145-
}
146-
147-
/////////////////////////////////////////////////////////
148-
/// Errors Tests : https://nodejs.org/api/errors.html ///
149-
/////////////////////////////////////////////////////////
150-
151-
{
152-
{
153-
Error.stackTraceLimit = Infinity;
154-
}
155-
{
156-
const myObject = {};
157-
Error.captureStackTrace(myObject);
158-
}
159-
{
160-
const frames: NodeJS.CallSite[] = [];
161-
Error.prepareStackTrace!(new Error(), frames);
162-
}
163-
{
164-
const frame: NodeJS.CallSite = null!;
165-
const frameThis: unknown = frame.getThis();
166-
const typeName: string | null = frame.getTypeName();
167-
const func: Function | undefined = frame.getFunction();
168-
const funcName: string | null = frame.getFunctionName();
169-
const meth: string | null = frame.getMethodName();
170-
const fname: string | undefined = frame.getFileName();
171-
const lineno: number | null = frame.getLineNumber();
172-
const colno: number | null = frame.getColumnNumber();
173-
const evalOrigin: string | undefined = frame.getEvalOrigin();
174-
const isTop: boolean = frame.isToplevel();
175-
const isEval: boolean = frame.isEval();
176-
const isNative: boolean = frame.isNative();
177-
const isConstr: boolean = frame.isConstructor();
178-
}
179-
}
180-
181-
/*****************************************************************************
182-
* *
183-
* The following tests are the modules not mentioned in document but existed *
184-
* *
185-
*****************************************************************************/
186-
187-
///////////////////////////////////////////////////////////
188-
/// Trace Events Tests ///
189-
///////////////////////////////////////////////////////////
190-
191-
{
192-
const enabledCategories: string | undefined = trace_events.getEnabledCategories();
193-
const tracing: trace_events.Tracing = trace_events.createTracing({ categories: ["node", "v8"] });
194-
const categories: string = tracing.categories;
195-
const enabled: boolean = tracing.enabled;
196-
tracing.enable();
197-
tracing.disable();
198-
}
199-
200-
////////////////////////////////////////////////////
201-
/// Node.js ESNEXT Support
202-
////////////////////////////////////////////////////
203-
204-
{
205-
const s = "foo";
206-
const s1: string = s.trimLeft();
207-
const s2: string = s.trimRight();
208-
const s3: string = s.trimStart();
209-
const s4: string = s.trimEnd();
210-
}
211-
212-
////////////////////////////////////////////////////
213-
/// Node.js http2 tests
214-
////////////////////////////////////////////////////
215-
216-
{
217-
http2.connect("https://foo.com", {
218-
createConnection: (authority, option) => {
219-
authority; // $ExpectType URL
220-
option; // $ExpectType SessionOptions
221-
return new stream.Duplex();
222-
},
223-
});
224-
}

types/node/test/globals.ts

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,62 @@
1-
//////////////////////////////////////////////////////////////////////////
2-
/// `globalThis` Tests: https://node.green/#ES2020-features-globalThis ///
3-
//////////////////////////////////////////////////////////////////////////
4-
1+
// global / globalThis
52
{
63
const isGlobalThis: typeof globalThis = global;
7-
8-
const accessibleToGlobalThisMembers: true = global.RANDOM_GLOBAL_VARIABLE;
4+
const accessibleAsGlobalProperty: true = global.RANDOM_GLOBAL_VARIABLE;
95
}
106

117
declare var RANDOM_GLOBAL_VARIABLE: true;
128

13-
// exposed gc
9+
// ErrorConstructor
10+
{
11+
{
12+
Error.stackTraceLimit = Infinity;
13+
}
14+
{
15+
const myObject = {};
16+
Error.captureStackTrace(myObject);
17+
}
18+
{
19+
const original = Error.prepareStackTrace;
20+
Error.prepareStackTrace = (error, frames) => {
21+
error; // $ExpectType Error
22+
23+
const [frame] = frames;
24+
frame.getColumnNumber(); // $ExpectType number | null
25+
frame.getEnclosingColumnNumber(); // $ExpectType number | null
26+
frame.getEnclosingLineNumber(); // $ExpectType number | null
27+
frame.getEvalOrigin(); // $ExpectType string | undefined
28+
frame.getFileName(); // $ExpectType string | null
29+
frame.getFunction(); // $ExpectType Function | undefined
30+
frame.getFunctionName(); // $ExpectType string | null
31+
frame.getLineNumber(); // $ExpectType number | null
32+
frame.getMethodName(); // $ExpectType string | null
33+
frame.getPosition(); // $ExpectType number
34+
frame.getPromiseIndex(); // $ExpectType number | null
35+
frame.getScriptHash(); // $ExpectType string
36+
frame.getScriptNameOrSourceURL(); // $ExpectType string | null
37+
frame.getThis(); // $ExpectType unknown
38+
frame.getTypeName(); // $ExpectType string | null
39+
frame.isAsync(); // $ExpectType boolean
40+
frame.isConstructor(); // $ExpectType boolean
41+
frame.isEval(); // $ExpectType boolean
42+
frame.isNative(); // $ExpectType boolean
43+
frame.isPromiseAll(); // $ExpectType boolean
44+
frame.isToplevel(); // $ExpectType boolean
45+
46+
return original(error, frames);
47+
};
48+
}
49+
}
50+
51+
// gc()
1452
{
15-
if (gc) {
16-
gc();
17-
gc(true);
53+
if (typeof gc === "function") {
54+
gc(); // $ExpectType void
55+
gc(true); // $ExpectType void
56+
gc({ flavor: "regular", type: "major-snapshot", filename: "/tmp/snapshot" }); // $ExpectType void
1857
gc({ execution: "sync" }); // $ExpectType void
1958
gc({ execution: "async" }); // $ExpectType Promise<void>
20-
gc({ execution: "async", flavor: "regular", type: "major" }); // $ExpectType Promise<void>
59+
gc({ execution: Math.random() > 0.5 ? "sync" : "async" }); // $ExpectType void
2160
}
2261
}
2362

0 commit comments

Comments
 (0)