bun-types 1.0.14 → 1.0.15
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/package.json +1 -1
- package/types.d.ts +647 -27
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Type definitions for bun 1.0.
|
|
1
|
+
// Type definitions for bun 1.0.15
|
|
2
2
|
// Project: https://github.com/oven-sh/bun
|
|
3
3
|
// Definitions by: Jarred Sumner <https://github.com/Jarred-Sumner>
|
|
4
4
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
@@ -10454,6 +10454,7 @@ declare module "bun:test" {
|
|
|
10454
10454
|
*/
|
|
10455
10455
|
export const test: Test;
|
|
10456
10456
|
export { test as it };
|
|
10457
|
+
|
|
10457
10458
|
/**
|
|
10458
10459
|
* Asserts that a value matches some criteria.
|
|
10459
10460
|
*
|
|
@@ -10463,16 +10464,73 @@ declare module "bun:test" {
|
|
|
10463
10464
|
* expect([1,2,3]).toContain(2);
|
|
10464
10465
|
* expect(null).toBeNull();
|
|
10465
10466
|
*
|
|
10466
|
-
* @param actual
|
|
10467
|
+
* @param actual The actual (received) value
|
|
10467
10468
|
*/
|
|
10468
|
-
export const expect:
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10469
|
+
export const expect: Expect;
|
|
10470
|
+
|
|
10471
|
+
type ExpectNot = Omit<AsymmetricMatchers, keyof AsymmetricMatchersBuiltin> &
|
|
10472
|
+
AsymmetricMatchersBuiltinNegated;
|
|
10473
|
+
|
|
10474
|
+
export interface Expect extends AsymmetricMatchers {
|
|
10475
|
+
// the `expect()` callable signature
|
|
10476
|
+
<T = unknown>(actual?: T): Matchers<T>;
|
|
10477
|
+
|
|
10478
|
+
/**
|
|
10479
|
+
* Access to negated asymmetric matchers.
|
|
10480
|
+
*
|
|
10481
|
+
* @example
|
|
10482
|
+
* expect("abc").toEqual(expect.stringContaining("abc")); // will pass
|
|
10483
|
+
* expect("abc").toEqual(expect.not.stringContaining("abc")); // will fail
|
|
10484
|
+
*/
|
|
10485
|
+
not: ExpectNot;
|
|
10486
|
+
|
|
10487
|
+
/**
|
|
10488
|
+
* Create an asymmetric matcher for a promise resolved value.
|
|
10489
|
+
*
|
|
10490
|
+
* @example
|
|
10491
|
+
* expect(Promise.resolve("value")).toEqual(expect.resolvesTo.stringContaining("value")); // will pass
|
|
10492
|
+
* expect(Promise.reject("value")).toEqual(expect.resolvesTo.stringContaining("value")); // will fail
|
|
10493
|
+
* expect("value").toEqual(expect.resolvesTo.stringContaining("value")); // will fail
|
|
10494
|
+
*/
|
|
10495
|
+
resolvesTo: AsymmetricMatchers;
|
|
10496
|
+
|
|
10497
|
+
/**
|
|
10498
|
+
* Create an asymmetric matcher for a promise rejected value.
|
|
10499
|
+
*
|
|
10500
|
+
* @example
|
|
10501
|
+
* expect(Promise.reject("error")).toEqual(expect.rejectsTo.stringContaining("error")); // will pass
|
|
10502
|
+
* expect(Promise.resolve("error")).toEqual(expect.rejectsTo.stringContaining("error")); // will fail
|
|
10503
|
+
* expect("error").toEqual(expect.rejectsTo.stringContaining("error")); // will fail
|
|
10504
|
+
*/
|
|
10505
|
+
rejectsTo: AsymmetricMatchers;
|
|
10506
|
+
|
|
10507
|
+
/**
|
|
10508
|
+
* Register new custom matchers.
|
|
10509
|
+
* @param matchers An object containing the matchers to register, where each key is the matcher name, and its value the implementation function.
|
|
10510
|
+
* The function must satisfy: `(actualValue, ...matcherInstantiationArguments) => { pass: true|false, message: () => string }`
|
|
10511
|
+
*
|
|
10512
|
+
* @example
|
|
10513
|
+
* expect.extend({
|
|
10514
|
+
* toBeWithinRange(actual, min, max) {
|
|
10515
|
+
* if (typeof actual !== 'number' || typeof min !== 'number' || typeof max !== 'number')
|
|
10516
|
+
* throw new Error('Invalid usage');
|
|
10517
|
+
* const pass = actual >= min && actual <= max;
|
|
10518
|
+
* return {
|
|
10519
|
+
* pass: pass,
|
|
10520
|
+
* message: () => `expected ${this.utils.printReceived(actual)} ` +
|
|
10521
|
+
* (pass ? `not to be`: `to be`) + ` within range ${this.utils.printExpected(`${min} .. ${max}`)}`,
|
|
10522
|
+
* };
|
|
10523
|
+
* },
|
|
10524
|
+
* });
|
|
10525
|
+
*
|
|
10526
|
+
* test('some test', () => {
|
|
10527
|
+
* expect(50).toBeWithinRange(0, 100); // will pass
|
|
10528
|
+
* expect(50).toBeWithinRange(100, 200); // will fail
|
|
10529
|
+
* expect(50).toBe(expect.toBeWithinRange(0, 100)); // will pass
|
|
10530
|
+
* expect(50).toBe(expect.not.toBeWithinRange(100, 200)); // will pass
|
|
10531
|
+
* });
|
|
10532
|
+
*/
|
|
10533
|
+
extend<M>(matchers: ExpectExtendMatchers<M>): void;
|
|
10476
10534
|
|
|
10477
10535
|
/**
|
|
10478
10536
|
* Throw an error if this function is called.
|
|
@@ -10497,41 +10555,227 @@ declare module "bun:test" {
|
|
|
10497
10555
|
* ```
|
|
10498
10556
|
*/
|
|
10499
10557
|
unreachable(msg?: string | Error): never;
|
|
10500
|
-
}
|
|
10558
|
+
}
|
|
10559
|
+
|
|
10501
10560
|
/**
|
|
10502
|
-
*
|
|
10561
|
+
* You can extend this interface with declaration merging, in order to add type support for custom matchers.
|
|
10562
|
+
* @template T Type of the actual value
|
|
10503
10563
|
*
|
|
10504
|
-
* @link https://jestjs.io/docs/expect#reference
|
|
10505
10564
|
* @example
|
|
10506
|
-
*
|
|
10507
|
-
*
|
|
10508
|
-
*
|
|
10565
|
+
* // my_modules.d.ts
|
|
10566
|
+
* interface MyCustomMatchers {
|
|
10567
|
+
* toBeWithinRange(floor: number, ceiling: number): any;
|
|
10568
|
+
* }
|
|
10569
|
+
* declare module "bun:test" {
|
|
10570
|
+
* interface Matchers<T> extends MyCustomMatchers {}
|
|
10571
|
+
* interface AsymmetricMatchers extends MyCustomMatchers {}
|
|
10572
|
+
* }
|
|
10573
|
+
* export {};
|
|
10509
10574
|
*
|
|
10510
|
-
* @
|
|
10575
|
+
* @example
|
|
10576
|
+
* // my_modules.d.ts (alternatively)
|
|
10577
|
+
* declare module "bun:test" {
|
|
10578
|
+
* interface Matchers<T> {
|
|
10579
|
+
* toBeWithinRange(floor: number, ceiling: number): any;
|
|
10580
|
+
* }
|
|
10581
|
+
* interface AsymmetricMatchers {
|
|
10582
|
+
* toBeWithinRange(floor: number, ceiling: number): any;
|
|
10583
|
+
* }
|
|
10584
|
+
* }
|
|
10585
|
+
* export {};
|
|
10511
10586
|
*/
|
|
10512
|
-
export
|
|
10587
|
+
export interface Matchers<T = unknown> extends MatchersBuiltin<T> {}
|
|
10588
|
+
|
|
10589
|
+
/**
|
|
10590
|
+
* You can extend this interface with declaration merging, in order to add type support for custom asymmetric matchers.
|
|
10591
|
+
* @example
|
|
10592
|
+
* // my_modules.d.ts
|
|
10593
|
+
* interface MyCustomMatchers {
|
|
10594
|
+
* toBeWithinRange(floor: number, ceiling: number): any;
|
|
10595
|
+
* }
|
|
10596
|
+
* declare module "bun:test" {
|
|
10597
|
+
* interface Matchers<T> extends MyCustomMatchers {}
|
|
10598
|
+
* interface AsymmetricMatchers extends MyCustomMatchers {}
|
|
10599
|
+
* }
|
|
10600
|
+
* export {};
|
|
10601
|
+
*
|
|
10602
|
+
* @example
|
|
10603
|
+
* // my_modules.d.ts (alternatively)
|
|
10604
|
+
* declare module "bun:test" {
|
|
10605
|
+
* interface Matchers<T> {
|
|
10606
|
+
* toBeWithinRange(floor: number, ceiling: number): any;
|
|
10607
|
+
* }
|
|
10608
|
+
* interface AsymmetricMatchers {
|
|
10609
|
+
* toBeWithinRange(floor: number, ceiling: number): any;
|
|
10610
|
+
* }
|
|
10611
|
+
* }
|
|
10612
|
+
* export {};
|
|
10613
|
+
*/
|
|
10614
|
+
export interface AsymmetricMatchers extends AsymmetricMatchersBuiltin {}
|
|
10615
|
+
|
|
10616
|
+
export interface AsymmetricMatchersBuiltin {
|
|
10617
|
+
/**
|
|
10618
|
+
* Matches anything that was created with the given constructor.
|
|
10619
|
+
* You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value.
|
|
10620
|
+
*
|
|
10621
|
+
* @example
|
|
10622
|
+
*
|
|
10623
|
+
* function randocall(fn) {
|
|
10624
|
+
* return fn(Math.floor(Math.random() * 6 + 1));
|
|
10625
|
+
* }
|
|
10626
|
+
*
|
|
10627
|
+
* test('randocall calls its callback with a number', () => {
|
|
10628
|
+
* const mock = jest.fn();
|
|
10629
|
+
* randocall(mock);
|
|
10630
|
+
* expect(mock).toBeCalledWith(expect.any(Number));
|
|
10631
|
+
* });
|
|
10632
|
+
*/
|
|
10633
|
+
any(
|
|
10634
|
+
constructor: ((..._: any[]) => any) | { new (..._: any[]): any },
|
|
10635
|
+
): AsymmetricMatcher;
|
|
10636
|
+
/**
|
|
10637
|
+
* Matches anything but null or undefined. You can use it inside `toEqual` or `toBeCalledWith` instead
|
|
10638
|
+
* of a literal value. For example, if you want to check that a mock function is called with a
|
|
10639
|
+
* non-null argument:
|
|
10640
|
+
*
|
|
10641
|
+
* @example
|
|
10642
|
+
*
|
|
10643
|
+
* test('map calls its argument with a non-null argument', () => {
|
|
10644
|
+
* const mock = jest.fn();
|
|
10645
|
+
* [1].map(x => mock(x));
|
|
10646
|
+
* expect(mock).toBeCalledWith(expect.anything());
|
|
10647
|
+
* });
|
|
10648
|
+
*/
|
|
10649
|
+
anything(): AsymmetricMatcher;
|
|
10650
|
+
/**
|
|
10651
|
+
* Matches any array made up entirely of elements in the provided array.
|
|
10652
|
+
* You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value.
|
|
10653
|
+
*
|
|
10654
|
+
* Optionally, you can provide a type for the elements via a generic.
|
|
10655
|
+
*/
|
|
10656
|
+
arrayContaining<E = any>(arr: readonly E[]): AsymmetricMatcher;
|
|
10657
|
+
/**
|
|
10658
|
+
* Matches any object that recursively matches the provided keys.
|
|
10659
|
+
* This is often handy in conjunction with other asymmetric matchers.
|
|
10660
|
+
*
|
|
10661
|
+
* Optionally, you can provide a type for the object via a generic.
|
|
10662
|
+
* This ensures that the object contains the desired structure.
|
|
10663
|
+
*/
|
|
10664
|
+
objectContaining(obj: object): AsymmetricMatcher;
|
|
10665
|
+
/**
|
|
10666
|
+
* Matches any received string that contains the exact expected string
|
|
10667
|
+
*/
|
|
10668
|
+
stringContaining(str: string | String): AsymmetricMatcher;
|
|
10669
|
+
/**
|
|
10670
|
+
* Matches any string that contains the exact provided string
|
|
10671
|
+
*/
|
|
10672
|
+
stringMatching(regex: string | String | RegExp): AsymmetricMatcher;
|
|
10673
|
+
/**
|
|
10674
|
+
* Useful when comparing floating point numbers in object properties or array item.
|
|
10675
|
+
* If you need to compare a number, use `.toBeCloseTo` instead.
|
|
10676
|
+
*
|
|
10677
|
+
* The optional `numDigits` argument limits the number of digits to check after the decimal point.
|
|
10678
|
+
* For the default value 2, the test criterion is `Math.abs(expected - received) < 0.005` (that is, `10 ** -2 / 2`).
|
|
10679
|
+
*/
|
|
10680
|
+
closeTo(num: number, numDigits?: number): AsymmetricMatcher;
|
|
10681
|
+
}
|
|
10682
|
+
|
|
10683
|
+
interface AsymmetricMatchersBuiltinNegated {
|
|
10684
|
+
/**
|
|
10685
|
+
* Create an asymmetric matcher that will fail on a promise resolved value that matches the chained matcher.
|
|
10686
|
+
*
|
|
10687
|
+
* @example
|
|
10688
|
+
* expect(Promise.resolve("value")).toEqual(expect.not.resolvesTo.stringContaining("value")); // will fail
|
|
10689
|
+
* expect(Promise.reject("value")).toEqual(expect.not.resolvesTo.stringContaining("value")); // will pass
|
|
10690
|
+
* expect("value").toEqual(expect.not.resolvesTo.stringContaining("value")); // will pass
|
|
10691
|
+
*/
|
|
10692
|
+
resolvesTo: ExpectNot;
|
|
10693
|
+
|
|
10694
|
+
/**
|
|
10695
|
+
* Create an asymmetric matcher that will fail on a promise rejected value that matches the chained matcher.
|
|
10696
|
+
*
|
|
10697
|
+
* @example
|
|
10698
|
+
* expect(Promise.reject("value")).toEqual(expect.not.rejectsTo.stringContaining("value")); // will fail
|
|
10699
|
+
* expect(Promise.resolve("value")).toEqual(expect.not.rejectsTo.stringContaining("value")); // will pass
|
|
10700
|
+
* expect("value").toEqual(expect.not.rejectsTo.stringContaining("value")); // will pass
|
|
10701
|
+
*/
|
|
10702
|
+
rejectsTo: ExpectNot;
|
|
10703
|
+
|
|
10704
|
+
/**
|
|
10705
|
+
* `expect.not.arrayContaining(array)` matches a received array which
|
|
10706
|
+
* does not contain all of the elements in the expected array. That is,
|
|
10707
|
+
* the expected array is not a subset of the received array. It is the
|
|
10708
|
+
* inverse of `expect.arrayContaining`.
|
|
10709
|
+
*
|
|
10710
|
+
* Optionally, you can provide a type for the elements via a generic.
|
|
10711
|
+
*/
|
|
10712
|
+
arrayContaining<E = any>(arr: readonly E[]): AsymmetricMatcher;
|
|
10713
|
+
|
|
10714
|
+
/**
|
|
10715
|
+
* `expect.not.objectContaining(object)` matches any received object
|
|
10716
|
+
* that does not recursively match the expected properties. That is, the
|
|
10717
|
+
* expected object is not a subset of the received object. Therefore,
|
|
10718
|
+
* it matches a received object which contains properties that are not
|
|
10719
|
+
* in the expected object. It is the inverse of `expect.objectContaining`.
|
|
10720
|
+
*
|
|
10721
|
+
* Optionally, you can provide a type for the object via a generic.
|
|
10722
|
+
* This ensures that the object contains the desired structure.
|
|
10723
|
+
*/
|
|
10724
|
+
objectContaining(obj: object): AsymmetricMatcher;
|
|
10725
|
+
|
|
10726
|
+
/**
|
|
10727
|
+
* `expect.not.stringContaining(string)` matches the received string
|
|
10728
|
+
* that does not contain the exact expected string. It is the inverse of
|
|
10729
|
+
* `expect.stringContaining`.
|
|
10730
|
+
*/
|
|
10731
|
+
stringContaining(str: string | String): AsymmetricMatcher;
|
|
10732
|
+
|
|
10733
|
+
/**
|
|
10734
|
+
* `expect.not.stringMatching(string | regexp)` matches the received
|
|
10735
|
+
* string that does not match the expected regexp. It is the inverse of
|
|
10736
|
+
* `expect.stringMatching`.
|
|
10737
|
+
*/
|
|
10738
|
+
stringMatching(str: string | String | RegExp): AsymmetricMatcher;
|
|
10739
|
+
|
|
10740
|
+
/**
|
|
10741
|
+
* `expect.not.closeTo` matches a number not close to the provided value.
|
|
10742
|
+
* Useful when comparing floating point numbers in object properties or array item.
|
|
10743
|
+
* It is the inverse of `expect.closeTo`.
|
|
10744
|
+
*/
|
|
10745
|
+
closeTo(num: number, numDigits?: number): AsymmetricMatcher;
|
|
10746
|
+
}
|
|
10747
|
+
|
|
10748
|
+
export interface MatchersBuiltin<T = unknown> {
|
|
10513
10749
|
/**
|
|
10514
10750
|
* Negates the result of a subsequent assertion.
|
|
10751
|
+
* If you know how to test something, `.not` lets you test its opposite.
|
|
10515
10752
|
*
|
|
10516
10753
|
* @example
|
|
10517
10754
|
* expect(1).not.toBe(0);
|
|
10518
10755
|
* expect(null).not.toBeNull();
|
|
10756
|
+
*
|
|
10757
|
+
* @example
|
|
10758
|
+
* expect(42).toEqual(42); // will pass
|
|
10759
|
+
* expect(42).not.toEqual(42); // will fail
|
|
10519
10760
|
*/
|
|
10520
|
-
not:
|
|
10761
|
+
not: Matchers<unknown>;
|
|
10762
|
+
|
|
10521
10763
|
/**
|
|
10522
10764
|
* Expects the value to be a promise that resolves.
|
|
10523
10765
|
*
|
|
10524
10766
|
* @example
|
|
10525
10767
|
* expect(Promise.resolve(1)).resolves.toBe(1);
|
|
10526
10768
|
*/
|
|
10527
|
-
resolves:
|
|
10769
|
+
resolves: Matchers<Awaited<T>>;
|
|
10770
|
+
|
|
10528
10771
|
/**
|
|
10529
10772
|
* Expects the value to be a promise that rejects.
|
|
10530
10773
|
*
|
|
10531
10774
|
* @example
|
|
10532
10775
|
* expect(Promise.reject("error")).rejects.toBe("error");
|
|
10533
10776
|
*/
|
|
10534
|
-
rejects:
|
|
10777
|
+
rejects: Matchers<unknown>;
|
|
10778
|
+
|
|
10535
10779
|
/**
|
|
10536
10780
|
* Assertion which passes.
|
|
10537
10781
|
*
|
|
@@ -10671,16 +10915,21 @@ declare module "bun:test" {
|
|
|
10671
10915
|
toHaveLength(length: number): void;
|
|
10672
10916
|
/**
|
|
10673
10917
|
* Asserts that a value has a property with the
|
|
10674
|
-
* expected name, and value
|
|
10918
|
+
* expected name, and value if provided.
|
|
10675
10919
|
*
|
|
10676
10920
|
* @example
|
|
10677
10921
|
* expect(new Set()).toHaveProperty("size");
|
|
10678
10922
|
* expect(new Uint8Array()).toHaveProperty("byteLength", 0);
|
|
10923
|
+
* expect({ kitchen: { area: 20 }}).toHaveProperty("kitchen.area", 20);
|
|
10924
|
+
* expect({ kitchen: { area: 20 }}).toHaveProperty(["kitchen", "area"], 20);
|
|
10679
10925
|
*
|
|
10680
|
-
* @param
|
|
10926
|
+
* @param keyPath the expected property name or path, or an index
|
|
10681
10927
|
* @param value the expected property value, if provided
|
|
10682
10928
|
*/
|
|
10683
|
-
toHaveProperty(
|
|
10929
|
+
toHaveProperty(
|
|
10930
|
+
keyPath: string | number | (string | number)[],
|
|
10931
|
+
value?: unknown,
|
|
10932
|
+
): void;
|
|
10684
10933
|
/**
|
|
10685
10934
|
* Asserts that a value is "truthy".
|
|
10686
10935
|
*
|
|
@@ -10841,7 +11090,7 @@ declare module "bun:test" {
|
|
|
10841
11090
|
* @param propertyMatchers Object containing properties to match against the value.
|
|
10842
11091
|
* @param hint Hint used to identify the snapshot in the snapshot file.
|
|
10843
11092
|
*/
|
|
10844
|
-
toMatchSnapshot(propertyMatchers?:
|
|
11093
|
+
toMatchSnapshot(propertyMatchers?: object, hint?: string): void;
|
|
10845
11094
|
/**
|
|
10846
11095
|
* Asserts that an object matches a subset of properties.
|
|
10847
11096
|
*
|
|
@@ -10851,7 +11100,7 @@ declare module "bun:test" {
|
|
|
10851
11100
|
*
|
|
10852
11101
|
* @param subset Subset of properties to match with.
|
|
10853
11102
|
*/
|
|
10854
|
-
toMatchObject(subset:
|
|
11103
|
+
toMatchObject(subset: object): void;
|
|
10855
11104
|
/**
|
|
10856
11105
|
* Asserts that a value is empty.
|
|
10857
11106
|
*
|
|
@@ -11095,8 +11344,119 @@ declare module "bun:test" {
|
|
|
11095
11344
|
/**
|
|
11096
11345
|
* Ensure that a mock function is called with specific arguments.
|
|
11097
11346
|
*/
|
|
11098
|
-
|
|
11347
|
+
toHaveBeenCalledWith(...expected: Array<unknown>): void;
|
|
11348
|
+
/**
|
|
11349
|
+
* Ensure that a mock function is called with specific arguments for the last call.
|
|
11350
|
+
*/
|
|
11351
|
+
toHaveBeenLastCalledWith(...expected: Array<unknown>): void;
|
|
11352
|
+
/**
|
|
11353
|
+
* Ensure that a mock function is called with specific arguments for the nth call.
|
|
11354
|
+
*/
|
|
11355
|
+
toHaveBeenNthCalledWith(n: number, ...expected: Array<unknown>): void;
|
|
11356
|
+
}
|
|
11357
|
+
|
|
11358
|
+
/**
|
|
11359
|
+
* Object representing an asymmetric matcher obtained by an static call to expect like `expect.anything()`, `expect.stringContaining("...")`, etc.
|
|
11360
|
+
*/
|
|
11361
|
+
// Defined as an alias of `any` so that it does not trigger any type mismatch
|
|
11362
|
+
export type AsymmetricMatcher = any;
|
|
11363
|
+
|
|
11364
|
+
export interface MatcherResult {
|
|
11365
|
+
pass: boolean;
|
|
11366
|
+
message?: string | (() => string);
|
|
11367
|
+
}
|
|
11368
|
+
|
|
11369
|
+
export type CustomMatcher<E, P extends any[]> = (
|
|
11370
|
+
this: MatcherContext,
|
|
11371
|
+
expected: E,
|
|
11372
|
+
...matcherArguments: P
|
|
11373
|
+
) => MatcherResult | Promise<MatcherResult>;
|
|
11374
|
+
|
|
11375
|
+
/** All non-builtin matchers and asymmetric matchers that have been type-registered through declaration merging */
|
|
11376
|
+
export type CustomMatchersDetected = Omit<
|
|
11377
|
+
Matchers<unknown>,
|
|
11378
|
+
keyof MatchersBuiltin<unknown>
|
|
11379
|
+
> &
|
|
11380
|
+
Omit<AsymmetricMatchers, keyof AsymmetricMatchersBuiltin>;
|
|
11381
|
+
|
|
11382
|
+
/**
|
|
11383
|
+
* If the types has been defined through declaration merging, enforce it.
|
|
11384
|
+
* Otherwise enforce the generic custom matcher signature.
|
|
11385
|
+
*/
|
|
11386
|
+
export type ExpectExtendMatchers<M> = {
|
|
11387
|
+
[k in keyof M]: k extends keyof CustomMatchersDetected
|
|
11388
|
+
? CustomMatcher<unknown, Parameters<CustomMatchersDetected[k]>>
|
|
11389
|
+
: CustomMatcher<unknown, any[]>;
|
|
11099
11390
|
};
|
|
11391
|
+
|
|
11392
|
+
/** Custom equality tester */
|
|
11393
|
+
export type Tester = (
|
|
11394
|
+
this: TesterContext,
|
|
11395
|
+
a: any,
|
|
11396
|
+
b: any,
|
|
11397
|
+
customTesters: Array<Tester>,
|
|
11398
|
+
) => boolean | undefined;
|
|
11399
|
+
|
|
11400
|
+
export type EqualsFunction = (
|
|
11401
|
+
a: unknown,
|
|
11402
|
+
b: unknown,
|
|
11403
|
+
//customTesters?: Array<Tester>,
|
|
11404
|
+
//strictCheck?: boolean,
|
|
11405
|
+
) => boolean;
|
|
11406
|
+
|
|
11407
|
+
export interface TesterContext {
|
|
11408
|
+
equals: EqualsFunction;
|
|
11409
|
+
}
|
|
11410
|
+
|
|
11411
|
+
interface MatcherState {
|
|
11412
|
+
//assertionCalls: number;
|
|
11413
|
+
//currentConcurrentTestName?: () => string | undefined;
|
|
11414
|
+
//currentTestName?: string;
|
|
11415
|
+
//error?: Error;
|
|
11416
|
+
//expand: boolean;
|
|
11417
|
+
//expectedAssertionsNumber: number | null;
|
|
11418
|
+
//expectedAssertionsNumberError?: Error;
|
|
11419
|
+
//isExpectingAssertions: boolean;
|
|
11420
|
+
//isExpectingAssertionsError?: Error;
|
|
11421
|
+
isNot: boolean;
|
|
11422
|
+
//numPassingAsserts: number;
|
|
11423
|
+
promise: string;
|
|
11424
|
+
//suppressedErrors: Array<Error>;
|
|
11425
|
+
//testPath?: string;
|
|
11426
|
+
}
|
|
11427
|
+
|
|
11428
|
+
type MatcherHintColor = (arg: string) => string; // subset of Chalk type
|
|
11429
|
+
|
|
11430
|
+
interface MatcherUtils {
|
|
11431
|
+
//customTesters: Array<Tester>;
|
|
11432
|
+
//dontThrow(): void; // (internally used by jest snapshot)
|
|
11433
|
+
equals: EqualsFunction;
|
|
11434
|
+
utils: Readonly<{
|
|
11435
|
+
stringify(value: unknown): string;
|
|
11436
|
+
printReceived(value: unknown): string;
|
|
11437
|
+
printExpected(value: unknown): string;
|
|
11438
|
+
matcherHint(
|
|
11439
|
+
matcherName: string,
|
|
11440
|
+
received?: unknown,
|
|
11441
|
+
expected?: unknown,
|
|
11442
|
+
options?: {
|
|
11443
|
+
isNot?: boolean;
|
|
11444
|
+
promise?: string;
|
|
11445
|
+
isDirectExpectCall?: boolean; // (internal)
|
|
11446
|
+
comment?: string;
|
|
11447
|
+
expectedColor?: MatcherHintColor;
|
|
11448
|
+
receivedColor?: MatcherHintColor;
|
|
11449
|
+
secondArgument?: string;
|
|
11450
|
+
secondArgumentColor?: MatcherHintColor;
|
|
11451
|
+
},
|
|
11452
|
+
): string;
|
|
11453
|
+
//iterableEquality: Tester;
|
|
11454
|
+
//subsetEquality: Tester;
|
|
11455
|
+
// ...
|
|
11456
|
+
}>;
|
|
11457
|
+
}
|
|
11458
|
+
|
|
11459
|
+
type MatcherContext = MatcherUtils & MatcherState;
|
|
11100
11460
|
}
|
|
11101
11461
|
|
|
11102
11462
|
declare module "test" {
|
|
@@ -25614,6 +25974,258 @@ declare module "util" {
|
|
|
25614
25974
|
*/
|
|
25615
25975
|
const custom: unique symbol;
|
|
25616
25976
|
}
|
|
25977
|
+
|
|
25978
|
+
// //// parseArgs
|
|
25979
|
+
// /**
|
|
25980
|
+
// * Provides a higher level API for command-line argument parsing than interacting
|
|
25981
|
+
// * with `process.argv` directly. Takes a specification for the expected arguments
|
|
25982
|
+
// * and returns a structured object with the parsed options and positionals.
|
|
25983
|
+
// *
|
|
25984
|
+
// * ```js
|
|
25985
|
+
// * import { parseArgs } from 'node:util';
|
|
25986
|
+
// * const args = ['-f', '--bar', 'b'];
|
|
25987
|
+
// * const options = {
|
|
25988
|
+
// * foo: {
|
|
25989
|
+
// * type: 'boolean',
|
|
25990
|
+
// * short: 'f',
|
|
25991
|
+
// * },
|
|
25992
|
+
// * bar: {
|
|
25993
|
+
// * type: 'string',
|
|
25994
|
+
// * },
|
|
25995
|
+
// * };
|
|
25996
|
+
// * const {
|
|
25997
|
+
// * values,
|
|
25998
|
+
// * positionals,
|
|
25999
|
+
// * } = parseArgs({ args, options });
|
|
26000
|
+
// * console.log(values, positionals);
|
|
26001
|
+
// * // Prints: [Object: null prototype] { foo: true, bar: 'b' } []
|
|
26002
|
+
// * ```
|
|
26003
|
+
// * @since v18.3.0, v16.17.0
|
|
26004
|
+
// * @param config Used to provide arguments for parsing and to configure the parser.
|
|
26005
|
+
// * @return The parsed command line arguments:
|
|
26006
|
+
// */
|
|
26007
|
+
// export function parseArgs<T extends ParseArgsConfig>(
|
|
26008
|
+
// config?: T,
|
|
26009
|
+
// ): ParsedResults<T>;
|
|
26010
|
+
interface ParseArgsOptionConfig {
|
|
26011
|
+
/**
|
|
26012
|
+
* Type of argument.
|
|
26013
|
+
*/
|
|
26014
|
+
type: "string" | "boolean";
|
|
26015
|
+
/**
|
|
26016
|
+
* Whether this option can be provided multiple times.
|
|
26017
|
+
* If `true`, all values will be collected in an array.
|
|
26018
|
+
* If `false`, values for the option are last-wins.
|
|
26019
|
+
* @default false.
|
|
26020
|
+
*/
|
|
26021
|
+
multiple?: boolean | undefined;
|
|
26022
|
+
/**
|
|
26023
|
+
* A single character alias for the option.
|
|
26024
|
+
*/
|
|
26025
|
+
short?: string | undefined;
|
|
26026
|
+
/**
|
|
26027
|
+
* The default option value when it is not set by args.
|
|
26028
|
+
* It must be of the same type as the the `type` property.
|
|
26029
|
+
* When `multiple` is `true`, it must be an array.
|
|
26030
|
+
* @since v18.11.0
|
|
26031
|
+
*/
|
|
26032
|
+
default?: string | boolean | string[] | boolean[] | undefined;
|
|
26033
|
+
}
|
|
26034
|
+
interface ParseArgsOptionsConfig {
|
|
26035
|
+
[longOption: string]: ParseArgsOptionConfig;
|
|
26036
|
+
}
|
|
26037
|
+
export interface ParseArgsConfig {
|
|
26038
|
+
/**
|
|
26039
|
+
* Array of argument strings.
|
|
26040
|
+
*/
|
|
26041
|
+
args?: string[] | undefined;
|
|
26042
|
+
/**
|
|
26043
|
+
* Used to describe arguments known to the parser.
|
|
26044
|
+
*/
|
|
26045
|
+
options?: ParseArgsOptionsConfig | undefined;
|
|
26046
|
+
/**
|
|
26047
|
+
* Should an error be thrown when unknown arguments are encountered,
|
|
26048
|
+
* or when arguments are passed that do not match the `type` configured in `options`.
|
|
26049
|
+
* @default true
|
|
26050
|
+
*/
|
|
26051
|
+
strict?: boolean | undefined;
|
|
26052
|
+
/**
|
|
26053
|
+
* Whether this command accepts positional arguments.
|
|
26054
|
+
*/
|
|
26055
|
+
allowPositionals?: boolean | undefined;
|
|
26056
|
+
/**
|
|
26057
|
+
* Return the parsed tokens. This is useful for extending the built-in behavior,
|
|
26058
|
+
* from adding additional checks through to reprocessing the tokens in different ways.
|
|
26059
|
+
* @default false
|
|
26060
|
+
*/
|
|
26061
|
+
tokens?: boolean | undefined;
|
|
26062
|
+
}
|
|
26063
|
+
/*
|
|
26064
|
+
IfDefaultsTrue and IfDefaultsFalse are helpers to handle default values for missing boolean properties.
|
|
26065
|
+
TypeScript does not have exact types for objects: https://github.com/microsoft/TypeScript/issues/12936
|
|
26066
|
+
This means it is impossible to distinguish between "field X is definitely not present" and "field X may or may not be present".
|
|
26067
|
+
But we expect users to generally provide their config inline or `as const`, which means TS will always know whether a given field is present.
|
|
26068
|
+
So this helper treats "not definitely present" (i.e., not `extends boolean`) as being "definitely not present", i.e. it should have its default value.
|
|
26069
|
+
This is technically incorrect but is a much nicer UX for the common case.
|
|
26070
|
+
The IfDefaultsTrue version is for things which default to true; the IfDefaultsFalse version is for things which default to false.
|
|
26071
|
+
*/
|
|
26072
|
+
type IfDefaultsTrue<T, IfTrue, IfFalse> = T extends true
|
|
26073
|
+
? IfTrue
|
|
26074
|
+
: T extends false
|
|
26075
|
+
? IfFalse
|
|
26076
|
+
: IfTrue;
|
|
26077
|
+
|
|
26078
|
+
// we put the `extends false` condition first here because `undefined` compares like `any` when `strictNullChecks: false`
|
|
26079
|
+
type IfDefaultsFalse<T, IfTrue, IfFalse> = T extends false
|
|
26080
|
+
? IfFalse
|
|
26081
|
+
: T extends true
|
|
26082
|
+
? IfTrue
|
|
26083
|
+
: IfFalse;
|
|
26084
|
+
|
|
26085
|
+
type ExtractOptionValue<
|
|
26086
|
+
T extends ParseArgsConfig,
|
|
26087
|
+
O extends ParseArgsOptionConfig,
|
|
26088
|
+
> = IfDefaultsTrue<
|
|
26089
|
+
T["strict"],
|
|
26090
|
+
O["type"] extends "string"
|
|
26091
|
+
? string
|
|
26092
|
+
: O["type"] extends "boolean"
|
|
26093
|
+
? boolean
|
|
26094
|
+
: string | boolean,
|
|
26095
|
+
string | boolean
|
|
26096
|
+
>;
|
|
26097
|
+
|
|
26098
|
+
type ParsedValues<T extends ParseArgsConfig> = IfDefaultsTrue<
|
|
26099
|
+
T["strict"],
|
|
26100
|
+
unknown,
|
|
26101
|
+
{ [longOption: string]: undefined | string | boolean }
|
|
26102
|
+
> &
|
|
26103
|
+
(T["options"] extends ParseArgsOptionsConfig
|
|
26104
|
+
? {
|
|
26105
|
+
-readonly [LongOption in keyof T["options"]]: IfDefaultsFalse<
|
|
26106
|
+
T["options"][LongOption]["multiple"],
|
|
26107
|
+
undefined | Array<ExtractOptionValue<T, T["options"][LongOption]>>,
|
|
26108
|
+
undefined | ExtractOptionValue<T, T["options"][LongOption]>
|
|
26109
|
+
>;
|
|
26110
|
+
}
|
|
26111
|
+
: {});
|
|
26112
|
+
|
|
26113
|
+
type ParsedPositionals<T extends ParseArgsConfig> = IfDefaultsTrue<
|
|
26114
|
+
T["strict"],
|
|
26115
|
+
IfDefaultsFalse<T["allowPositionals"], string[], []>,
|
|
26116
|
+
IfDefaultsTrue<T["allowPositionals"], string[], []>
|
|
26117
|
+
>;
|
|
26118
|
+
|
|
26119
|
+
type PreciseTokenForOptions<
|
|
26120
|
+
K extends string,
|
|
26121
|
+
O extends ParseArgsOptionConfig,
|
|
26122
|
+
> = O["type"] extends "string"
|
|
26123
|
+
? {
|
|
26124
|
+
kind: "option";
|
|
26125
|
+
index: number;
|
|
26126
|
+
name: K;
|
|
26127
|
+
rawName: string;
|
|
26128
|
+
value: string;
|
|
26129
|
+
inlineValue: boolean;
|
|
26130
|
+
}
|
|
26131
|
+
: O["type"] extends "boolean"
|
|
26132
|
+
? {
|
|
26133
|
+
kind: "option";
|
|
26134
|
+
index: number;
|
|
26135
|
+
name: K;
|
|
26136
|
+
rawName: string;
|
|
26137
|
+
value: undefined;
|
|
26138
|
+
inlineValue: undefined;
|
|
26139
|
+
}
|
|
26140
|
+
: OptionToken & { name: K };
|
|
26141
|
+
|
|
26142
|
+
type TokenForOptions<
|
|
26143
|
+
T extends ParseArgsConfig,
|
|
26144
|
+
K extends keyof T["options"] = keyof T["options"],
|
|
26145
|
+
> = K extends unknown
|
|
26146
|
+
? T["options"] extends ParseArgsOptionsConfig
|
|
26147
|
+
? PreciseTokenForOptions<K & string, T["options"][K]>
|
|
26148
|
+
: OptionToken
|
|
26149
|
+
: never;
|
|
26150
|
+
|
|
26151
|
+
type ParsedOptionToken<T extends ParseArgsConfig> = IfDefaultsTrue<
|
|
26152
|
+
T["strict"],
|
|
26153
|
+
TokenForOptions<T>,
|
|
26154
|
+
OptionToken
|
|
26155
|
+
>;
|
|
26156
|
+
|
|
26157
|
+
type ParsedPositionalToken<T extends ParseArgsConfig> = IfDefaultsTrue<
|
|
26158
|
+
T["strict"],
|
|
26159
|
+
IfDefaultsFalse<
|
|
26160
|
+
T["allowPositionals"],
|
|
26161
|
+
{ kind: "positional"; index: number; value: string },
|
|
26162
|
+
never
|
|
26163
|
+
>,
|
|
26164
|
+
IfDefaultsTrue<
|
|
26165
|
+
T["allowPositionals"],
|
|
26166
|
+
{ kind: "positional"; index: number; value: string },
|
|
26167
|
+
never
|
|
26168
|
+
>
|
|
26169
|
+
>;
|
|
26170
|
+
|
|
26171
|
+
type ParsedTokens<T extends ParseArgsConfig> = Array<
|
|
26172
|
+
| ParsedOptionToken<T>
|
|
26173
|
+
| ParsedPositionalToken<T>
|
|
26174
|
+
| { kind: "option-terminator"; index: number }
|
|
26175
|
+
>;
|
|
26176
|
+
|
|
26177
|
+
type PreciseParsedResults<T extends ParseArgsConfig> = IfDefaultsFalse<
|
|
26178
|
+
T["tokens"],
|
|
26179
|
+
{
|
|
26180
|
+
values: ParsedValues<T>;
|
|
26181
|
+
positionals: ParsedPositionals<T>;
|
|
26182
|
+
tokens: ParsedTokens<T>;
|
|
26183
|
+
},
|
|
26184
|
+
{
|
|
26185
|
+
values: ParsedValues<T>;
|
|
26186
|
+
positionals: ParsedPositionals<T>;
|
|
26187
|
+
}
|
|
26188
|
+
>;
|
|
26189
|
+
|
|
26190
|
+
type OptionToken =
|
|
26191
|
+
| {
|
|
26192
|
+
kind: "option";
|
|
26193
|
+
index: number;
|
|
26194
|
+
name: string;
|
|
26195
|
+
rawName: string;
|
|
26196
|
+
value: string;
|
|
26197
|
+
inlineValue: boolean;
|
|
26198
|
+
}
|
|
26199
|
+
| {
|
|
26200
|
+
kind: "option";
|
|
26201
|
+
index: number;
|
|
26202
|
+
name: string;
|
|
26203
|
+
rawName: string;
|
|
26204
|
+
value: undefined;
|
|
26205
|
+
inlineValue: undefined;
|
|
26206
|
+
};
|
|
26207
|
+
|
|
26208
|
+
type Token =
|
|
26209
|
+
| OptionToken
|
|
26210
|
+
| { kind: "positional"; index: number; value: string }
|
|
26211
|
+
| { kind: "option-terminator"; index: number };
|
|
26212
|
+
|
|
26213
|
+
// If ParseArgsConfig extends T, then the user passed config constructed elsewhere.
|
|
26214
|
+
// So we can't rely on the `"not definitely present" implies "definitely not present"` assumption mentioned above.
|
|
26215
|
+
type ParsedResults<T extends ParseArgsConfig> = ParseArgsConfig extends T
|
|
26216
|
+
? {
|
|
26217
|
+
values: {
|
|
26218
|
+
[longOption: string]:
|
|
26219
|
+
| undefined
|
|
26220
|
+
| string
|
|
26221
|
+
| boolean
|
|
26222
|
+
| Array<string | boolean>;
|
|
26223
|
+
};
|
|
26224
|
+
positionals: string[];
|
|
26225
|
+
tokens?: Token[];
|
|
26226
|
+
}
|
|
26227
|
+
: PreciseParsedResults<T>;
|
|
26228
|
+
|
|
25617
26229
|
export interface EncodeIntoResult {
|
|
25618
26230
|
/**
|
|
25619
26231
|
* The read Unicode code units of input.
|
|
@@ -33431,6 +34043,14 @@ interface ImportMeta {
|
|
|
33431
34043
|
* Filename of the source file
|
|
33432
34044
|
*/
|
|
33433
34045
|
readonly file: string;
|
|
34046
|
+
/**
|
|
34047
|
+
* The environment variables of the process
|
|
34048
|
+
*
|
|
34049
|
+
* ```ts
|
|
34050
|
+
* import.meta.env === process.env
|
|
34051
|
+
* ```
|
|
34052
|
+
*/
|
|
34053
|
+
readonly env: import("bun").Env;
|
|
33434
34054
|
/**
|
|
33435
34055
|
* Resolve a module ID the same as if you imported it
|
|
33436
34056
|
*
|