Add Robot_JoyIt driver

This commit is contained in:
2026-01-17 16:50:07 +01:00
parent e9e50acf5f
commit 0cfb4d5a95
15848 changed files with 570836 additions and 268976 deletions

View File

@@ -1,375 +0,0 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.closeTo =
exports.arrayNotContaining =
exports.arrayContaining =
exports.anything =
exports.any =
exports.AsymmetricMatcher =
void 0;
exports.hasProperty = hasProperty;
exports.stringNotMatching =
exports.stringNotContaining =
exports.stringMatching =
exports.stringContaining =
exports.objectNotContaining =
exports.objectContaining =
exports.notCloseTo =
void 0;
var _expectUtils = require('@jest/expect-utils');
var matcherUtils = _interopRequireWildcard(require('jest-matcher-utils'));
var _jestUtil = require('jest-util');
var _jestMatchersObject = require('./jestMatchersObject');
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== 'function') return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function (nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
return {default: obj};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor =
Object.defineProperty && Object.getOwnPropertyDescriptor;
for (var key in obj) {
if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor
? Object.getOwnPropertyDescriptor(obj, key)
: null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const functionToString = Function.prototype.toString;
function fnNameFor(func) {
if (func.name) {
return func.name;
}
const matches = functionToString
.call(func)
.match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
return matches ? matches[1] : '<anonymous>';
}
const utils = Object.freeze({
...matcherUtils,
iterableEquality: _expectUtils.iterableEquality,
subsetEquality: _expectUtils.subsetEquality
});
function getPrototype(obj) {
if (Object.getPrototypeOf) {
return Object.getPrototypeOf(obj);
}
if (obj.constructor.prototype == obj) {
return null;
}
return obj.constructor.prototype;
}
function hasProperty(obj, property) {
if (!obj) {
return false;
}
if (Object.prototype.hasOwnProperty.call(obj, property)) {
return true;
}
return hasProperty(getPrototype(obj), property);
}
class AsymmetricMatcher {
$$typeof = Symbol.for('jest.asymmetricMatcher');
constructor(sample, inverse = false) {
this.sample = sample;
this.inverse = inverse;
}
getMatcherContext() {
return {
customTesters: (0, _jestMatchersObject.getCustomEqualityTesters)(),
// eslint-disable-next-line @typescript-eslint/no-empty-function
dontThrow: () => {},
...(0, _jestMatchersObject.getState)(),
equals: _expectUtils.equals,
isNot: this.inverse,
utils
};
}
}
exports.AsymmetricMatcher = AsymmetricMatcher;
class Any extends AsymmetricMatcher {
constructor(sample) {
if (typeof sample === 'undefined') {
throw new TypeError(
'any() expects to be passed a constructor function. ' +
'Please pass one or use anything() to match any object.'
);
}
super(sample);
}
asymmetricMatch(other) {
if (this.sample == String) {
return typeof other == 'string' || other instanceof String;
}
if (this.sample == Number) {
return typeof other == 'number' || other instanceof Number;
}
if (this.sample == Function) {
return typeof other == 'function' || other instanceof Function;
}
if (this.sample == Boolean) {
return typeof other == 'boolean' || other instanceof Boolean;
}
if (this.sample == BigInt) {
return typeof other == 'bigint' || other instanceof BigInt;
}
if (this.sample == Symbol) {
return typeof other == 'symbol' || other instanceof Symbol;
}
if (this.sample == Object) {
return typeof other == 'object';
}
return other instanceof this.sample;
}
toString() {
return 'Any';
}
getExpectedType() {
if (this.sample == String) {
return 'string';
}
if (this.sample == Number) {
return 'number';
}
if (this.sample == Function) {
return 'function';
}
if (this.sample == Object) {
return 'object';
}
if (this.sample == Boolean) {
return 'boolean';
}
return fnNameFor(this.sample);
}
toAsymmetricMatcher() {
return `Any<${fnNameFor(this.sample)}>`;
}
}
class Anything extends AsymmetricMatcher {
asymmetricMatch(other) {
return other != null;
}
toString() {
return 'Anything';
}
// No getExpectedType method, because it matches either null or undefined.
toAsymmetricMatcher() {
return 'Anything';
}
}
class ArrayContaining extends AsymmetricMatcher {
constructor(sample, inverse = false) {
super(sample, inverse);
}
asymmetricMatch(other) {
if (!Array.isArray(this.sample)) {
throw new Error(
`You must provide an array to ${this.toString()}, not '${typeof this
.sample}'.`
);
}
const matcherContext = this.getMatcherContext();
const result =
this.sample.length === 0 ||
(Array.isArray(other) &&
this.sample.every(item =>
other.some(another =>
(0, _expectUtils.equals)(
item,
another,
matcherContext.customTesters
)
)
));
return this.inverse ? !result : result;
}
toString() {
return `Array${this.inverse ? 'Not' : ''}Containing`;
}
getExpectedType() {
return 'array';
}
}
class ObjectContaining extends AsymmetricMatcher {
constructor(sample, inverse = false) {
super(sample, inverse);
}
asymmetricMatch(other) {
if (typeof this.sample !== 'object') {
throw new Error(
`You must provide an object to ${this.toString()}, not '${typeof this
.sample}'.`
);
}
let result = true;
const matcherContext = this.getMatcherContext();
const objectKeys = (0, _expectUtils.getObjectKeys)(this.sample);
for (const key of objectKeys) {
if (
!hasProperty(other, key) ||
!(0, _expectUtils.equals)(
this.sample[key],
other[key],
matcherContext.customTesters
)
) {
result = false;
break;
}
}
return this.inverse ? !result : result;
}
toString() {
return `Object${this.inverse ? 'Not' : ''}Containing`;
}
getExpectedType() {
return 'object';
}
}
class StringContaining extends AsymmetricMatcher {
constructor(sample, inverse = false) {
if (!(0, _expectUtils.isA)('String', sample)) {
throw new Error('Expected is not a string');
}
super(sample, inverse);
}
asymmetricMatch(other) {
const result =
(0, _expectUtils.isA)('String', other) && other.includes(this.sample);
return this.inverse ? !result : result;
}
toString() {
return `String${this.inverse ? 'Not' : ''}Containing`;
}
getExpectedType() {
return 'string';
}
}
class StringMatching extends AsymmetricMatcher {
constructor(sample, inverse = false) {
if (
!(0, _expectUtils.isA)('String', sample) &&
!(0, _expectUtils.isA)('RegExp', sample)
) {
throw new Error('Expected is not a String or a RegExp');
}
super(new RegExp(sample), inverse);
}
asymmetricMatch(other) {
const result =
(0, _expectUtils.isA)('String', other) && this.sample.test(other);
return this.inverse ? !result : result;
}
toString() {
return `String${this.inverse ? 'Not' : ''}Matching`;
}
getExpectedType() {
return 'string';
}
}
class CloseTo extends AsymmetricMatcher {
precision;
constructor(sample, precision = 2, inverse = false) {
if (!(0, _expectUtils.isA)('Number', sample)) {
throw new Error('Expected is not a Number');
}
if (!(0, _expectUtils.isA)('Number', precision)) {
throw new Error('Precision is not a Number');
}
super(sample);
this.inverse = inverse;
this.precision = precision;
}
asymmetricMatch(other) {
if (!(0, _expectUtils.isA)('Number', other)) {
return false;
}
let result = false;
if (other === Infinity && this.sample === Infinity) {
result = true; // Infinity - Infinity is NaN
} else if (other === -Infinity && this.sample === -Infinity) {
result = true; // -Infinity - -Infinity is NaN
} else {
result =
Math.abs(this.sample - other) < Math.pow(10, -this.precision) / 2;
}
return this.inverse ? !result : result;
}
toString() {
return `Number${this.inverse ? 'Not' : ''}CloseTo`;
}
getExpectedType() {
return 'number';
}
toAsymmetricMatcher() {
return [
this.toString(),
this.sample,
`(${(0, _jestUtil.pluralize)('digit', this.precision)})`
].join(' ');
}
}
const any = expectedObject => new Any(expectedObject);
exports.any = any;
const anything = () => new Anything();
exports.anything = anything;
const arrayContaining = sample => new ArrayContaining(sample);
exports.arrayContaining = arrayContaining;
const arrayNotContaining = sample => new ArrayContaining(sample, true);
exports.arrayNotContaining = arrayNotContaining;
const objectContaining = sample => new ObjectContaining(sample);
exports.objectContaining = objectContaining;
const objectNotContaining = sample => new ObjectContaining(sample, true);
exports.objectNotContaining = objectNotContaining;
const stringContaining = expected => new StringContaining(expected);
exports.stringContaining = stringContaining;
const stringNotContaining = expected => new StringContaining(expected, true);
exports.stringNotContaining = stringNotContaining;
const stringMatching = expected => new StringMatching(expected);
exports.stringMatching = stringMatching;
const stringNotMatching = expected => new StringMatching(expected, true);
exports.stringNotMatching = stringNotMatching;
const closeTo = (expected, precision) => new CloseTo(expected, precision);
exports.closeTo = closeTo;
const notCloseTo = (expected, precision) =>
new CloseTo(expected, precision, true);
exports.notCloseTo = notCloseTo;

View File

@@ -1,86 +0,0 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.default = void 0;
var _jestMatcherUtils = require('jest-matcher-utils');
var _jestMatchersObject = require('./jestMatchersObject');
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const resetAssertionsLocalState = () => {
(0, _jestMatchersObject.setState)({
assertionCalls: 0,
expectedAssertionsNumber: null,
isExpectingAssertions: false,
numPassingAsserts: 0
});
};
// Create and format all errors related to the mismatched number of `expect`
// calls and reset the matcher's state.
const extractExpectedAssertionsErrors = () => {
const result = [];
const {
assertionCalls,
expectedAssertionsNumber,
expectedAssertionsNumberError,
isExpectingAssertions,
isExpectingAssertionsError
} = (0, _jestMatchersObject.getState)();
resetAssertionsLocalState();
if (
typeof expectedAssertionsNumber === 'number' &&
assertionCalls !== expectedAssertionsNumber
) {
const numOfAssertionsExpected = (0, _jestMatcherUtils.EXPECTED_COLOR)(
(0, _jestMatcherUtils.pluralize)('assertion', expectedAssertionsNumber)
);
expectedAssertionsNumberError.message =
`${(0, _jestMatcherUtils.matcherHint)(
'.assertions',
'',
expectedAssertionsNumber.toString(),
{
isDirectExpectCall: true
}
)}\n\n` +
`Expected ${numOfAssertionsExpected} to be called but received ${(0,
_jestMatcherUtils.RECEIVED_COLOR)(
(0, _jestMatcherUtils.pluralize)('assertion call', assertionCalls || 0)
)}.`;
result.push({
actual: assertionCalls.toString(),
error: expectedAssertionsNumberError,
expected: expectedAssertionsNumber.toString()
});
}
if (isExpectingAssertions && assertionCalls === 0) {
const expected = (0, _jestMatcherUtils.EXPECTED_COLOR)(
'at least one assertion'
);
const received = (0, _jestMatcherUtils.RECEIVED_COLOR)('received none');
isExpectingAssertionsError.message = `${(0, _jestMatcherUtils.matcherHint)(
'.hasAssertions',
'',
'',
{
isDirectExpectCall: true
}
)}\n\nExpected ${expected} to be called but ${received}.`;
result.push({
actual: 'none',
error: isExpectingAssertionsError,
expected: 'at least one'
});
}
return result;
};
var _default = extractExpectedAssertionsErrors;
exports.default = _default;

387
node_modules/expect/build/index.d.mts generated vendored Normal file
View File

@@ -0,0 +1,387 @@
import { EqualsFunction, Tester, Tester as Tester$1, TesterContext } from "@jest/expect-utils";
import * as jestMatcherUtils from "jest-matcher-utils";
import { MockInstance } from "jest-mock";
//#region src/types.d.ts
type SyncExpectationResult = {
pass: boolean;
message(): string;
};
type AsyncExpectationResult = Promise<SyncExpectationResult>;
type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
type MatcherFunctionWithContext<Context extends MatcherContext = MatcherContext, Expected extends Array<any> = [] /** TODO should be: extends Array<unknown> = [] */> = (this: Context, actual: unknown, ...expected: Expected) => ExpectationResult;
type MatcherFunction<Expected extends Array<unknown> = []> = MatcherFunctionWithContext<MatcherContext, Expected>;
type RawMatcherFn<Context extends MatcherContext = MatcherContext> = {
(this: Context, actual: any, ...expected: Array<any>): ExpectationResult;
};
type MatchersObject = {
[name: string]: RawMatcherFn;
};
interface MatcherUtils {
customTesters: Array<Tester$1>;
dontThrow(): void;
equals: EqualsFunction;
utils: typeof jestMatcherUtils & {
iterableEquality: Tester$1;
subsetEquality: Tester$1;
};
}
interface MatcherState {
assertionCalls: number;
currentConcurrentTestName?: () => string | undefined;
currentTestName?: string;
error?: Error;
expand?: boolean;
expectedAssertionsNumber: number | null;
expectedAssertionsNumberError?: Error;
isExpectingAssertions: boolean;
isExpectingAssertionsError?: Error;
isNot?: boolean;
numPassingAsserts: number;
promise?: string;
suppressedErrors: Array<Error>;
testPath?: string;
}
type MatcherContext = MatcherUtils & Readonly<MatcherState>;
type AsymmetricMatcher$1 = {
asymmetricMatch(other: unknown): boolean;
toString(): string;
getExpectedType?(): string;
toAsymmetricMatcher?(): string;
};
type ExpectedAssertionsErrors = Array<{
actual: string | number;
error: Error;
expected: string;
}>;
interface BaseExpect {
assertions(numberOfAssertions: number): void;
addEqualityTesters(testers: Array<Tester$1>): void;
extend(matchers: MatchersObject): void;
extractExpectedAssertionsErrors(): ExpectedAssertionsErrors;
getState(): MatcherState;
hasAssertions(): void;
setState(state: Partial<MatcherState>): void;
}
type Expect = (<T = unknown>(actual: T) => Matchers<void, T> & Inverse<Matchers<void, T>> & PromiseMatchers<T>) & BaseExpect & AsymmetricMatchers & Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;
type Inverse<Matchers> = {
/**
* Inverse next matcher. If you know how to test something, `.not` lets you test its opposite.
*/
not: Matchers;
};
interface AsymmetricMatchers {
any(sample: unknown): AsymmetricMatcher$1;
anything(): AsymmetricMatcher$1;
arrayContaining(sample: Array<unknown>): AsymmetricMatcher$1;
arrayOf(sample: unknown): AsymmetricMatcher$1;
closeTo(sample: number, precision?: number): AsymmetricMatcher$1;
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher$1;
stringContaining(sample: string): AsymmetricMatcher$1;
stringMatching(sample: string | RegExp): AsymmetricMatcher$1;
}
type PromiseMatchers<T = unknown> = {
/**
* Unwraps the reason of a rejected promise so any other matcher can be chained.
* If the promise is fulfilled the assertion fails.
*/
rejects: Matchers<Promise<void>, T> & Inverse<Matchers<Promise<void>, T>>;
/**
* Unwraps the value of a fulfilled promise so any other matcher can be chained.
* If the promise is rejected the assertion fails.
*/
resolves: Matchers<Promise<void>, T> & Inverse<Matchers<Promise<void>, T>>;
};
interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Checks that a value is what you expect. It calls `Object.is` to compare values.
* Don't use `toBe` with floating-point numbers.
*/
toBe(expected: unknown): R;
/**
* Using exact equality with floating point numbers is a bad idea.
* Rounding means that intuitive things fail.
* The default for `precision` is 2.
*/
toBeCloseTo(expected: number, precision?: number): R;
/**
* Ensure that a variable is not undefined.
*/
toBeDefined(): R;
/**
* When you don't care what a value is, you just want to
* ensure a value is false in a boolean context.
*/
toBeFalsy(): R;
/**
* For comparing floating point numbers.
*/
toBeGreaterThan(expected: number | bigint): R;
/**
* For comparing floating point numbers.
*/
toBeGreaterThanOrEqual(expected: number | bigint): R;
/**
* Ensure that an object is an instance of a class.
* This matcher uses `instanceof` underneath.
*/
toBeInstanceOf(expected: unknown): R;
/**
* For comparing floating point numbers.
*/
toBeLessThan(expected: number | bigint): R;
/**
* For comparing floating point numbers.
*/
toBeLessThanOrEqual(expected: number | bigint): R;
/**
* Used to check that a variable is NaN.
*/
toBeNaN(): R;
/**
* This is the same as `.toBe(null)` but the error messages are a bit nicer.
* So use `.toBeNull()` when you want to check that something is null.
*/
toBeNull(): R;
/**
* Use when you don't care what a value is, you just want to ensure a value
* is true in a boolean context. In JavaScript, there are six falsy values:
* `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
*/
toBeTruthy(): R;
/**
* Used to check that a variable is undefined.
*/
toBeUndefined(): R;
/**
* Used when you want to check that an item is in a list.
* For testing the items in the list, this uses `===`, a strict equality check.
*/
toContain(expected: unknown): R;
/**
* Used when you want to check that an item is in a list.
* For testing the items in the list, this matcher recursively checks the
* equality of all fields, rather than checking for object identity.
*/
toContainEqual(expected: unknown): R;
/**
* Used when you want to check that two objects have the same value.
* This matcher recursively checks the equality of all fields, rather than checking for object identity.
*/
toEqual(expected: unknown): R;
/**
* Ensures that a mock function is called.
*/
toHaveBeenCalled(): R;
/**
* Ensures that a mock function is called an exact number of times.
*/
toHaveBeenCalledTimes(expected: number): R;
/**
* Ensure that a mock function is called with specific arguments.
*/
toHaveBeenCalledWith(...expected: MockParameters<T>): R;
/**
* Ensure that a mock function is called with specific arguments on an Nth call.
*/
toHaveBeenNthCalledWith(nth: number, ...expected: MockParameters<T>): R;
/**
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
* to test what arguments it was last called with.
*/
toHaveBeenLastCalledWith(...expected: MockParameters<T>): R;
/**
* Use to test the specific value that a mock function last returned.
* If the last call to the mock function threw an error, then this matcher will fail
* no matter what value you provided as the expected return value.
*/
toHaveLastReturnedWith(expected?: unknown): R;
/**
* Used to check that an object has a `.length` property
* and it is set to a certain numeric value.
*/
toHaveLength(expected: number): R;
/**
* Use to test the specific value that a mock function returned for the nth call.
* If the nth call to the mock function threw an error, then this matcher will fail
* no matter what value you provided as the expected return value.
*/
toHaveNthReturnedWith(nth: number, expected?: unknown): R;
/**
* Use to check if property at provided reference keyPath exists for an object.
* For checking deeply nested properties in an object you may use dot notation or an array containing
* the keyPath for deep references.
*
* Optionally, you can provide a value to check if it's equal to the value present at keyPath
* on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
* the equality of all fields.
*
* @example
*
* expect(houseForSale).toHaveProperty('kitchen.area', 20);
*/
toHaveProperty(expectedPath: string | Array<string>, expectedValue?: unknown): R;
/**
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
*/
toHaveReturned(): R;
/**
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
*/
toHaveReturnedTimes(expected: number): R;
/**
* Use to ensure that a mock function returned a specific value.
*/
toHaveReturnedWith(expected?: unknown): R;
/**
* Check that a string matches a regular expression.
*/
toMatch(expected: string | RegExp): R;
/**
* Used to check that a JavaScript object matches a subset of the properties of an object
*/
toMatchObject(expected: Record<string, unknown> | Array<Record<string, unknown>>): R;
/**
* Use to test that objects have the same types as well as structure.
*/
toStrictEqual(expected: unknown): R;
/**
* Used to test that a function throws when it is called.
*/
toThrow(expected?: unknown): R;
}
/**
* Obtains the parameters of the given function or {@link MockInstance}'s function type.
* ```ts
* type P = MockParameters<MockInstance<(foo: number) => void>>;
* // or without an explicit mock
* // type P = MockParameters<(foo: number) => void>;
*
* const params1: P = [1]; // compiles
* const params2: P = ['bar']; // error
* const params3: P = []; // error
* ```
*
* This is similar to {@link Parameters}, with these notable differences:
*
* 1. Each of the parameters can also accept an {@link AsymmetricMatcher}.
* ```ts
* const params4: P = [expect.anything()]; // compiles
* ```
* This works with nested types as well:
* ```ts
* type Nested = MockParameters<MockInstance<(foo: { a: number }, bar: [string]) => void>>;
*
* const params1: Nested = [{ foo: { a: 1 }}, ['value']]; // compiles
* const params2: Nested = [expect.anything(), expect.anything()]; // compiles
* const params3: Nested = [{ foo: { a: expect.anything() }}, [expect.anything()]]; // compiles
* ```
*
* 2. This type works with overloaded functions (up to 15 overloads):
* ```ts
* function overloaded(): void;
* function overloaded(foo: number): void;
* function overloaded(foo: number, bar: string): void;
* function overloaded(foo?: number, bar?: string): void {}
*
* type Overloaded = MockParameters<MockInstance<typeof overloaded>>;
*
* const params1: Overloaded = []; // compiles
* const params2: Overloaded = [1]; // compiles
* const params3: Overloaded = [1, 'value']; // compiles
* const params4: Overloaded = ['value']; // error
* const params5: Overloaded = ['value', 1]; // error
* ```
*
* Mocks generated with the default `MockInstance` type will evaluate to `Array<unknown>`:
* ```ts
* MockParameters<MockInstance> // Array<unknown>
* ```
*
* If the given type is not a `MockInstance` nor a function, this type will evaluate to `Array<unknown>`:
* ```ts
* MockParameters<boolean> // Array<unknown>
* ```
*/
type MockParameters<M> = M extends MockInstance<infer F> ? FunctionParameters<F> : FunctionParameters<M>;
/**
* A wrapper over `FunctionParametersInternal` which converts `never` evaluations to `Array<unknown>`.
*
* This is only necessary for Typescript versions prior to 5.3.
*
* In those versions, a function without parameters (`() => any`) is interpreted the same as an overloaded function,
* causing `FunctionParametersInternal` to evaluate it to `[] | Array<unknown>`, which is incorrect.
*
* The workaround is to "catch" this edge-case in `WithAsymmetricMatchers` and interpret it as `never`.
* However, this also affects {@link UnknownFunction} (the default generic type of `MockInstance`):
* ```ts
* FunctionParametersInternal<() => any> // [] | never --> [] --> correct
* FunctionParametersInternal<UnknownFunction> // never --> incorrect
* ```
* An empty array is the expected type for a function without parameters,
* so all that's left is converting `never` to `Array<unknown>` for the case of `UnknownFunction`,
* as it needs to accept _any_ combination of parameters.
*/
type FunctionParameters<F> = FunctionParametersInternal<F> extends never ? Array<unknown> : FunctionParametersInternal<F>;
/**
* 1. If the function is overloaded or has no parameters -> overloaded form (union of tuples).
* 2. If the function has parameters -> simple form.
* 3. else -> `never`.
*/
type FunctionParametersInternal<F> = F extends {
(...args: infer P1): any;
(...args: infer P2): any;
(...args: infer P3): any;
(...args: infer P4): any;
(...args: infer P5): any;
(...args: infer P6): any;
(...args: infer P7): any;
(...args: infer P8): any;
(...args: infer P9): any;
(...args: infer P10): any;
(...args: infer P11): any;
(...args: infer P12): any;
(...args: infer P13): any;
(...args: infer P14): any;
(...args: infer P15): any;
} ? WithAsymmetricMatchers<P1> | WithAsymmetricMatchers<P2> | WithAsymmetricMatchers<P3> | WithAsymmetricMatchers<P4> | WithAsymmetricMatchers<P5> | WithAsymmetricMatchers<P6> | WithAsymmetricMatchers<P7> | WithAsymmetricMatchers<P8> | WithAsymmetricMatchers<P9> | WithAsymmetricMatchers<P10> | WithAsymmetricMatchers<P11> | WithAsymmetricMatchers<P12> | WithAsymmetricMatchers<P13> | WithAsymmetricMatchers<P14> | WithAsymmetricMatchers<P15> : F extends ((...args: infer P) => any) ? WithAsymmetricMatchers<P> : never;
/**
* @see FunctionParameters
*/
type WithAsymmetricMatchers<P extends Array<any>> = Array<unknown> extends P ? never : { [K in keyof P]: DeepAsymmetricMatcher<P[K]> };
/**
* Replaces `T` with `T | AsymmetricMatcher`.
*
* If `T` is an object or an array, recursively replaces all nested types with the same logic:
* ```ts
* type DeepAsymmetricMatcher<boolean>; // AsymmetricMatcher | boolean
* type DeepAsymmetricMatcher<{ foo: number }>; // AsymmetricMatcher | { foo: AsymmetricMatcher | number }
* type DeepAsymmetricMatcher<[string]>; // AsymmetricMatcher | [AsymmetricMatcher | string]
* ```
*/
type DeepAsymmetricMatcher<T> = T extends object ? AsymmetricMatcher$1 | { [K in keyof T]: DeepAsymmetricMatcher<T[K]> } : AsymmetricMatcher$1 | T;
//#endregion
//#region src/asymmetricMatchers.d.ts
declare abstract class AsymmetricMatcher<T> implements AsymmetricMatcher$1 {
protected sample: T;
protected inverse: boolean;
$$typeof: symbol;
constructor(sample: T, inverse?: boolean);
protected getMatcherContext(): MatcherContext;
abstract asymmetricMatch(other: unknown): boolean;
abstract toString(): string;
getExpectedType?(): string;
toAsymmetricMatcher?(): string;
}
//#endregion
//#region src/index.d.ts
declare class JestAssertionError extends Error {
matcherResult?: Omit<SyncExpectationResult, 'message'> & {
message: string;
};
}
declare const expect: Expect;
//#endregion
export { AsymmetricMatcher, AsymmetricMatchers, AsyncExpectationResult, BaseExpect, Expect, ExpectationResult, JestAssertionError, MatcherContext, MatcherFunction, MatcherFunctionWithContext, MatcherState, MatcherUtils, Matchers, SyncExpectationResult, Tester, TesterContext, expect as default, expect };

233
node_modules/expect/build/index.d.ts generated vendored
View File

@@ -4,10 +4,10 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {EqualsFunction} from '@jest/expect-utils';
import type * as jestMatcherUtils from 'jest-matcher-utils';
import {Tester} from '@jest/expect-utils';
import {TesterContext} from '@jest/expect-utils';
import {EqualsFunction, Tester, TesterContext} from '@jest/expect-utils';
import * as jestMatcherUtils from 'jest-matcher-utils';
import {MockInstance} from 'jest-mock';
export declare abstract class AsymmetricMatcher<T>
implements AsymmetricMatcher_2
@@ -34,6 +34,7 @@ export declare interface AsymmetricMatchers {
any(sample: unknown): AsymmetricMatcher_2;
anything(): AsymmetricMatcher_2;
arrayContaining(sample: Array<unknown>): AsymmetricMatcher_2;
arrayOf(sample: unknown): AsymmetricMatcher_2;
closeTo(sample: number, precision?: number): AsymmetricMatcher_2;
objectContaining(sample: Record<string, unknown>): AsymmetricMatcher_2;
stringContaining(sample: string): AsymmetricMatcher_2;
@@ -52,11 +53,28 @@ export declare interface BaseExpect {
setState(state: Partial<MatcherState>): void;
}
export declare type Expect = {
<T = unknown>(actual: T): Matchers<void, T> &
Inverse<Matchers<void, T>> &
PromiseMatchers<T>;
} & BaseExpect &
/**
* Replaces `T` with `T | AsymmetricMatcher`.
*
* If `T` is an object or an array, recursively replaces all nested types with the same logic:
* ```ts
* type DeepAsymmetricMatcher<boolean>; // AsymmetricMatcher | boolean
* type DeepAsymmetricMatcher<{ foo: number }>; // AsymmetricMatcher | { foo: AsymmetricMatcher | number }
* type DeepAsymmetricMatcher<[string]>; // AsymmetricMatcher | [AsymmetricMatcher | string]
* ```
*/
declare type DeepAsymmetricMatcher<T> = T extends object
?
| AsymmetricMatcher_2
| {
[K in keyof T]: DeepAsymmetricMatcher<T[K]>;
}
: AsymmetricMatcher_2 | T;
export declare type Expect = (<T = unknown>(
actual: T,
) => Matchers<void, T> & Inverse<Matchers<void, T>> & PromiseMatchers<T>) &
BaseExpect &
AsymmetricMatchers &
Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;
@@ -74,7 +92,72 @@ declare type ExpectedAssertionsErrors = Array<{
expected: string;
}>;
declare type Inverse<Matchers> = {
/**
* A wrapper over `FunctionParametersInternal` which converts `never` evaluations to `Array<unknown>`.
*
* This is only necessary for Typescript versions prior to 5.3.
*
* In those versions, a function without parameters (`() => any`) is interpreted the same as an overloaded function,
* causing `FunctionParametersInternal` to evaluate it to `[] | Array<unknown>`, which is incorrect.
*
* The workaround is to "catch" this edge-case in `WithAsymmetricMatchers` and interpret it as `never`.
* However, this also affects {@link UnknownFunction} (the default generic type of `MockInstance`):
* ```ts
* FunctionParametersInternal<() => any> // [] | never --> [] --> correct
* FunctionParametersInternal<UnknownFunction> // never --> incorrect
* ```
* An empty array is the expected type for a function without parameters,
* so all that's left is converting `never` to `Array<unknown>` for the case of `UnknownFunction`,
* as it needs to accept _any_ combination of parameters.
*/
declare type FunctionParameters<F> =
FunctionParametersInternal<F> extends never
? Array<unknown>
: FunctionParametersInternal<F>;
/**
* 1. If the function is overloaded or has no parameters -> overloaded form (union of tuples).
* 2. If the function has parameters -> simple form.
* 3. else -> `never`.
*/
declare type FunctionParametersInternal<F> = F extends {
(...args: infer P1): any;
(...args: infer P2): any;
(...args: infer P3): any;
(...args: infer P4): any;
(...args: infer P5): any;
(...args: infer P6): any;
(...args: infer P7): any;
(...args: infer P8): any;
(...args: infer P9): any;
(...args: infer P10): any;
(...args: infer P11): any;
(...args: infer P12): any;
(...args: infer P13): any;
(...args: infer P14): any;
(...args: infer P15): any;
}
?
| WithAsymmetricMatchers<P1>
| WithAsymmetricMatchers<P2>
| WithAsymmetricMatchers<P3>
| WithAsymmetricMatchers<P4>
| WithAsymmetricMatchers<P5>
| WithAsymmetricMatchers<P6>
| WithAsymmetricMatchers<P7>
| WithAsymmetricMatchers<P8>
| WithAsymmetricMatchers<P9>
| WithAsymmetricMatchers<P10>
| WithAsymmetricMatchers<P11>
| WithAsymmetricMatchers<P12>
| WithAsymmetricMatchers<P13>
| WithAsymmetricMatchers<P14>
| WithAsymmetricMatchers<P15>
: F extends (...args: infer P) => any
? WithAsymmetricMatchers<P>
: never;
export declare type Inverse<Matchers> = {
/**
* Inverse next matcher. If you know how to test something, `.not` lets you test its opposite.
*/
@@ -94,7 +177,8 @@ export declare type MatcherFunction<Expected extends Array<unknown> = []> =
export declare type MatcherFunctionWithContext<
Context extends MatcherContext = MatcherContext,
Expected extends Array<any> = [] /** TODO should be: extends Array<unknown> = [] */,
Expected extends
Array<any> = [] /** TODO should be: extends Array<unknown> = [] */,
> = (
this: Context,
actual: unknown,
@@ -102,39 +186,11 @@ export declare type MatcherFunctionWithContext<
) => ExpectationResult;
export declare interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Ensures the last call to a mock function was provided specific args.
*/
lastCalledWith(...expected: Array<unknown>): R;
/**
* Ensure that the last call to a mock function has returned a specified value.
*/
lastReturnedWith(expected?: unknown): R;
/**
* Ensure that a mock function is called with specific arguments on an Nth call.
*/
nthCalledWith(nth: number, ...expected: Array<unknown>): R;
/**
* Ensure that the nth call to a mock function has returned a specified value.
*/
nthReturnedWith(nth: number, expected?: unknown): R;
/**
* Checks that a value is what you expect. It calls `Object.is` to compare values.
* Don't use `toBe` with floating-point numbers.
*/
toBe(expected: unknown): R;
/**
* Ensures that a mock function is called.
*/
toBeCalled(): R;
/**
* Ensures that a mock function is called an exact number of times.
*/
toBeCalledTimes(expected: number): R;
/**
* Ensure that a mock function is called with specific arguments.
*/
toBeCalledWith(...expected: Array<unknown>): R;
/**
* Using exact equality with floating point numbers is a bad idea.
* Rounding means that intuitive things fail.
@@ -193,6 +249,7 @@ export declare interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Used when you want to check that an item is in a list.
* For testing the items in the list, this uses `===`, a strict equality check.
* `.toContain` can also check whether a string is a substring of another string.
*/
toContain(expected: unknown): R;
/**
@@ -217,16 +274,16 @@ export declare interface Matchers<R extends void | Promise<void>, T = unknown> {
/**
* Ensure that a mock function is called with specific arguments.
*/
toHaveBeenCalledWith(...expected: Array<unknown>): R;
toHaveBeenCalledWith(...expected: MockParameters<T>): R;
/**
* Ensure that a mock function is called with specific arguments on an Nth call.
*/
toHaveBeenNthCalledWith(nth: number, ...expected: Array<unknown>): R;
toHaveBeenNthCalledWith(nth: number, ...expected: MockParameters<T>): R;
/**
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
* to test what arguments it was last called with.
*/
toHaveBeenLastCalledWith(...expected: Array<unknown>): R;
toHaveBeenLastCalledWith(...expected: MockParameters<T>): R;
/**
* Use to test the specific value that a mock function last returned.
* If the last call to the mock function threw an error, then this matcher will fail
@@ -284,18 +341,6 @@ export declare interface Matchers<R extends void | Promise<void>, T = unknown> {
toMatchObject(
expected: Record<string, unknown> | Array<Record<string, unknown>>,
): R;
/**
* Ensure that a mock function has returned (as opposed to thrown) at least once.
*/
toReturn(): R;
/**
* Ensure that a mock function has returned (as opposed to thrown) a specified number of times.
*/
toReturnTimes(expected: number): R;
/**
* Ensure that a mock function has returned a specified value at least once.
*/
toReturnWith(expected?: unknown): R;
/**
* Use to test that objects have the same types as well as structure.
*/
@@ -304,10 +349,6 @@ export declare interface Matchers<R extends void | Promise<void>, T = unknown> {
* Used to test that a function throws when it is called.
*/
toThrow(expected?: unknown): R;
/**
* If you want to test that a specific error is thrown inside a function.
*/
toThrowError(expected?: unknown): R;
}
declare type MatchersObject = {
@@ -341,6 +382,64 @@ export declare interface MatcherUtils {
};
}
/**
* Obtains the parameters of the given function or {@link MockInstance}'s function type.
* ```ts
* type P = MockParameters<MockInstance<(foo: number) => void>>;
* // or without an explicit mock
* // type P = MockParameters<(foo: number) => void>;
*
* const params1: P = [1]; // compiles
* const params2: P = ['bar']; // error
* const params3: P = []; // error
* ```
*
* This is similar to {@link Parameters}, with these notable differences:
*
* 1. Each of the parameters can also accept an {@link AsymmetricMatcher}.
* ```ts
* const params4: P = [expect.anything()]; // compiles
* ```
* This works with nested types as well:
* ```ts
* type Nested = MockParameters<MockInstance<(foo: { a: number }, bar: [string]) => void>>;
*
* const params1: Nested = [{ foo: { a: 1 }}, ['value']]; // compiles
* const params2: Nested = [expect.anything(), expect.anything()]; // compiles
* const params3: Nested = [{ foo: { a: expect.anything() }}, [expect.anything()]]; // compiles
* ```
*
* 2. This type works with overloaded functions (up to 15 overloads):
* ```ts
* function overloaded(): void;
* function overloaded(foo: number): void;
* function overloaded(foo: number, bar: string): void;
* function overloaded(foo?: number, bar?: string): void {}
*
* type Overloaded = MockParameters<MockInstance<typeof overloaded>>;
*
* const params1: Overloaded = []; // compiles
* const params2: Overloaded = [1]; // compiles
* const params3: Overloaded = [1, 'value']; // compiles
* const params4: Overloaded = ['value']; // error
* const params5: Overloaded = ['value', 1]; // error
* ```
*
* Mocks generated with the default `MockInstance` type will evaluate to `Array<unknown>`:
* ```ts
* MockParameters<MockInstance> // Array<unknown>
* ```
*
* If the given type is not a `MockInstance` nor a function, this type will evaluate to `Array<unknown>`:
* ```ts
* MockParameters<boolean> // Array<unknown>
* ```
*/
declare type MockParameters<M> =
M extends MockInstance<infer F>
? FunctionParameters<F>
: FunctionParameters<M>;
declare type PromiseMatchers<T = unknown> = {
/**
* Unwraps the reason of a rejected promise so any other matcher can be chained.
@@ -354,9 +453,11 @@ declare type PromiseMatchers<T = unknown> = {
resolves: Matchers<Promise<void>, T> & Inverse<Matchers<Promise<void>, T>>;
};
declare type RawMatcherFn<Context extends MatcherContext = MatcherContext> = {
(this: Context, actual: any, ...expected: Array<any>): ExpectationResult;
};
declare type RawMatcherFn<Context extends MatcherContext = MatcherContext> = (
this: Context,
actual: any,
...expected: Array<any>
) => ExpectationResult;
export declare type SyncExpectationResult = {
pass: boolean;
@@ -367,4 +468,14 @@ export {Tester};
export {TesterContext};
/**
* @see FunctionParameters
*/
declare type WithAsymmetricMatchers<P extends Array<any>> =
Array<unknown> extends P
? never
: {
[K in keyof P]: DeepAsymmetricMatcher<P[K]>;
};
export {};

2528
node_modules/expect/build/index.js generated vendored

File diff suppressed because it is too large Load Diff

6
node_modules/expect/build/index.mjs generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import cjsModule from './index.js';
export const AsymmetricMatcher = cjsModule.AsymmetricMatcher;
export const JestAssertionError = cjsModule.JestAssertionError;
export const expect = cjsModule.expect;
export default cjsModule.default;

View File

@@ -1,123 +0,0 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.setState =
exports.setMatchers =
exports.getState =
exports.getMatchers =
exports.getCustomEqualityTesters =
exports.addCustomEqualityTesters =
exports.INTERNAL_MATCHER_FLAG =
void 0;
var _jestGetType = require('jest-get-type');
var _asymmetricMatchers = require('./asymmetricMatchers');
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol;
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
// Global matchers object holds the list of available matchers and
// the state, that can hold matcher specific values that change over time.
const JEST_MATCHERS_OBJECT = Symbol.for('$$jest-matchers-object');
// Notes a built-in/internal Jest matcher.
// Jest may override the stack trace of Errors thrown by internal matchers.
const INTERNAL_MATCHER_FLAG = Symbol.for('$$jest-internal-matcher');
exports.INTERNAL_MATCHER_FLAG = INTERNAL_MATCHER_FLAG;
if (!Object.prototype.hasOwnProperty.call(globalThis, JEST_MATCHERS_OBJECT)) {
const defaultState = {
assertionCalls: 0,
expectedAssertionsNumber: null,
isExpectingAssertions: false,
numPassingAsserts: 0,
suppressedErrors: [] // errors that are not thrown immediately.
};
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
value: {
customEqualityTesters: [],
matchers: Object.create(null),
state: defaultState
}
});
}
const getState = () => globalThis[JEST_MATCHERS_OBJECT].state;
exports.getState = getState;
const setState = state => {
Object.assign(globalThis[JEST_MATCHERS_OBJECT].state, state);
};
exports.setState = setState;
const getMatchers = () => globalThis[JEST_MATCHERS_OBJECT].matchers;
exports.getMatchers = getMatchers;
const setMatchers = (matchers, isInternal, expect) => {
Object.keys(matchers).forEach(key => {
const matcher = matchers[key];
if (typeof matcher !== 'function') {
throw new TypeError(
`expect.extend: \`${key}\` is not a valid matcher. Must be a function, is "${(0,
_jestGetType.getType)(matcher)}"`
);
}
Object.defineProperty(matcher, INTERNAL_MATCHER_FLAG, {
value: isInternal
});
if (!isInternal) {
// expect is defined
class CustomMatcher extends _asymmetricMatchers.AsymmetricMatcher {
constructor(inverse = false, ...sample) {
super(sample, inverse);
}
asymmetricMatch(other) {
const {pass} = matcher.call(
this.getMatcherContext(),
other,
...this.sample
);
return this.inverse ? !pass : pass;
}
toString() {
return `${this.inverse ? 'not.' : ''}${key}`;
}
getExpectedType() {
return 'any';
}
toAsymmetricMatcher() {
return `${this.toString()}<${this.sample.map(String).join(', ')}>`;
}
}
Object.defineProperty(expect, key, {
configurable: true,
enumerable: true,
value: (...sample) => new CustomMatcher(false, ...sample),
writable: true
});
Object.defineProperty(expect.not, key, {
configurable: true,
enumerable: true,
value: (...sample) => new CustomMatcher(true, ...sample),
writable: true
});
}
});
Object.assign(globalThis[JEST_MATCHERS_OBJECT].matchers, matchers);
};
exports.setMatchers = setMatchers;
const getCustomEqualityTesters = () =>
globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters;
exports.getCustomEqualityTesters = getCustomEqualityTesters;
const addCustomEqualityTesters = newTesters => {
if (!Array.isArray(newTesters)) {
throw new TypeError(
`expect.customEqualityTesters: Must be set to an array of Testers. Was given "${(0,
_jestGetType.getType)(newTesters)}"`
);
}
globalThis[JEST_MATCHERS_OBJECT].customEqualityTesters.push(...newTesters);
};
exports.addCustomEqualityTesters = addCustomEqualityTesters;

1292
node_modules/expect/build/matchers.js generated vendored

File diff suppressed because it is too large Load Diff

122
node_modules/expect/build/print.js generated vendored
View File

@@ -1,122 +0,0 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.printReceivedStringContainExpectedSubstring =
exports.printReceivedStringContainExpectedResult =
exports.printReceivedConstructorNameNot =
exports.printReceivedConstructorName =
exports.printReceivedArrayContainExpectedItem =
exports.printExpectedConstructorNameNot =
exports.printExpectedConstructorName =
exports.printCloseTo =
void 0;
var _jestMatcherUtils = require('jest-matcher-utils');
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/* eslint-disable local/ban-types-eventually */
// Format substring but do not enclose in double quote marks.
// The replacement is compatible with pretty-format package.
const printSubstring = val => val.replace(/"|\\/g, '\\$&');
const printReceivedStringContainExpectedSubstring = (
received,
start,
length // not end
) =>
(0, _jestMatcherUtils.RECEIVED_COLOR)(
`"${printSubstring(received.slice(0, start))}${(0,
_jestMatcherUtils.INVERTED_COLOR)(
printSubstring(received.slice(start, start + length))
)}${printSubstring(received.slice(start + length))}"`
);
exports.printReceivedStringContainExpectedSubstring =
printReceivedStringContainExpectedSubstring;
const printReceivedStringContainExpectedResult = (received, result) =>
result === null
? (0, _jestMatcherUtils.printReceived)(received)
: printReceivedStringContainExpectedSubstring(
received,
result.index,
result[0].length
);
// The serialized array is compatible with pretty-format package min option.
// However, items have default stringify depth (instead of depth - 1)
// so expected item looks consistent by itself and enclosed in the array.
exports.printReceivedStringContainExpectedResult =
printReceivedStringContainExpectedResult;
const printReceivedArrayContainExpectedItem = (received, index) =>
(0, _jestMatcherUtils.RECEIVED_COLOR)(
`[${received
.map((item, i) => {
const stringified = (0, _jestMatcherUtils.stringify)(item);
return i === index
? (0, _jestMatcherUtils.INVERTED_COLOR)(stringified)
: stringified;
})
.join(', ')}]`
);
exports.printReceivedArrayContainExpectedItem =
printReceivedArrayContainExpectedItem;
const printCloseTo = (receivedDiff, expectedDiff, precision, isNot) => {
const receivedDiffString = (0, _jestMatcherUtils.stringify)(receivedDiff);
const expectedDiffString = receivedDiffString.includes('e')
? // toExponential arg is number of digits after the decimal point.
expectedDiff.toExponential(0)
: 0 <= precision && precision < 20
? // toFixed arg is number of digits after the decimal point.
// It may be a value between 0 and 20 inclusive.
// Implementations may optionally support a larger range of values.
expectedDiff.toFixed(precision + 1)
: (0, _jestMatcherUtils.stringify)(expectedDiff);
return (
`Expected precision: ${isNot ? ' ' : ''} ${(0,
_jestMatcherUtils.stringify)(precision)}\n` +
`Expected difference: ${isNot ? 'not ' : ''}< ${(0,
_jestMatcherUtils.EXPECTED_COLOR)(expectedDiffString)}\n` +
`Received difference: ${isNot ? ' ' : ''} ${(0,
_jestMatcherUtils.RECEIVED_COLOR)(receivedDiffString)}`
);
};
exports.printCloseTo = printCloseTo;
const printExpectedConstructorName = (label, expected) =>
`${printConstructorName(label, expected, false, true)}\n`;
exports.printExpectedConstructorName = printExpectedConstructorName;
const printExpectedConstructorNameNot = (label, expected) =>
`${printConstructorName(label, expected, true, true)}\n`;
exports.printExpectedConstructorNameNot = printExpectedConstructorNameNot;
const printReceivedConstructorName = (label, received) =>
`${printConstructorName(label, received, false, false)}\n`;
// Do not call function if received is equal to expected.
exports.printReceivedConstructorName = printReceivedConstructorName;
const printReceivedConstructorNameNot = (label, received, expected) =>
typeof expected.name === 'string' &&
expected.name.length !== 0 &&
typeof received.name === 'string' &&
received.name.length !== 0
? `${printConstructorName(label, received, true, false)} ${
Object.getPrototypeOf(received) === expected
? 'extends'
: 'extends … extends'
} ${(0, _jestMatcherUtils.EXPECTED_COLOR)(expected.name)}\n`
: `${printConstructorName(label, received, false, false)}\n`;
exports.printReceivedConstructorNameNot = printReceivedConstructorNameNot;
const printConstructorName = (label, constructor, isNot, isExpected) =>
typeof constructor.name !== 'string'
? `${label} name is not a string`
: constructor.name.length === 0
? `${label} name is an empty string`
: `${label}: ${!isNot ? '' : isExpected ? 'not ' : ' '}${
isExpected
? (0, _jestMatcherUtils.EXPECTED_COLOR)(constructor.name)
: (0, _jestMatcherUtils.RECEIVED_COLOR)(constructor.name)
}`;

File diff suppressed because it is too large Load Diff

View File

@@ -1,481 +0,0 @@
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.default = exports.createMatcher = void 0;
var _expectUtils = require('@jest/expect-utils');
var _jestMatcherUtils = require('jest-matcher-utils');
var _jestMessageUtil = require('jest-message-util');
var _print = require('./print');
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/* eslint-disable local/ban-types-eventually */
const DID_NOT_THROW = 'Received function did not throw';
const getThrown = e => {
const hasMessage =
e !== null && e !== undefined && typeof e.message === 'string';
if (hasMessage && typeof e.name === 'string' && typeof e.stack === 'string') {
return {
hasMessage,
isError: true,
message: e.message,
value: e
};
}
return {
hasMessage,
isError: false,
message: hasMessage ? e.message : String(e),
value: e
};
};
const createMatcher = (matcherName, fromPromise) =>
function (received, expected) {
const options = {
isNot: this.isNot,
promise: this.promise
};
let thrown = null;
if (fromPromise && (0, _expectUtils.isError)(received)) {
thrown = getThrown(received);
} else {
if (typeof received !== 'function') {
if (!fromPromise) {
const placeholder = expected === undefined ? '' : 'expected';
throw new Error(
(0, _jestMatcherUtils.matcherErrorMessage)(
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
placeholder,
options
),
`${(0, _jestMatcherUtils.RECEIVED_COLOR)(
'received'
)} value must be a function`,
(0, _jestMatcherUtils.printWithType)(
'Received',
received,
_jestMatcherUtils.printReceived
)
)
);
}
} else {
try {
received();
} catch (e) {
thrown = getThrown(e);
}
}
}
if (expected === undefined) {
return toThrow(matcherName, options, thrown);
} else if (typeof expected === 'function') {
return toThrowExpectedClass(matcherName, options, thrown, expected);
} else if (typeof expected === 'string') {
return toThrowExpectedString(matcherName, options, thrown, expected);
} else if (expected !== null && typeof expected.test === 'function') {
return toThrowExpectedRegExp(matcherName, options, thrown, expected);
} else if (
expected !== null &&
typeof expected.asymmetricMatch === 'function'
) {
return toThrowExpectedAsymmetric(matcherName, options, thrown, expected);
} else if (expected !== null && typeof expected === 'object') {
return toThrowExpectedObject(matcherName, options, thrown, expected);
} else {
throw new Error(
(0, _jestMatcherUtils.matcherErrorMessage)(
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
),
`${(0, _jestMatcherUtils.EXPECTED_COLOR)(
'expected'
)} value must be a string or regular expression or class or error`,
(0, _jestMatcherUtils.printWithType)(
'Expected',
expected,
_jestMatcherUtils.printExpected
)
)
);
}
};
exports.createMatcher = createMatcher;
const matchers = {
toThrow: createMatcher('toThrow'),
toThrowError: createMatcher('toThrowError')
};
const toThrowExpectedRegExp = (matcherName, options, thrown, expected) => {
const pass = thrown !== null && expected.test(thrown.message);
const message = pass
? () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
formatExpected('Expected pattern: not ', expected) +
(thrown !== null && thrown.hasMessage
? formatReceived(
'Received message: ',
thrown,
'message',
expected
) + formatStack(thrown)
: formatReceived('Received value: ', thrown, 'value'))
: () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
formatExpected('Expected pattern: ', expected) +
(thrown === null
? `\n${DID_NOT_THROW}`
: thrown.hasMessage
? formatReceived('Received message: ', thrown, 'message') +
formatStack(thrown)
: formatReceived('Received value: ', thrown, 'value'));
return {
message,
pass
};
};
const toThrowExpectedAsymmetric = (matcherName, options, thrown, expected) => {
const pass = thrown !== null && expected.asymmetricMatch(thrown.value);
const message = pass
? () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
formatExpected('Expected asymmetric matcher: not ', expected) +
'\n' +
(thrown !== null && thrown.hasMessage
? formatReceived('Received name: ', thrown, 'name') +
formatReceived('Received message: ', thrown, 'message') +
formatStack(thrown)
: formatReceived('Thrown value: ', thrown, 'value'))
: () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
formatExpected('Expected asymmetric matcher: ', expected) +
'\n' +
(thrown === null
? DID_NOT_THROW
: thrown.hasMessage
? formatReceived('Received name: ', thrown, 'name') +
formatReceived('Received message: ', thrown, 'message') +
formatStack(thrown)
: formatReceived('Thrown value: ', thrown, 'value'));
return {
message,
pass
};
};
const toThrowExpectedObject = (matcherName, options, thrown, expected) => {
const expectedMessageAndCause = createMessageAndCause(expected);
const thrownMessageAndCause =
thrown !== null ? createMessageAndCause(thrown.value) : null;
const pass =
thrown !== null &&
thrown.message === expected.message &&
thrownMessageAndCause === expectedMessageAndCause;
const message = pass
? () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
formatExpected(
`Expected ${messageAndCause(expected)}: not `,
expectedMessageAndCause
) +
(thrown !== null && thrown.hasMessage
? formatStack(thrown)
: formatReceived('Received value: ', thrown, 'value'))
: () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
(thrown === null
? // eslint-disable-next-line prefer-template
formatExpected(
`Expected ${messageAndCause(expected)}: `,
expectedMessageAndCause
) +
'\n' +
DID_NOT_THROW
: thrown.hasMessage
? // eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.printDiffOrStringify)(
expectedMessageAndCause,
thrownMessageAndCause,
`Expected ${messageAndCause(expected)}`,
`Received ${messageAndCause(thrown.value)}`,
true
) +
'\n' +
formatStack(thrown)
: formatExpected(
`Expected ${messageAndCause(expected)}: `,
expectedMessageAndCause
) + formatReceived('Received value: ', thrown, 'value'));
return {
message,
pass
};
};
const toThrowExpectedClass = (matcherName, options, thrown, expected) => {
const pass = thrown !== null && thrown.value instanceof expected;
const message = pass
? () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
(0, _print.printExpectedConstructorNameNot)(
'Expected constructor',
expected
) +
(thrown !== null &&
thrown.value != null &&
typeof thrown.value.constructor === 'function' &&
thrown.value.constructor !== expected
? (0, _print.printReceivedConstructorNameNot)(
'Received constructor',
thrown.value.constructor,
expected
)
: '') +
'\n' +
(thrown !== null && thrown.hasMessage
? formatReceived('Received message: ', thrown, 'message') +
formatStack(thrown)
: formatReceived('Received value: ', thrown, 'value'))
: () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
(0, _print.printExpectedConstructorName)(
'Expected constructor',
expected
) +
(thrown === null
? `\n${DID_NOT_THROW}`
: `${
thrown.value != null &&
typeof thrown.value.constructor === 'function'
? (0, _print.printReceivedConstructorName)(
'Received constructor',
thrown.value.constructor
)
: ''
}\n${
thrown.hasMessage
? formatReceived('Received message: ', thrown, 'message') +
formatStack(thrown)
: formatReceived('Received value: ', thrown, 'value')
}`);
return {
message,
pass
};
};
const toThrowExpectedString = (matcherName, options, thrown, expected) => {
const pass = thrown !== null && thrown.message.includes(expected);
const message = pass
? () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
formatExpected('Expected substring: not ', expected) +
(thrown !== null && thrown.hasMessage
? formatReceived(
'Received message: ',
thrown,
'message',
expected
) + formatStack(thrown)
: formatReceived('Received value: ', thrown, 'value'))
: () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
undefined,
options
) +
'\n\n' +
formatExpected('Expected substring: ', expected) +
(thrown === null
? `\n${DID_NOT_THROW}`
: thrown.hasMessage
? formatReceived('Received message: ', thrown, 'message') +
formatStack(thrown)
: formatReceived('Received value: ', thrown, 'value'));
return {
message,
pass
};
};
const toThrow = (matcherName, options, thrown) => {
const pass = thrown !== null;
const message = pass
? () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
'',
options
) +
'\n\n' +
(thrown !== null && thrown.hasMessage
? formatReceived('Error name: ', thrown, 'name') +
formatReceived('Error message: ', thrown, 'message') +
formatStack(thrown)
: formatReceived('Thrown value: ', thrown, 'value'))
: () =>
// eslint-disable-next-line prefer-template
(0, _jestMatcherUtils.matcherHint)(
matcherName,
undefined,
'',
options
) +
'\n\n' +
DID_NOT_THROW;
return {
message,
pass
};
};
const formatExpected = (label, expected) =>
`${label + (0, _jestMatcherUtils.printExpected)(expected)}\n`;
const formatReceived = (label, thrown, key, expected) => {
if (thrown === null) {
return '';
}
if (key === 'message') {
const message = thrown.message;
if (typeof expected === 'string') {
const index = message.indexOf(expected);
if (index !== -1) {
return `${
label +
(0, _print.printReceivedStringContainExpectedSubstring)(
message,
index,
expected.length
)
}\n`;
}
} else if (expected instanceof RegExp) {
return `${
label +
(0, _print.printReceivedStringContainExpectedResult)(
message,
typeof expected.exec === 'function' ? expected.exec(message) : null
)
}\n`;
}
return `${label + (0, _jestMatcherUtils.printReceived)(message)}\n`;
}
if (key === 'name') {
return thrown.isError
? `${label + (0, _jestMatcherUtils.printReceived)(thrown.value.name)}\n`
: '';
}
if (key === 'value') {
return thrown.isError
? ''
: `${label + (0, _jestMatcherUtils.printReceived)(thrown.value)}\n`;
}
return '';
};
const formatStack = thrown =>
thrown === null || !thrown.isError
? ''
: (0, _jestMessageUtil.formatStackTrace)(
(0, _jestMessageUtil.separateMessageFromStack)(thrown.value.stack)
.stack,
{
rootDir: process.cwd(),
testMatch: []
},
{
noStackTrace: false
}
);
function createMessageAndCauseMessage(error) {
if (error.cause instanceof Error) {
return `{ message: ${error.message}, cause: ${createMessageAndCauseMessage(
error.cause
)}}`;
}
return `{ message: ${error.message} }`;
}
function createMessageAndCause(error) {
if (error.cause instanceof Error) {
return createMessageAndCauseMessage(error);
}
return error.message;
}
function messageAndCause(error) {
return error.cause === undefined ? 'message' : 'message and cause';
}
var _default = matchers;
exports.default = _default;

3
node_modules/expect/build/types.js generated vendored
View File

@@ -1,3 +0,0 @@
'use strict';
var _jestMatchersObject = require('./jestMatchersObject');