Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions types/node/node-tests-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./test/events-dom";
import "./test/globals-dom";
import "./test/perf_hooks-dom";
3 changes: 3 additions & 0 deletions types/node/node-tests-non-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "./test/events-non-dom";
import "./test/globals-non-dom";
import "./test/perf_hooks-non-dom";
1 change: 0 additions & 1 deletion types/node/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import "./test/crypto";
import "./test/dgram";
import "./test/diagnostics_channel";
import "./test/dns";
import "./test/dom-events"; // dom-events behaves differently under lib-dom
import "./test/events";
import "./test/events_generic";
import "./test/fs";
Expand Down
9 changes: 1 addition & 8 deletions types/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
"projects": [
"https://nodejs.org/"
],
"types": "index",
"typesVersions": {
"<=4.8": {
"*": [
"ts4.8/*"
]
}
},
"tsconfigs": ["tsconfig.dom.json", "tsconfig.non-dom.json"],
"dependencies": {
"undici-types": "~5.26.4"
},
Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions types/node/test/globals-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// fetch
{
// This tsconfig.json references lib.dom.d.ts. The fetch
// types included in globals.d.ts are designed to be empty
// merges when lib.dom.d.ts is included. This test ensures
// the merge works, but the types observed are from lib.dom.d.ts.
fetch("https://example.com").then(response => {
response.arrayBuffer(); // $ExpectType Promise<ArrayBuffer>
response.blob(); // $ExpectType Promise<Blob>
response.formData(); // $ExpectType Promise<FormData>

// undici-types uses `Promise<unknown>` for `json()`
// This $ExpectType will change if tsconfig.json drops
// lib.dom.d.ts.
response.json(); // $ExpectType Promise<any>
response.text(); // $ExpectType Promise<string>
});
const fd = new FormData();
fd.append("foo", "bar");
const headers = new Headers();
headers.append("Accept", "application/json");
fetch("https://example.com", { body: fd });

fetch(new URL("https://example.com"), {
// @ts-expect-error this should not be available when lib.dom.d.ts is present
dispatcher: undefined,
});

const reqinit: RequestInit = {};
reqinit.method; // $ExpectType string | undefined
const resinit: ResponseInit = {};
resinit.status; // $ExpectType number | undefined

const f: File = {} as any;
f.name; // $ExpectType string
}

{
crypto.randomUUID(); // $ExpectType `${string}-${string}-${string}-${string}-${string}` || string
crypto.getRandomValues(Buffer.alloc(8)); // $ExpectType Buffer
crypto.getRandomValues(new BigInt64Array(4)); // $ExpectType BigInt64Array

crypto.subtle.generateKey({ name: "HMAC", hash: "SHA-1" }, true, ["sign", "decrypt", "deriveBits"]).then(
(out) => {
out.algorithm; // $ExpectType KeyAlgorithm
out.extractable; // $ExpectType boolean
out.usages; // $ExpectType KeyUsage[]
},
);
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,3 @@
//////////////////////////////////////////////////////////////////////////
/// `globalThis` Tests: https://node.green/#ES2020-features-globalThis ///
//////////////////////////////////////////////////////////////////////////

{
const isGlobalThis: typeof globalThis = global;

const accessibleToGlobalThisMembers: true = global.RANDOM_GLOBAL_VARIABLE;
}

declare var RANDOM_GLOBAL_VARIABLE: true;

// global aliases for compatibility
{
const x: NodeModule = {} as any;
const y: NodeModule = {} as any;
x.children.push(y);
x.parent = require.main!;
require.main = y;
x.path; // $ExpectType string
}

// exposed gc
{
if (gc) {
gc();
}
}

// structuredClone
{
structuredClone(123); // $ExpectType 123
structuredClone("hello"); // $ExpectType "hello"
structuredClone({ test: 123 }); // $ExpectType { test: number; }
structuredClone([{ test: 123 }]); // $ExpectType { test: number; }[]

const arrayBuffer = new ArrayBuffer(0);
structuredClone({ test: arrayBuffer }, { transfer: [arrayBuffer] }); // $ExpectType { test: ArrayBuffer; }
}

// Array.prototype.at()
{
const mutableArray = ["a"];
mutableArray.at(-1);
const readonlyArray: readonly string[] = ["b"];
readonlyArray.at(-1);
}

{
const x = new AbortController().signal;
x.reason; // $ExpectType any
x.throwIfAborted(); // $ExpectType void
}

// fetch
{
fetch("https://example.com").then(response => {
Expand Down
51 changes: 0 additions & 51 deletions types/node/test/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,54 +51,3 @@ declare var RANDOM_GLOBAL_VARIABLE: true;
x.reason; // $ExpectType any
x.throwIfAborted(); // $ExpectType void
}

// fetch
{
// This tsconfig.json references lib.dom.d.ts. The fetch
// types included in globals.d.ts are designed to be empty
// merges when lib.dom.d.ts is included. This test ensures
// the merge works, but the types observed are from lib.dom.d.ts.
fetch("https://example.com").then(response => {
response.arrayBuffer(); // $ExpectType Promise<ArrayBuffer>
response.blob(); // $ExpectType Promise<Blob>
response.formData(); // $ExpectType Promise<FormData>

// undici-types uses `Promise<unknown>` for `json()`
// This $ExpectType will change if tsconfig.json drops
// lib.dom.d.ts.
response.json(); // $ExpectType Promise<any>
response.text(); // $ExpectType Promise<string>
});
const fd = new FormData();
fd.append("foo", "bar");
const headers = new Headers();
headers.append("Accept", "application/json");
fetch("https://example.com", { body: fd });

fetch(new URL("https://example.com"), {
// @ts-expect-error this should not be available when lib.dom.d.ts is present
dispatcher: undefined,
});

const reqinit: RequestInit = {};
reqinit.method; // $ExpectType string | undefined
const resinit: ResponseInit = {};
resinit.status; // $ExpectType number | undefined

const f: File = {} as any;
f.name; // $ExpectType string
}

{
crypto.randomUUID(); // $ExpectType `${string}-${string}-${string}-${string}-${string}` || string
crypto.getRandomValues(Buffer.alloc(8)); // $ExpectType Buffer
crypto.getRandomValues(new BigInt64Array(4)); // $ExpectType BigInt64Array

crypto.subtle.generateKey({ name: "HMAC", hash: "SHA-1" }, true, ["sign", "decrypt", "deriveBits"]).then(
(out) => {
out.algorithm; // $ExpectType KeyAlgorithm
out.extractable; // $ExpectType boolean
out.usages; // $ExpectType KeyUsage[]
},
);
}
2 changes: 2 additions & 0 deletions types/node/test/perf_hooks-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error - Node API isn't available in DOM environment
performance.eventLoopUtilization();
1 change: 1 addition & 0 deletions types/node/test/perf_hooks-non-dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
performance.eventLoopUtilization();
3 changes: 0 additions & 3 deletions types/node/test/perf_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ const mean: number = monitor.mean;
const stddev: number = monitor.stddev;
const exceeds: number = monitor.exceeds;

// @ts-expect-error - Node API isn't available in DOM environment
performance.eventLoopUtilization();

let histogram: RecordableHistogram = createHistogram({
figures: 123,
min: 1,
Expand Down
Loading