@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/CHANGELOG.json
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils-jest",
|
|
3
3
|
"entries": [
|
|
4
|
-
{
|
|
5
|
-
"version": "5.0.0",
|
|
6
|
-
"tag": "@fgv/ts-utils-jest_v5.0.0",
|
|
7
|
-
"date": "Thu, 17 Jul 2025 00:13:24 GMT",
|
|
8
|
-
"comments": {
|
|
9
|
-
"none": [
|
|
10
|
-
{
|
|
11
|
-
"comment": "minor fixes"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"comment": "bump version"
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
4
|
{
|
|
20
5
|
"version": "4.6.0",
|
|
21
6
|
"tag": "@fgv/ts-utils-jest_v4.6.0",
|
package/lib/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils-jest",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-24",
|
|
4
4
|
"description": "Custom matchers for ts-utils result class",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
"rimraf": "^5.0.7",
|
|
35
35
|
"ts-jest": "^29.4.1",
|
|
36
36
|
"ts-node": "^10.9.2",
|
|
37
|
-
"typescript": "
|
|
38
|
-
"@rushstack/heft": "
|
|
39
|
-
"@rushstack/eslint-config": "
|
|
40
|
-
"@rushstack/heft-jest-plugin": "
|
|
41
|
-
"@rushstack/heft-node-rig": "
|
|
37
|
+
"typescript": "5.8.3",
|
|
38
|
+
"@rushstack/heft": "0.74.3",
|
|
39
|
+
"@rushstack/eslint-config": "4.4.0",
|
|
40
|
+
"@rushstack/heft-jest-plugin": "0.16.12",
|
|
41
|
+
"@rushstack/heft-node-rig": "2.9.4",
|
|
42
42
|
"@types/heft-jest": "1.0.6",
|
|
43
43
|
"eslint-plugin-n": "^16.6.2",
|
|
44
44
|
"eslint-plugin-tsdoc": "~0.4.0",
|
|
45
|
-
"@fgv/ts-utils": "5.0.0-
|
|
45
|
+
"@fgv/ts-utils": "5.0.0-24"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@fgv/ts-utils": "5.0.0-
|
|
48
|
+
"@fgv/ts-utils": "5.0.0-24"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "heft build --clean",
|
package/.vscode/launch.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "Launch Program",
|
|
11
|
-
"skipFiles": ["<node_internals>/**"],
|
|
12
|
-
"program": "${workspaceFolder}/src/matchers/toHaveBeenCalledWithArgumentsMatching/index.test.ts",
|
|
13
|
-
"outFiles": ["${workspaceFolder}/**/*.js"]
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
}
|
package/dist/ts-utils-jest.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @public
|
|
3
|
-
*/
|
|
4
|
-
declare interface IMockFileConfig {
|
|
5
|
-
path: string;
|
|
6
|
-
backingFile?: string;
|
|
7
|
-
payload?: string;
|
|
8
|
-
writable?: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
declare interface IMockFileSystemOptions {
|
|
15
|
-
mockWriteOnly?: boolean;
|
|
16
|
-
allowUnknownMockWrite?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @public
|
|
21
|
-
*/
|
|
22
|
-
declare class MockFileSystem {
|
|
23
|
-
protected readonly _options?: IMockFileSystemOptions;
|
|
24
|
-
protected readonly _config: Map<string, IMockFileConfig>;
|
|
25
|
-
protected readonly _data: Map<string, string>;
|
|
26
|
-
protected readonly _realReadFileSync: ReadFunc;
|
|
27
|
-
protected readonly _extraWrites: string[];
|
|
28
|
-
constructor(configs: Iterable<IMockFileConfig>, options?: IMockFileSystemOptions);
|
|
29
|
-
readMockFileSync(wanted: string): string;
|
|
30
|
-
writeMockFileSync(wanted: string, body: string): void;
|
|
31
|
-
getExtraFilesWritten(): string[];
|
|
32
|
-
tryGetPayload(want: string): string | undefined;
|
|
33
|
-
reset(): void;
|
|
34
|
-
startSpies(): ReadWriteSpies;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
declare namespace MockFs {
|
|
38
|
-
export {
|
|
39
|
-
IMockFileConfig,
|
|
40
|
-
ReadWriteSpies,
|
|
41
|
-
IMockFileSystemOptions,
|
|
42
|
-
MockFileSystem
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export { MockFs }
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
declare type ReadFunc = (path: string | number | Buffer | URL, options?: {
|
|
51
|
-
encoding?: null;
|
|
52
|
-
flag?: string;
|
|
53
|
-
} | null) => Buffer;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
declare class ReadWriteSpies {
|
|
59
|
-
readonly read: jest.SpyInstance;
|
|
60
|
-
readonly write: jest.SpyInstance;
|
|
61
|
-
constructor(read: jest.SpyInstance, write: jest.SpyInstance);
|
|
62
|
-
clear(): void;
|
|
63
|
-
restore(): void;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { }
|
package/lib/index.test.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`verify matchers accessibility toFailTestAndMatchSnapshot exists and works: toFailTestAndMatchSnapshot 1`] = `
|
|
4
|
-
"expect(received).toBe(expected) // Object.is equality
|
|
5
|
-
|
|
6
|
-
Expected: false
|
|
7
|
-
Received: true"
|
|
8
|
-
`;
|
|
9
|
-
|
|
10
|
-
exports[`verify matchers accessibility toSucceedAndMatchSnapshot exists and works: toSucceedAndMatchSnapshot 1`] = `
|
|
11
|
-
Object {
|
|
12
|
-
"child": Object {
|
|
13
|
-
"values": Array [
|
|
14
|
-
Object {
|
|
15
|
-
"number": 1,
|
|
16
|
-
},
|
|
17
|
-
Object {
|
|
18
|
-
"number": 2,
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
"field": "field",
|
|
23
|
-
}
|
|
24
|
-
`;
|
package/src/helpers/fsHelpers.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import fs from 'fs';
|
|
24
|
-
import * as path from 'path';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
export interface IMockFileConfig {
|
|
30
|
-
path: string;
|
|
31
|
-
backingFile?: string;
|
|
32
|
-
payload?: string;
|
|
33
|
-
writable?: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
|
-
export class ReadWriteSpies {
|
|
40
|
-
public readonly read: jest.SpyInstance;
|
|
41
|
-
public readonly write: jest.SpyInstance;
|
|
42
|
-
|
|
43
|
-
public constructor(read: jest.SpyInstance, write: jest.SpyInstance) {
|
|
44
|
-
this.read = read;
|
|
45
|
-
this.write = write;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public clear(): void {
|
|
49
|
-
this.read.mockClear();
|
|
50
|
-
this.write.mockClear();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public restore(): void {
|
|
54
|
-
this.read.mockRestore();
|
|
55
|
-
this.write.mockRestore();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @public
|
|
61
|
-
*/
|
|
62
|
-
export interface IMockFileSystemOptions {
|
|
63
|
-
mockWriteOnly?: boolean;
|
|
64
|
-
allowUnknownMockWrite?: boolean;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @public
|
|
69
|
-
*/
|
|
70
|
-
// eslint-disable-next-line @rushstack/no-new-null
|
|
71
|
-
type ReadFunc = (
|
|
72
|
-
path: string | number | Buffer | URL,
|
|
73
|
-
// eslint-disable-next-line @rushstack/no-new-null
|
|
74
|
-
options?: { encoding?: null; flag?: string } | null
|
|
75
|
-
) => Buffer;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @public
|
|
79
|
-
*/
|
|
80
|
-
export class MockFileSystem {
|
|
81
|
-
protected readonly _options?: IMockFileSystemOptions;
|
|
82
|
-
protected readonly _config: Map<string, IMockFileConfig>;
|
|
83
|
-
protected readonly _data: Map<string, string>;
|
|
84
|
-
protected readonly _realReadFileSync: ReadFunc;
|
|
85
|
-
protected readonly _extraWrites: string[] = [];
|
|
86
|
-
|
|
87
|
-
public constructor(configs: Iterable<IMockFileConfig>, options?: IMockFileSystemOptions) {
|
|
88
|
-
this._config = new Map<string, IMockFileConfig>();
|
|
89
|
-
this._data = new Map<string, string>();
|
|
90
|
-
this._options = options;
|
|
91
|
-
this._realReadFileSync = fs.readFileSync;
|
|
92
|
-
|
|
93
|
-
for (const config of configs) {
|
|
94
|
-
const fullPath = path.resolve(config.path);
|
|
95
|
-
this._config.set(fullPath, config);
|
|
96
|
-
if (config.backingFile) {
|
|
97
|
-
this.readMockFileSync(fullPath);
|
|
98
|
-
} else if (config.payload) {
|
|
99
|
-
this._data.set(fullPath, config.payload);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public readMockFileSync(wanted: string): string {
|
|
105
|
-
const fullPathWanted = path.resolve(wanted);
|
|
106
|
-
if (!this._data.has(fullPathWanted)) {
|
|
107
|
-
const config = this._config.get(fullPathWanted);
|
|
108
|
-
if (config?.backingFile === undefined) {
|
|
109
|
-
if (this._options?.mockWriteOnly !== true) {
|
|
110
|
-
throw new Error(`Mock file not found: ${wanted}`);
|
|
111
|
-
}
|
|
112
|
-
const body = this._realReadFileSync(fullPathWanted).toString();
|
|
113
|
-
this._data.set(fullPathWanted, body);
|
|
114
|
-
} else {
|
|
115
|
-
const fullBackingPath = path.resolve(config.backingFile);
|
|
116
|
-
const body = this._realReadFileSync(fullBackingPath).toString();
|
|
117
|
-
this._data.set(fullPathWanted, body);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const payload = this._data.get(fullPathWanted);
|
|
122
|
-
// not actually reproducible right now
|
|
123
|
-
/* c8 ignore next 3 */
|
|
124
|
-
if (payload === undefined) {
|
|
125
|
-
throw new Error(`Mock file ${wanted} payload is undefined.`);
|
|
126
|
-
}
|
|
127
|
-
return payload;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public writeMockFileSync(wanted: string, body: string): void {
|
|
131
|
-
const fullPathWanted = path.resolve(wanted);
|
|
132
|
-
const config = this._config.get(fullPathWanted);
|
|
133
|
-
if (config === undefined) {
|
|
134
|
-
if (this._options?.allowUnknownMockWrite !== true) {
|
|
135
|
-
throw new Error(`Mock path not found: ${wanted}`);
|
|
136
|
-
}
|
|
137
|
-
this._extraWrites.push(fullPathWanted);
|
|
138
|
-
} else if (config.writable !== true) {
|
|
139
|
-
throw new Error(`Mock permission denied: ${wanted}`);
|
|
140
|
-
}
|
|
141
|
-
this._data.set(fullPathWanted, body);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
public getExtraFilesWritten(): string[] {
|
|
145
|
-
return Array.from(this._extraWrites);
|
|
146
|
-
}
|
|
147
|
-
public tryGetPayload(want: string): string | undefined {
|
|
148
|
-
return this._data.get(path.resolve(want));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public reset(): void {
|
|
152
|
-
const writable = Array.from(this._config.values()).filter((c) => c.writable === true);
|
|
153
|
-
for (const config of writable) {
|
|
154
|
-
this._data.delete(path.resolve(config.path));
|
|
155
|
-
if (config.backingFile) {
|
|
156
|
-
this.readMockFileSync(path.resolve(config.path));
|
|
157
|
-
} else if (config.payload) {
|
|
158
|
-
this._data.set(path.resolve(config.path), config.payload);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
for (const path of this._extraWrites) {
|
|
163
|
-
this._data.delete(path);
|
|
164
|
-
}
|
|
165
|
-
this._extraWrites.splice(0, this._extraWrites.length);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
public startSpies(): ReadWriteSpies {
|
|
169
|
-
return new ReadWriteSpies(
|
|
170
|
-
jest.spyOn(fs, 'readFileSync').mockImplementation((wanted: unknown) => {
|
|
171
|
-
if (typeof wanted !== 'string') {
|
|
172
|
-
throw new Error('readFileSync mock supports only string parameters');
|
|
173
|
-
}
|
|
174
|
-
return this.readMockFileSync(wanted);
|
|
175
|
-
}),
|
|
176
|
-
jest.spyOn(fs, 'writeFileSync').mockImplementation((wanted: unknown, payload: unknown) => {
|
|
177
|
-
if (typeof wanted !== 'string' || typeof payload !== 'string') {
|
|
178
|
-
throw new Error('writeFileSync mock supports only string parameters');
|
|
179
|
-
}
|
|
180
|
-
return this.writeMockFileSync(wanted, payload);
|
|
181
|
-
})
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
package/src/helpers/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './fsHelpers';
|
package/src/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import matchers from './matchers';
|
|
2
|
-
import './types';
|
|
3
|
-
|
|
4
|
-
import * as MockFs from './helpers/fsHelpers';
|
|
5
|
-
export { MockFs };
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line no-undef
|
|
8
|
-
type JestGlobal = typeof global & { expect: jest.Expect };
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line no-undef
|
|
11
|
-
function isJestGlobal(g: typeof global): g is JestGlobal {
|
|
12
|
-
return g.hasOwnProperty('expect');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/* c8 ignore else */
|
|
16
|
-
if (isJestGlobal(global)) {
|
|
17
|
-
global.expect.extend(matchers);
|
|
18
|
-
} else {
|
|
19
|
-
/* eslint-disable no-console */
|
|
20
|
-
console.error(
|
|
21
|
-
[
|
|
22
|
-
"Unable to find Jest's global expect",
|
|
23
|
-
'Please check that you have added ts-utils-jest correctly to your jest configuration.'
|
|
24
|
-
].join('\n')
|
|
25
|
-
);
|
|
26
|
-
/* eslint-enable no-console */
|
|
27
|
-
}
|
package/src/matchers/index.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import ToFail from './toFail';
|
|
2
|
-
import ToFailTest from './toFailTest';
|
|
3
|
-
import ToFailTestAndMatchSnapshot from './toFailTestAndMatchSnapshot';
|
|
4
|
-
import ToFailTestWith from './toFailTestWith';
|
|
5
|
-
import ToFailWith from './toFailWith';
|
|
6
|
-
import ToFailWithDetail from './toFailWithDetail';
|
|
7
|
-
import ToHaveBeenCalledWithArgumentsMatching from './toHaveBeenCalledWithArgumentsMatching';
|
|
8
|
-
import ToSucceed from './toSucceed';
|
|
9
|
-
import ToSucceedAndMatchInlineSnapshot from './toSucceedAndMatchInlineSnapshot';
|
|
10
|
-
import ToSucceedAndMatchSnapshot from './toSucceedAndMatchSnapshot';
|
|
11
|
-
import ToSucceedAndSatisfy from './toSucceedAndSatisfy';
|
|
12
|
-
import ToSucceedWith from './toSucceedWith';
|
|
13
|
-
import toSucceedWithDetail from './toSucceedWithDetail';
|
|
14
|
-
|
|
15
|
-
export default {
|
|
16
|
-
...ToFail,
|
|
17
|
-
...ToFailTest,
|
|
18
|
-
...ToFailTestAndMatchSnapshot,
|
|
19
|
-
...ToFailTestWith,
|
|
20
|
-
...ToFailWith,
|
|
21
|
-
...ToFailWithDetail,
|
|
22
|
-
...ToHaveBeenCalledWithArgumentsMatching,
|
|
23
|
-
...ToSucceed,
|
|
24
|
-
...ToSucceedAndMatchInlineSnapshot,
|
|
25
|
-
...ToSucceedAndMatchSnapshot,
|
|
26
|
-
...ToSucceedAndSatisfy,
|
|
27
|
-
...ToSucceedWith,
|
|
28
|
-
...toSucceedWithDetail
|
|
29
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`.toFail reports details for a failed test with .not: toFailTestAndMatchSnapshot 1`] = `
|
|
4
|
-
"expect(received).not.toFail(expected)
|
|
5
|
-
Expected:
|
|
6
|
-
Not failure
|
|
7
|
-
Received:
|
|
8
|
-
Failure with \\"oops\\""
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
exports[`.toFail reports details for a failed test: toFailTestAndMatchSnapshot 1`] = `
|
|
12
|
-
"expect(received).toFail(expected)
|
|
13
|
-
Expected:
|
|
14
|
-
Failure
|
|
15
|
-
Received:
|
|
16
|
-
Success with \\"hello\\""
|
|
17
|
-
`;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { printExpectedResult, printReceivedResult } from '../../utils/matcherHelpers';
|
|
2
|
-
import { matcherName, predicate } from './predicate';
|
|
3
|
-
|
|
4
|
-
import { Result } from '@fgv/ts-utils';
|
|
5
|
-
import { matcherHint } from 'jest-matcher-utils';
|
|
6
|
-
|
|
7
|
-
declare global {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
-
namespace jest {
|
|
10
|
-
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars, @typescript-eslint/naming-convention
|
|
11
|
-
interface Matchers<R, T> {
|
|
12
|
-
/**
|
|
13
|
-
* Use .toFail to verify that a Result<T> is a failure
|
|
14
|
-
*/
|
|
15
|
-
toFail(): R;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function passMessage<T extends Result<unknown>>(received: T): () => string {
|
|
21
|
-
return () =>
|
|
22
|
-
[
|
|
23
|
-
matcherHint(`.not.${matcherName}`),
|
|
24
|
-
printExpectedResult('failure', false),
|
|
25
|
-
printReceivedResult(received)
|
|
26
|
-
].join('\n');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function failMessage<T extends Result<unknown>>(received: T): () => string {
|
|
30
|
-
return () =>
|
|
31
|
-
[matcherHint(`${matcherName}`), printExpectedResult('failure', true), printReceivedResult(received)].join(
|
|
32
|
-
'\n'
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default {
|
|
37
|
-
toFail: function <T extends Result<unknown>>(received: T): jest.CustomMatcherResult {
|
|
38
|
-
const pass = predicate(received);
|
|
39
|
-
if (pass) {
|
|
40
|
-
return { pass: true, message: passMessage(received) };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return { pass: false, message: failMessage(received) };
|
|
44
|
-
}
|
|
45
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`.toFailTest logs details correctly for a failed .not result: toFailTestAndMatchSnapshot 1`] = `
|
|
4
|
-
"expect(callback).not.toFailTest(expected)
|
|
5
|
-
Expected:
|
|
6
|
-
Not failure
|
|
7
|
-
Received: Test failed"
|
|
8
|
-
`;
|
|
9
|
-
|
|
10
|
-
exports[`.toFailTest logs details correctly for a failed result: toFailTestAndMatchSnapshot 1`] = `
|
|
11
|
-
"expect(callback).toFailTest(expected)
|
|
12
|
-
Expected:
|
|
13
|
-
Failure
|
|
14
|
-
Received: Test passed"
|
|
15
|
-
`;
|