graphql-data-generator 0.3.0-alpha.24 → 0.3.0-alpha.26
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/esm/jest.js +18 -4
- package/package.json +6 -2
- package/script/jest.js +20 -5
- package/types/jest.d.ts +9 -0
package/esm/jest.js
CHANGED
|
@@ -6,15 +6,30 @@ import { MockedProvider as ApolloMockedProvider, MockLink, } from "@apollo/clien
|
|
|
6
6
|
import { waitFor } from "@testing-library/dom";
|
|
7
7
|
import { Kind, print } from "graphql";
|
|
8
8
|
import { diff as jestDiff } from "jest-diff";
|
|
9
|
+
import "@testing-library/react/dont-cleanup-after-each";
|
|
10
|
+
import { cleanup } from "@testing-library/react";
|
|
9
11
|
let currentSpecResult;
|
|
10
12
|
jasmine.getEnv().addReporter({
|
|
11
13
|
specStarted: (result) => currentSpecResult = result,
|
|
12
14
|
});
|
|
15
|
+
let _skipCleanupAfterEach = false;
|
|
16
|
+
/**
|
|
17
|
+
* `@testing-library/react` automatically unmounts React trees that were mounted
|
|
18
|
+
* with render after each test, which `graphql-data-generator` hijacks to ensure
|
|
19
|
+
* cleanup is done after all mocks are consumed. Invoke this functions to
|
|
20
|
+
* disable automatic cleanup.
|
|
21
|
+
* @param value
|
|
22
|
+
*/
|
|
23
|
+
export const skipCleanupAfterEach = (value = false) => {
|
|
24
|
+
_skipCleanupAfterEach = value;
|
|
25
|
+
};
|
|
13
26
|
const afterTest = [];
|
|
14
27
|
afterEach(async () => {
|
|
15
28
|
const hooks = afterTest.splice(0);
|
|
16
29
|
for (const hook of hooks)
|
|
17
30
|
await hook();
|
|
31
|
+
if (!_skipCleanupAfterEach)
|
|
32
|
+
cleanup();
|
|
18
33
|
});
|
|
19
34
|
const diff = (a, b) => jestDiff(a, b, { omitAnnotationLines: true })
|
|
20
35
|
?.replace(/\w+ \{/g, "{") // Remove class names
|
|
@@ -201,14 +216,13 @@ export const MockedProvider = ({ mocks, stack: renderStack, children, link: pass
|
|
|
201
216
|
if (_failRefetchWarnings) {
|
|
202
217
|
const oldWarn = console.warn.bind(console.warn);
|
|
203
218
|
console.warn = (message, operation, ...etc) => {
|
|
204
|
-
if (message !==
|
|
205
|
-
|
|
219
|
+
if (typeof message !== "string" ||
|
|
220
|
+
!message.match(/Unknown query named.*refetchQueries/))
|
|
206
221
|
return oldWarn(message, operation, ...etc);
|
|
207
|
-
}
|
|
208
222
|
try {
|
|
209
223
|
fail({
|
|
210
224
|
name: "Error",
|
|
211
|
-
message: `Expected query ${operation} requested in refetchQueries options.include array to have
|
|
225
|
+
message: `Expected query ${operation} requested in refetchQueries options.include array to have been mocked`,
|
|
212
226
|
stack: renderStack,
|
|
213
227
|
});
|
|
214
228
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphql-data-generator",
|
|
3
|
-
"version": "0.3.0-alpha.
|
|
3
|
+
"version": "0.3.0-alpha.26",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voces/graphql-data-generator.git"
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"react": "*",
|
|
62
62
|
"@types/react": "*",
|
|
63
63
|
"@apollo/client": "*",
|
|
64
|
-
"@testing-library/dom": "*"
|
|
64
|
+
"@testing-library/dom": "*",
|
|
65
|
+
"@testing-library/react": "*"
|
|
65
66
|
},
|
|
66
67
|
"peerDependenciesMeta": {
|
|
67
68
|
"react": {
|
|
@@ -75,6 +76,9 @@
|
|
|
75
76
|
},
|
|
76
77
|
"@testing-library/dom": {
|
|
77
78
|
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"@testing-library/react": {
|
|
81
|
+
"optional": true
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
}
|
package/script/jest.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.MockedProvider = exports.waitForMocks = exports.allowMissingMocks = exports.failRefetchWarnings = void 0;
|
|
26
|
+
exports.MockedProvider = exports.waitForMocks = exports.allowMissingMocks = exports.failRefetchWarnings = exports.skipCleanupAfterEach = void 0;
|
|
27
27
|
const dntShim = __importStar(require("./_dnt.shims.js"));
|
|
28
28
|
const react_1 = __importStar(require("react"));
|
|
29
29
|
const client_1 = require("@apollo/client");
|
|
@@ -32,15 +32,31 @@ const testing_1 = require("@apollo/client/testing");
|
|
|
32
32
|
const dom_1 = require("@testing-library/dom");
|
|
33
33
|
const graphql_1 = require("graphql");
|
|
34
34
|
const jest_diff_1 = require("jest-diff");
|
|
35
|
+
require("@testing-library/react/dont-cleanup-after-each");
|
|
36
|
+
const react_2 = require("@testing-library/react");
|
|
35
37
|
let currentSpecResult;
|
|
36
38
|
jasmine.getEnv().addReporter({
|
|
37
39
|
specStarted: (result) => currentSpecResult = result,
|
|
38
40
|
});
|
|
41
|
+
let _skipCleanupAfterEach = false;
|
|
42
|
+
/**
|
|
43
|
+
* `@testing-library/react` automatically unmounts React trees that were mounted
|
|
44
|
+
* with render after each test, which `graphql-data-generator` hijacks to ensure
|
|
45
|
+
* cleanup is done after all mocks are consumed. Invoke this functions to
|
|
46
|
+
* disable automatic cleanup.
|
|
47
|
+
* @param value
|
|
48
|
+
*/
|
|
49
|
+
const skipCleanupAfterEach = (value = false) => {
|
|
50
|
+
_skipCleanupAfterEach = value;
|
|
51
|
+
};
|
|
52
|
+
exports.skipCleanupAfterEach = skipCleanupAfterEach;
|
|
39
53
|
const afterTest = [];
|
|
40
54
|
afterEach(async () => {
|
|
41
55
|
const hooks = afterTest.splice(0);
|
|
42
56
|
for (const hook of hooks)
|
|
43
57
|
await hook();
|
|
58
|
+
if (!_skipCleanupAfterEach)
|
|
59
|
+
(0, react_2.cleanup)();
|
|
44
60
|
});
|
|
45
61
|
const diff = (a, b) => (0, jest_diff_1.diff)(a, b, { omitAnnotationLines: true })
|
|
46
62
|
?.replace(/\w+ \{/g, "{") // Remove class names
|
|
@@ -230,14 +246,13 @@ const MockedProvider = ({ mocks, stack: renderStack, children, link: passedLink,
|
|
|
230
246
|
if (_failRefetchWarnings) {
|
|
231
247
|
const oldWarn = console.warn.bind(console.warn);
|
|
232
248
|
console.warn = (message, operation, ...etc) => {
|
|
233
|
-
if (message !==
|
|
234
|
-
|
|
249
|
+
if (typeof message !== "string" ||
|
|
250
|
+
!message.match(/Unknown query named.*refetchQueries/))
|
|
235
251
|
return oldWarn(message, operation, ...etc);
|
|
236
|
-
}
|
|
237
252
|
try {
|
|
238
253
|
fail({
|
|
239
254
|
name: "Error",
|
|
240
|
-
message: `Expected query ${operation} requested in refetchQueries options.include array to have
|
|
255
|
+
message: `Expected query ${operation} requested in refetchQueries options.include array to have been mocked`,
|
|
241
256
|
stack: renderStack,
|
|
242
257
|
});
|
|
243
258
|
}
|
package/types/jest.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { MockedProviderProps, MockedResponse } from "@apollo/client/testing";
|
|
3
|
+
import "@testing-library/react/dont-cleanup-after-each";
|
|
3
4
|
type ExtendedMockedResponse = MockedResponse & {
|
|
4
5
|
stack?: string;
|
|
5
6
|
watch?: boolean;
|
|
6
7
|
optional?: boolean;
|
|
7
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* `@testing-library/react` automatically unmounts React trees that were mounted
|
|
11
|
+
* with render after each test, which `graphql-data-generator` hijacks to ensure
|
|
12
|
+
* cleanup is done after all mocks are consumed. Invoke this functions to
|
|
13
|
+
* disable automatic cleanup.
|
|
14
|
+
* @param value
|
|
15
|
+
*/
|
|
16
|
+
export declare const skipCleanupAfterEach: (value?: boolean) => void;
|
|
8
17
|
/**
|
|
9
18
|
* In older versions of `@apollo/client`, refetches with missing mocks trigger
|
|
10
19
|
* warnings instead of being treated as standard missing mocks.
|