@fgv/ts-utils-jest 5.0.0-22 → 5.0.0-24
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/CHANGELOG.json +0 -15
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +8 -8
- package/.vscode/launch.json +0 -16
- package/dist/ts-utils-jest.d.ts +0 -66
- package/lib/helpers/fsHelpers.test.d.ts +0 -2
- package/lib/index.test.d.ts +0 -2
- package/lib/matchers/toFail/index.test.d.ts +0 -2
- package/lib/matchers/toFail/predicate.test.d.ts +0 -2
- package/lib/matchers/toFailTest/index.test.d.ts +0 -2
- package/lib/matchers/toFailTest/predicate.test.d.ts +0 -2
- package/lib/matchers/toFailTestAndMatchSnapshot/index.test.d.ts +0 -2
- package/lib/matchers/toFailTestAndMatchSnapshot/predicate.test.d.ts +0 -2
- package/lib/matchers/toFailTestWith/index.test.d.ts +0 -2
- package/lib/matchers/toFailTestWith/predicate.test.d.ts +0 -2
- package/lib/matchers/toFailWith/index.test.d.ts +0 -2
- package/lib/matchers/toFailWith/predicate.test.d.ts +0 -2
- package/lib/matchers/toFailWithDetail/index.test.d.ts +0 -2
- package/lib/matchers/toFailWithDetail/predicate.test.d.ts +0 -2
- package/lib/matchers/toHaveBeenCalledWithArgumentsMatching/index.test.d.ts +0 -2
- package/lib/matchers/toHaveBeenCalledWithArgumentsMatching/predicate.test.d.ts +0 -2
- package/lib/matchers/toSucceed/index.test.d.ts +0 -2
- package/lib/matchers/toSucceed/predicate.test.d.ts +0 -2
- package/lib/matchers/toSucceedAndMatchInlineSnapshot/index.test.d.ts +0 -2
- package/lib/matchers/toSucceedAndMatchSnapshot/index.test.d.ts +0 -2
- package/lib/matchers/toSucceedAndSatisfy/index.test.d.ts +0 -2
- package/lib/matchers/toSucceedAndSatisfy/predicate.test.d.ts +0 -2
- package/lib/matchers/toSucceedWith/index.test.d.ts +0 -2
- package/lib/matchers/toSucceedWith/predicate.test.d.ts +0 -2
- package/lib/matchers/toSucceedWithDetail/index.test.d.ts +0 -2
- package/lib/matchers/toSucceedWithDetail/predicate.test.d.ts +0 -2
- package/lib/resolvers/resolvers.test.d.ts +0 -2
- package/src/__snapshots__/index.test.ts.snap +0 -24
- package/src/helpers/fsHelpers.ts +0 -184
- package/src/helpers/index.ts +0 -1
- package/src/index.ts +0 -27
- package/src/matchers/index.ts +0 -29
- package/src/matchers/toFail/__snapshots__/index.test.ts.snap +0 -17
- package/src/matchers/toFail/index.ts +0 -45
- package/src/matchers/toFail/predicate.ts +0 -7
- package/src/matchers/toFailTest/__snapshots__/index.test.ts.snap +0 -15
- package/src/matchers/toFailTest/index.ts +0 -48
- package/src/matchers/toFailTest/predicate.ts +0 -8
- package/src/matchers/toFailTestAndMatchSnapshot/__snapshots__/index.test.ts.snap +0 -14
- package/src/matchers/toFailTestAndMatchSnapshot/index.ts +0 -48
- package/src/matchers/toFailTestAndMatchSnapshot/predicate.ts +0 -12
- package/src/matchers/toFailTestWith/__snapshots__/index.test.ts.snap +0 -34
- package/src/matchers/toFailTestWith/index.ts +0 -56
- package/src/matchers/toFailTestWith/predicate.ts +0 -24
- package/src/matchers/toFailWith/__snapshots__/index.test.ts.snap +0 -25
- package/src/matchers/toFailWith/index.ts +0 -52
- package/src/matchers/toFailWith/predicate.ts +0 -16
- package/src/matchers/toFailWithDetail/__snapshots__/index.test.ts.snap +0 -41
- package/src/matchers/toFailWithDetail/index.ts +0 -63
- package/src/matchers/toFailWithDetail/predicate.ts +0 -27
- package/src/matchers/toHaveBeenCalledWithArgumentsMatching/__snapshots__/index.test.ts.snap +0 -82
- package/src/matchers/toHaveBeenCalledWithArgumentsMatching/index.ts +0 -100
- package/src/matchers/toHaveBeenCalledWithArgumentsMatching/predicate.ts +0 -18
- package/src/matchers/toSucceed/__snapshots__/index.test.ts.snap +0 -17
- package/src/matchers/toSucceed/index.ts +0 -45
- package/src/matchers/toSucceed/predicate.ts +0 -7
- package/src/matchers/toSucceedAndMatchInlineSnapshot/__snapshots__/index.test.ts.snap +0 -15
- package/src/matchers/toSucceedAndMatchInlineSnapshot/index.ts +0 -44
- package/src/matchers/toSucceedAndMatchSnapshot/__snapshots__/index.test.ts.snap +0 -27
- package/src/matchers/toSucceedAndMatchSnapshot/index.ts +0 -47
- package/src/matchers/toSucceedAndSatisfy/__snapshots__/index.test.ts.snap +0 -37
- package/src/matchers/toSucceedAndSatisfy/index.ts +0 -78
- package/src/matchers/toSucceedAndSatisfy/predicate.ts +0 -22
- package/src/matchers/toSucceedWith/__snapshots__/index.test.ts.snap +0 -25
- package/src/matchers/toSucceedWith/index.ts +0 -58
- package/src/matchers/toSucceedWith/predicate.ts +0 -14
- package/src/matchers/toSucceedWithDetail/__snapshots__/index.test.ts.snap +0 -41
- package/src/matchers/toSucceedWithDetail/index.ts +0 -62
- package/src/matchers/toSucceedWithDetail/predicate.ts +0 -23
- package/src/resolvers/cli.ts +0 -21
- package/src/resolvers/ide.ts +0 -21
- package/src/ts-utils.ts +0 -1
- package/src/types/index.ts +0 -107
- package/src/utils/colorHelpers.ts +0 -82
- package/src/utils/matcherHelpers.ts +0 -64
- package/src/utils/snapshotResolver.ts +0 -28
package/src/types/index.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest"/>
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any
|
|
4
|
-
export type Function = (...args: any[]) => any;
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
|
|
7
|
-
import { ResultDetailType, ResultValueType } from '@fgv/ts-utils';
|
|
8
|
-
|
|
9
|
-
/* eslint-disable @typescript-eslint/no-unused-vars,no-unused-vars */
|
|
10
|
-
declare global {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
12
|
-
namespace jest {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
14
|
-
interface Matchers<R, T> {
|
|
15
|
-
/**
|
|
16
|
-
* Use .toSucceed to verify that a Result\<T\> is a success
|
|
17
|
-
*/
|
|
18
|
-
toSucceed(): R;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Use .toSucceedWith to verify that a Result\<T\> is a success
|
|
22
|
-
* and that the result value matches the supplied value
|
|
23
|
-
* @param expected -
|
|
24
|
-
*/
|
|
25
|
-
toSucceedWith(expected: ResultValueType<T> | RegExp): R;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Use .toSucceedWithDetail to verify that a DetailedResult\<T, TD\> is
|
|
29
|
-
* a success and that the result value and detail matches the supplied
|
|
30
|
-
* values
|
|
31
|
-
* @param expected -
|
|
32
|
-
* @param detail -
|
|
33
|
-
*/
|
|
34
|
-
toSucceedWithDetail(expected: ResultValueType<T>, detail: ResultDetailType<T> | undefined): R;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Use .toSucceedAndSatisfy to verify that a Result\<T\> is a success
|
|
38
|
-
* and that the supplied test function returns true (or void)
|
|
39
|
-
* for the resulting value
|
|
40
|
-
* @param test -
|
|
41
|
-
*/
|
|
42
|
-
toSucceedAndSatisfy(test: (value: ResultValueType<T>) => boolean | void): R;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Use .toSucceedAndMatchInlineSnapshot to verify that a Result\<T\> is a success
|
|
46
|
-
* and that the result value matches an inline snapshot
|
|
47
|
-
*/
|
|
48
|
-
toSucceedAndMatchInlineSnapshot(snapshot: string | undefined): R;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Use .toSucceedAndMatchSnapshot to verify that a Result\<T\> is a success
|
|
52
|
-
* and that the result value matches a stored snapshot
|
|
53
|
-
*/
|
|
54
|
-
toSucceedAndMatchSnapshot(): R;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Use .toFail to verify that a Result\<T\> is a failure
|
|
58
|
-
*/
|
|
59
|
-
toFail(): R;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Use .toFailWith to verify that a Result\<T\> is a failure
|
|
63
|
-
* that matches a supplied string, RegExp or undefined value
|
|
64
|
-
* @param message -
|
|
65
|
-
*/
|
|
66
|
-
toFailWith(expected: string | RegExp | undefined): R;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Use .toFailWithDetail to verify that a DetailedResult\<T\> is
|
|
70
|
-
* a failure that matches both a supplied expected failure value
|
|
71
|
-
* (string, RegExp or undefined) and a supplied failure detail.
|
|
72
|
-
* @param message -
|
|
73
|
-
* @param detail -
|
|
74
|
-
*/
|
|
75
|
-
toFailWithDetail<TDetail>(message: string | RegExp, detail: TDetail): R;
|
|
76
|
-
toFailWithDetail(message: string | RegExp | undefined, detail: ResultDetailType<T>): R;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Use .toFailTest to test a custom matcher by
|
|
80
|
-
* verifying that a test case fails.
|
|
81
|
-
*/
|
|
82
|
-
toFailTest(): R;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Use .toFailTestWith to test a custom matcher by
|
|
86
|
-
* verifying that a test case fails as expected and
|
|
87
|
-
* reports an error matching a stored snapshot.
|
|
88
|
-
*/
|
|
89
|
-
toFailTestAndMatchSnapshot(): R;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Use .toFailTestWith to test a custom matcher by
|
|
93
|
-
* verifying that a test case fails as expected and
|
|
94
|
-
* reports an error matching a supplied value.
|
|
95
|
-
* @param expected -
|
|
96
|
-
*/
|
|
97
|
-
toFailTestWith(expected: string | string[] | RegExp): R;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Use .toSucceedWith to verify that a Result\<T\> is a success
|
|
101
|
-
* and that the result value matches the supplied value
|
|
102
|
-
* @param expected -
|
|
103
|
-
*/
|
|
104
|
-
toHaveBeenCalledWithArgumentsMatching(expected: unknown): R;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for handling ANSI color codes in test output.
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Regular expression to match ANSI color/style escape sequences.
|
|
9
|
-
*
|
|
10
|
-
* This matches:
|
|
11
|
-
* - ESC character (ASCII 27) followed by `[`
|
|
12
|
-
* - `[0-9;]*` - Zero or more digits and semicolons (parameters)
|
|
13
|
-
* - `[a-zA-Z]` - Single letter command (m for SGR, K for erase, etc.)
|
|
14
|
-
*
|
|
15
|
-
* Examples of what this matches:
|
|
16
|
-
* - `\u001b[31m` - Red foreground
|
|
17
|
-
* - `\u001b[39m` - Default foreground
|
|
18
|
-
* - `\u001b[2m` - Dim/faint
|
|
19
|
-
* - `\u001b[22m` - Normal intensity
|
|
20
|
-
*
|
|
21
|
-
* Using a pre-compiled regex literal to satisfy ESLint security requirements.
|
|
22
|
-
* We use the unicode escape sequence \\u001b instead of \\x1b to avoid control-regex warnings.
|
|
23
|
-
*/
|
|
24
|
-
// eslint-disable-next-line @rushstack/security/no-unsafe-regexp, no-control-regex
|
|
25
|
-
const ANSI_COLOR_REGEX: RegExp = /\u001b\[[0-9;]*[a-zA-Z]/g;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Strips ANSI color/style escape sequences from a string.
|
|
29
|
-
*
|
|
30
|
-
* This function removes all ANSI escape sequences commonly used for
|
|
31
|
-
* terminal colors and text styling, making the output suitable for
|
|
32
|
-
* color-agnostic snapshot testing.
|
|
33
|
-
*
|
|
34
|
-
* @param text - The text that may contain ANSI escape sequences
|
|
35
|
-
* @returns The text with all ANSI escape sequences removed
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const coloredText = '\u001b[31mError:\u001b[39m Something failed';
|
|
40
|
-
* const plainText = stripAnsiColors(coloredText);
|
|
41
|
-
* console.log(plainText); // "Error: Something failed"
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* // Common usage in Jest matchers
|
|
47
|
-
* const formattedOutput = matcherUtils.printReceived(value);
|
|
48
|
-
* const cleanOutput = stripAnsiColors(formattedOutput);
|
|
49
|
-
* expect(cleanOutput).toMatchSnapshot();
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
export function stripAnsiColors(text: string): string {
|
|
55
|
-
return text.replace(ANSI_COLOR_REGEX, '');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Creates a wrapper function that strips ANSI colors from any string-returning function.
|
|
60
|
-
*
|
|
61
|
-
* This is useful for wrapping Jest matcher utility functions to make them
|
|
62
|
-
* color-agnostic for snapshot testing.
|
|
63
|
-
*
|
|
64
|
-
* @param fn - A function that returns a string (potentially with ANSI colors)
|
|
65
|
-
* @returns A wrapped function that returns the same string with colors stripped
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* import { printReceived } from 'jest-matcher-utils';
|
|
70
|
-
*
|
|
71
|
-
* const printReceivedClean = createColorStripWrapper(printReceived);
|
|
72
|
-
* const output = printReceivedClean(someValue); // No colors
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
export function createColorStripWrapper<T extends (...args: unknown[]) => string>(fn: T): T {
|
|
78
|
-
return ((...args: Parameters<T>) => {
|
|
79
|
-
const result = fn(...args);
|
|
80
|
-
return stripAnsiColors(result);
|
|
81
|
-
}) as T;
|
|
82
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { printExpected, printReceived } from 'jest-matcher-utils';
|
|
2
|
-
import { DetailedResult, Result } from '../ts-utils';
|
|
3
|
-
import { createColorStripWrapper } from './colorHelpers';
|
|
4
|
-
|
|
5
|
-
// Create color-stripped versions of Jest matcher utilities
|
|
6
|
-
const printExpectedClean: typeof printExpected = createColorStripWrapper(printExpected);
|
|
7
|
-
const printReceivedClean: typeof printReceived = createColorStripWrapper(printReceived);
|
|
8
|
-
|
|
9
|
-
function printExpectedValue<T>(outcome: string, expected?: T): string {
|
|
10
|
-
return expected !== undefined ? ` ${outcome} with ${printExpectedClean(expected)}` : ` ${outcome}`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function printExpectedResult<T>(expect: 'success' | 'failure', isNot: boolean, expected?: T): string {
|
|
14
|
-
return [
|
|
15
|
-
'Expected:',
|
|
16
|
-
isNot
|
|
17
|
-
? expect === 'success'
|
|
18
|
-
? printExpectedValue('Success', expected)
|
|
19
|
-
: printExpectedValue('Failure', expected)
|
|
20
|
-
: expect === 'success'
|
|
21
|
-
? printExpectedValue('Not success', expected)
|
|
22
|
-
: printExpectedValue('Not failure', expected)
|
|
23
|
-
].join('\n');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function printExpectedDetailedResult<T, TD>(
|
|
27
|
-
expect: 'success' | 'failure',
|
|
28
|
-
isNot: boolean,
|
|
29
|
-
expectedMessage?: T,
|
|
30
|
-
expectedDetail?: TD
|
|
31
|
-
): string {
|
|
32
|
-
/* c8 ignore next */
|
|
33
|
-
return [
|
|
34
|
-
'Expected:',
|
|
35
|
-
isNot
|
|
36
|
-
? expect === 'success'
|
|
37
|
-
? printExpectedValue('Success', expectedMessage)
|
|
38
|
-
: printExpectedValue('Failure', expectedMessage)
|
|
39
|
-
: expect === 'success'
|
|
40
|
-
? printExpectedValue('Not success', expectedMessage)
|
|
41
|
-
: printExpectedValue('Not failure', expectedMessage),
|
|
42
|
-
` Detail: "${printExpectedClean(expectedDetail)}"`
|
|
43
|
-
].join('\n');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function printReceivedResult<T>(received: Result<T>): string {
|
|
47
|
-
return [
|
|
48
|
-
'Received:',
|
|
49
|
-
received.isSuccess()
|
|
50
|
-
? ` Success with ${printReceivedClean(received.value)}`
|
|
51
|
-
: ` Failure with "${received.message}"`
|
|
52
|
-
].join('\n');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function printReceivedDetailedResult<T, TD>(received: DetailedResult<T, TD>): string {
|
|
56
|
-
return [
|
|
57
|
-
'Received:',
|
|
58
|
-
received.isSuccess()
|
|
59
|
-
? ` Success with "${printReceivedClean(received.value)}"\n Detail: "${printReceivedClean(
|
|
60
|
-
received.detail
|
|
61
|
-
)}"`
|
|
62
|
-
: ` Failure with "${received.message}"\n Detail: "${printReceivedClean(received.detail)}"`
|
|
63
|
-
].join('\n');
|
|
64
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
export function resolveSnapshotPath(
|
|
4
|
-
testPath: string,
|
|
5
|
-
snapshotExtension: string,
|
|
6
|
-
snapshotFolderName: string
|
|
7
|
-
): string {
|
|
8
|
-
const snapshotPath = path.join(
|
|
9
|
-
path.join(path.dirname(testPath), '__snapshots__', snapshotFolderName),
|
|
10
|
-
path.basename(testPath) + snapshotExtension
|
|
11
|
-
);
|
|
12
|
-
return snapshotPath;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function resolveTestPath(snapshotFilePath: string, snapshotExtension: string): string {
|
|
16
|
-
const testPath = path.join(
|
|
17
|
-
path.dirname(path.dirname(path.dirname(snapshotFilePath))),
|
|
18
|
-
path.basename(snapshotFilePath, snapshotExtension)
|
|
19
|
-
);
|
|
20
|
-
return testPath;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const testPathForConsistencyCheck: string = path.posix.join(
|
|
24
|
-
'consistency_check',
|
|
25
|
-
'__tests__',
|
|
26
|
-
'subdir',
|
|
27
|
-
'example.test.js'
|
|
28
|
-
);
|