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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions types/node/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4324,6 +4324,18 @@ declare module "fs" {
* Function to filter out files/directories. Return true to exclude the item, false to include it.
*/
exclude?: ((fileName: string) => boolean) | undefined;
/**
* `true` if the glob should return paths as `Dirent`s, `false` otherwise.
* @default false
* @since v22.2.0
*/
withFileTypes?: boolean | undefined;
}
export interface GlobOptionsWithFileTypes extends GlobOptions {
withFileTypes: true;
}
export interface GlobOptionsWithoutFileTypes extends GlobOptions {
withFileTypes?: false | undefined;
}
/**
* Retrieves the files matching the specified pattern.
Expand All @@ -4332,15 +4344,46 @@ declare module "fs" {
pattern: string | string[],
callback: (err: NodeJS.ErrnoException | null, matches: string[]) => void,
): void;
export function glob(
pattern: string | string[],
options: GlobOptionsWithFileTypes,
callback: (
err: NodeJS.ErrnoException | null,
matches: Dirent[],
) => void,
): void;
export function glob(
pattern: string | string[],
options: GlobOptionsWithoutFileTypes,
callback: (
err: NodeJS.ErrnoException | null,
matches: string[],
) => void,
): void;
export function glob(
pattern: string | string[],
options: GlobOptions,
callback: (err: NodeJS.ErrnoException | null, matches: string[]) => void,
callback: (
err: NodeJS.ErrnoException | null,
matches: Dirent[] | string[],
) => void,
): void;
/**
* Retrieves the files matching the specified pattern.
*/
export function globSync(pattern: string | string[], options?: GlobOptions): string[];
export function globSync(pattern: string | string[]): string[];
export function globSync(
pattern: string | string[],
options: GlobOptionsWithFileTypes,
): Dirent[];
export function globSync(
pattern: string | string[],
options: GlobOptionsWithoutFileTypes,
): string[];
export function globSync(
pattern: string | string[],
options: GlobOptions,
): Dirent[] | string[];
}
declare module "node:fs" {
export * from "fs";
Expand Down
16 changes: 15 additions & 1 deletion types/node/fs/promises.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ declare module "fs/promises" {
Dir,
Dirent,
GlobOptions,
GlobOptionsWithFileTypes,
GlobOptionsWithoutFileTypes,
MakeDirectoryOptions,
Mode,
ObjectEncodingOptions,
Expand Down Expand Up @@ -1243,7 +1245,19 @@ declare module "fs/promises" {
/**
* Retrieves the files matching the specified pattern.
*/
function glob(pattern: string | string[], options?: GlobOptions): AsyncIterableIterator<string>;
function glob(pattern: string | string[]): AsyncIterableIterator<string>;
function glob(
pattern: string | string[],
opt: GlobOptionsWithFileTypes,
): AsyncIterableIterator<Dirent>;
function glob(
pattern: string | string[],
opt: GlobOptionsWithoutFileTypes,
): AsyncIterableIterator<string>;
function glob(
pattern: string | string[],
opt: GlobOptions,
): AsyncIterableIterator<Dirent> | AsyncIterableIterator<string>;
}
declare module "node:fs/promises" {
export * from "fs/promises";
Expand Down
2 changes: 1 addition & 1 deletion types/node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/node",
"version": "22.1.9999",
"version": "22.2.9999",
"nonNpm": "conflict",
"nonNpmDescription": "Node.js",
"projects": [
Expand Down
38 changes: 37 additions & 1 deletion types/node/perf_hooks.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@
*/
declare module "perf_hooks" {
import { AsyncResource } from "node:async_hooks";
type EntryType = "node" | "mark" | "measure" | "gc" | "function" | "http2" | "http" | "dns" | "net";
type EntryType =
| "dns" // Node.js only
| "function" // Node.js only
| "gc" // Node.js only
| "http2" // Node.js only
| "http" // Node.js only
| "mark" // available on the Web
| "measure" // available on the Web
| "net" // Node.js only
| "node" // Node.js only
| "resource"; // available on the Web
interface NodeGCPerformanceDetail {
/**
* When `performanceEntry.entryType` is equal to 'gc', the `performance.kind` property identifies
Expand Down Expand Up @@ -114,6 +124,7 @@ declare module "perf_hooks" {
* @since v8.5.0
*/
class PerformanceNodeTiming extends PerformanceEntry {
readonly entryType: "node";
/**
* The high resolution millisecond timestamp at which the Node.js process
* completed bootstrapping. If bootstrapping has not yet finished, the property
Expand Down Expand Up @@ -270,6 +281,30 @@ declare module "perf_hooks" {
* @param name
*/
mark(name: string, options?: MarkOptions): PerformanceMark;
/**
* Creates a new `PerformanceResourceTiming` entry in the Resource Timeline.
* A `PerformanceResourceTiming` is a subclass of `PerformanceEntry` whose `performanceEntry.entryType` is always `'resource'`.
* Performance resources are used to mark moments in the Resource Timeline.
* @param timingInfo [Fetch Timing Info](https://fetch.spec.whatwg.org/#fetch-timing-info)
* @param requestedUrl The resource url
* @param initiatorType The initiator name, e.g: 'fetch'
* @param global
* @param cacheMode The cache mode must be an empty string ('') or 'local'
* @param bodyInfo [Fetch Response Body Info](https://fetch.spec.whatwg.org/#response-body-info)
* @param responseStatus The response's status code
* @param deliveryType The delivery type. Default: ''.
* @since v18.2.0, v16.17.0
*/
markResourceTiming(
timingInfo: object,
requestedUrl: string,
initiatorType: string,
global: object,
cacheMode: "" | "local",
bodyInfo: object,
responseStatus: number,
deliveryType?: string,
): PerformanceResourceTiming;
/**
* Creates a new PerformanceMeasure entry in the Performance Timeline.
* A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure',
Expand Down Expand Up @@ -543,6 +578,7 @@ declare module "perf_hooks" {
* @since v18.2.0, v16.17.0
*/
class PerformanceResourceTiming extends PerformanceEntry {
readonly entryType: "resource";
protected constructor();
/**
* The high resolution millisecond timestamp at immediately before dispatching the `fetch`
Expand Down
120 changes: 120 additions & 0 deletions types/node/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ declare module "node:test" {
* @since v18.0.0, v16.17.0
*/
class TestContext {
/**
* An object containing assertion methods bound to the test context.
* The top-level functions from the `node:assert` module are exposed here for the purpose of creating test plans.
* @since v22.2.0
*/
readonly assert: TestContextAssert;
/**
* This function is used to create a hook running before subtest of the current test.
* @param fn The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
Expand Down Expand Up @@ -508,6 +514,42 @@ declare module "node:test" {
* @since v18.8.0, v16.18.0
*/
readonly name: string;
/**
* Used to set the number of assertions and subtests that are expected to run within the test.
* If the number of assertions and subtests that run does not match the expected count, the test will fail.
*
* To make sure assertions are tracked, the assert functions on `context.assert` must be used,
* instead of importing from the `node:assert` module.
* ```js
* test('top level test', (t) => {
* t.plan(2);
* t.assert.ok('some relevant assertion here');
* t.test('subtest', () => {});
* });
* ```
*
* When working with asynchronous code, the `plan` function can be used to ensure that the correct number of assertions are run:
* ```js
* test('planning with streams', (t, done) => {
* function* generate() {
* yield 'a';
* yield 'b';
* yield 'c';
* }
* const expected = ['a', 'b', 'c'];
* t.plan(expected.length);
* const stream = Readable.from(generate());
* stream.on('data', (chunk) => {
* t.assert.strictEqual(chunk, expected.shift());
* });
* stream.on('end', () => {
* done();
* });
* });
* ```
* @since v22.2.0
*/
plan(count: number): void;
/**
* If `shouldRunOnlyTests` is truthy, the test context will only run tests that
* have the `only` option set. Otherwise, all tests are run. If Node.js was not
Expand Down Expand Up @@ -584,6 +626,76 @@ declare module "node:test" {
*/
readonly mock: MockTracker;
}
interface TestContextAssert {
/**
* Identical to the `deepEqual` function from the `node:assert` module, but bound to the test context.
*/
deepEqual: typeof import("node:assert").deepEqual;
/**
* Identical to the `deepStrictEqual` function from the `node:assert` module, but bound to the test context.
*/
deepStrictEqual: typeof import("node:assert").deepStrictEqual;
/**
* Identical to the `doesNotMatch` function from the `node:assert` module, but bound to the test context.
*/
doesNotMatch: typeof import("node:assert").doesNotMatch;
/**
* Identical to the `doesNotReject` function from the `node:assert` module, but bound to the test context.
*/
doesNotReject: typeof import("node:assert").doesNotReject;
/**
* Identical to the `doesNotThrow` function from the `node:assert` module, but bound to the test context.
*/
doesNotThrow: typeof import("node:assert").doesNotThrow;
/**
* Identical to the `equal` function from the `node:assert` module, but bound to the test context.
*/
equal: typeof import("node:assert").equal;
/**
* Identical to the `fail` function from the `node:assert` module, but bound to the test context.
*/
fail: typeof import("node:assert").fail;
/**
* Identical to the `ifError` function from the `node:assert` module, but bound to the test context.
*/
ifError: typeof import("node:assert").ifError;
/**
* Identical to the `match` function from the `node:assert` module, but bound to the test context.
*/
match: typeof import("node:assert").match;
/**
* Identical to the `notDeepEqual` function from the `node:assert` module, but bound to the test context.
*/
notDeepEqual: typeof import("node:assert").notDeepEqual;
/**
* Identical to the `notDeepStrictEqual` function from the `node:assert` module, but bound to the test context.
*/
notDeepStrictEqual: typeof import("node:assert").notDeepStrictEqual;
/**
* Identical to the `notEqual` function from the `node:assert` module, but bound to the test context.
*/
notEqual: typeof import("node:assert").notEqual;
/**
* Identical to the `notStrictEqual` function from the `node:assert` module, but bound to the test context.
*/
notStrictEqual: typeof import("node:assert").notStrictEqual;
/**
* Identical to the `ok` function from the `node:assert` module, but bound to the test context.
*/
ok: typeof import("node:assert").ok;
/**
* Identical to the `rejects` function from the `node:assert` module, but bound to the test context.
*/
rejects: typeof import("node:assert").rejects;
/**
* Identical to the `strictEqual` function from the `node:assert` module, but bound to the test context.
*/
strictEqual: typeof import("node:assert").strictEqual;
/**
* Identical to the `throws` function from the `node:assert` module, but bound to the test context.
*/
throws: typeof import("node:assert").throws;
}

/**
* An instance of `SuiteContext` is passed to each suite function in order to
Expand Down Expand Up @@ -643,6 +755,14 @@ declare module "node:test" {
* @default false
*/
todo?: boolean | string | undefined;
/**
* The number of assertions and subtests expected to be run in the test.
* If the number of assertions run in the test does not match the number
* specified in the plan, the test will fail.
* @default undefined
* @since v22.2.0
*/
plan?: number | undefined;
}
/**
* This function creates a hook that runs before executing a suite.
Expand Down
18 changes: 18 additions & 0 deletions types/node/test/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,12 @@ const anyStatFs: fs.StatsFs | fs.BigIntStatsFs = fs.statfsSync(".", { bigint: Ma
for await (const entry of globAsync("**/*.js")) {
entry; // $ExpectType string
}
for await (const entry of globAsync("**/*.js", { withFileTypes: true })) {
entry; // $ExpectType Dirent
}
for await (const entry of globAsync("**/*.js", { withFileTypes: Math.random() > 0.5 })) {
entry; // $ExpectType Dirent | string
}

glob("**/*.js", (err, matches) => {
matches; // $ExpectType string[]
Expand All @@ -919,11 +925,23 @@ const anyStatFs: fs.StatsFs | fs.BigIntStatsFs = fs.statfsSync(".", { bigint: Ma
matches; // $ExpectType string[]
},
);
glob("**/*.js", { withFileTypes: true }, (err, matches) => {
matches; // $ExpectType Dirent[]
});
glob("**/*.js", { withFileTypes: Math.random() > 0.5 }, (err, matches) => {
matches; // $ExpectType Dirent[] | string[]
});

for (const entry of globSync("**/*.js")) {
entry; // $ExpectType string
}
for (const entry of globSync("**/*.js", { cwd: "/" })) {
entry; // $ExpectType string
}
for (const entry of globSync("**/*.js", { withFileTypes: true })) {
entry; // $ExpectType Dirent
}
for (const entry of globSync("**/*.js", { withFileTypes: Math.random() > 0.5 })) {
entry; // $ExpectType Dirent | string
}
});
31 changes: 31 additions & 0 deletions types/node/test/perf_hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,34 @@ performance.getEntriesByName("test")[0]; // $ExpectType PerformanceEntry
performance.getEntriesByName("test", "mark")[0]; // $ExpectType PerformanceEntry

performance.getEntriesByType("mark")[0]; // $ExpectType PerformanceEntry

const resource = NodePerf.markResourceTiming(
{
startTime: 0,
endTime: 0,
finalServiceWorkerStartTime: 0,
redirectStartTime: 0,
redirectEndTime: 0,
postRedirectStartTime: 0,
finalConnectionTimingInfo: {
domainLookupStartTime: 0,
domainLookupEndTime: 0,
connectionStartTime: 0,
connectionEndTime: 0,
secureConnectionStartTime: 0,
ALPNNegotiatedProtocol: "",
},
finalNetworkRequestStartTime: 0,
finalNetworkResponseStartTime: 0,
encodedBodySize: 0,
decodedBodySize: 0,
},
"https://nodejs.org",
"",
global,
"",
{},
200,
"",
);
resource; // $ExpectType PerformanceResourceTiming
Loading