relay-test-utils-internal 20.1.0 → 21.0.0
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/consoleErrorsAndWarnings.js.flow +1 -1
- package/describeWithFeatureFlags.js.flow +4 -4
- package/generateTestsFromFixtures.js.flow +3 -3
- package/getOutputForFixture.js.flow +4 -4
- package/index.js +1 -1
- package/lib/generateTestsFromFixtures.js +12 -6
- package/lib/getOutputForFixture.js +19 -12
- package/lib/testschema.graphql +58 -9
- package/package.json +2 -2
- package/printAST.js.flow +4 -2
- package/simpleClone.js.flow +3 -3
- package/trackRetentionForEnvironment.js.flow +3 -3
|
@@ -18,7 +18,7 @@ export type WillFireOptions = {
|
|
|
18
18
|
optional?: boolean,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
type API =
|
|
21
|
+
type API = Readonly<{
|
|
22
22
|
disallowMessages: () => void,
|
|
23
23
|
expectMessageWillFire: (string, void | WillFireOptions) => void,
|
|
24
24
|
expectMessage: <T>(string, () => T) => T,
|
|
@@ -27,20 +27,20 @@ type JestDoneFn = {
|
|
|
27
27
|
...
|
|
28
28
|
};
|
|
29
29
|
declare function afterEach(
|
|
30
|
-
fn: (done: JestDoneFn) => ?Promise<
|
|
30
|
+
fn: (done: JestDoneFn) => ?Promise<unknown>,
|
|
31
31
|
timeout?: number,
|
|
32
32
|
): void;
|
|
33
33
|
declare function beforeEach(
|
|
34
|
-
fn: (done: JestDoneFn) => ?Promise<
|
|
34
|
+
fn: (done: JestDoneFn) => ?Promise<unknown>,
|
|
35
35
|
timeout?: number,
|
|
36
36
|
): void;
|
|
37
37
|
declare var describe: {
|
|
38
38
|
(name: JestTestName, fn: () => void): void,
|
|
39
39
|
each(
|
|
40
|
-
...table:
|
|
40
|
+
...table: ReadonlyArray<Array<unknown> | unknown> | [Array<string>, string]
|
|
41
41
|
): (
|
|
42
42
|
name: JestTestName,
|
|
43
|
-
fn?: (...args: Array<any>) => ?Promise<
|
|
43
|
+
fn?: (...args: Array<any>) => ?Promise<unknown>,
|
|
44
44
|
timeout?: number,
|
|
45
45
|
) => void,
|
|
46
46
|
...
|
|
@@ -40,7 +40,7 @@ expect.addSnapshotSerializer({
|
|
|
40
40
|
*/
|
|
41
41
|
function generateTestsFromFixtures(
|
|
42
42
|
fixturesPath: string,
|
|
43
|
-
operation: (input: string) => string
|
|
43
|
+
operation: (input: string) => Promise<string>,
|
|
44
44
|
): void {
|
|
45
45
|
let fixtures = fs.readdirSync(fixturesPath);
|
|
46
46
|
|
|
@@ -56,9 +56,9 @@ function generateTestsFromFixtures(
|
|
|
56
56
|
);
|
|
57
57
|
fixtures = onlyFixtures;
|
|
58
58
|
}
|
|
59
|
-
test.each(fixtures)('matches expected output: %s', file => {
|
|
59
|
+
test.each(fixtures)('matches expected output: %s', async file => {
|
|
60
60
|
const input = fs.readFileSync(path.join(fixturesPath, file), 'utf8');
|
|
61
|
-
const output = getOutputForFixture(input, operation, file);
|
|
61
|
+
const output = await getOutputForFixture(input, operation, file);
|
|
62
62
|
expect({
|
|
63
63
|
[FIXTURE_TAG]: true,
|
|
64
64
|
input,
|
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
function getOutputForFixture(
|
|
14
|
+
async function getOutputForFixture(
|
|
15
15
|
input: string,
|
|
16
|
-
operation: (input: string) => string,
|
|
16
|
+
operation: (input: string) => Promise<string> | string,
|
|
17
17
|
file: string,
|
|
18
|
-
): string {
|
|
18
|
+
): Promise<string> {
|
|
19
19
|
const shouldThrow =
|
|
20
20
|
/^# *expected-to-throw/.test(input) || /\.error\.\w+$/.test(file);
|
|
21
21
|
if (shouldThrow) {
|
|
22
22
|
let result;
|
|
23
23
|
try {
|
|
24
|
-
result = operation(input);
|
|
24
|
+
result = await operation(input);
|
|
25
25
|
} catch (e) {
|
|
26
26
|
return `THROWN EXCEPTION:\n\n${e.toString()}`;
|
|
27
27
|
}
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
+
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator").default;
|
|
4
5
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
5
6
|
var getOutputForFixture = require('./getOutputForFixture');
|
|
6
7
|
var fs = require('fs');
|
|
@@ -30,12 +31,17 @@ function generateTestsFromFixtures(fixturesPath, operation) {
|
|
|
30
31
|
}))('matches expected output: %s', function () {});
|
|
31
32
|
fixtures = onlyFixtures;
|
|
32
33
|
}
|
|
33
|
-
test.each(fixtures)('matches expected output: %s', function (
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
test.each(fixtures)('matches expected output: %s', /*#__PURE__*/function () {
|
|
35
|
+
var _ref = _asyncToGenerator(function* (file) {
|
|
36
|
+
var _expect;
|
|
37
|
+
var input = fs.readFileSync(path.join(fixturesPath, file), 'utf8');
|
|
38
|
+
var output = yield getOutputForFixture(input, operation, file);
|
|
39
|
+
expect((_expect = {}, (0, _defineProperty2["default"])(_expect, FIXTURE_TAG, true), (0, _defineProperty2["default"])(_expect, "input", input), (0, _defineProperty2["default"])(_expect, "output", output), _expect)).toMatchSnapshot();
|
|
40
|
+
});
|
|
41
|
+
return function (_x) {
|
|
42
|
+
return _ref.apply(this, arguments);
|
|
43
|
+
};
|
|
44
|
+
}());
|
|
39
45
|
}
|
|
40
46
|
module.exports = {
|
|
41
47
|
generateTestsFromFixtures: generateTestsFromFixtures,
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator").default;
|
|
4
|
+
function getOutputForFixture(_x, _x2, _x3) {
|
|
5
|
+
return _getOutputForFixture.apply(this, arguments);
|
|
6
|
+
}
|
|
7
|
+
function _getOutputForFixture() {
|
|
8
|
+
_getOutputForFixture = _asyncToGenerator(function* (input, operation, file) {
|
|
9
|
+
var shouldThrow = /^# *expected-to-throw/.test(input) || /\.error\.\w+$/.test(file);
|
|
10
|
+
if (shouldThrow) {
|
|
11
|
+
var result;
|
|
12
|
+
try {
|
|
13
|
+
result = yield operation(input);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return "THROWN EXCEPTION:\n\n".concat(e.toString());
|
|
16
|
+
}
|
|
17
|
+
throw new Error("Expected test file '".concat(file, "' to throw, but it passed:\n").concat(result));
|
|
18
|
+
} else {
|
|
19
|
+
return operation(input);
|
|
11
20
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return operation(input);
|
|
15
|
-
}
|
|
21
|
+
});
|
|
22
|
+
return _getOutputForFixture.apply(this, arguments);
|
|
16
23
|
}
|
|
17
24
|
module.exports = getOutputForFixture;
|
package/lib/testschema.graphql
CHANGED
|
@@ -26,15 +26,7 @@ directive @fetchable(field_name: String!) on OBJECT
|
|
|
26
26
|
|
|
27
27
|
directive @relay_client_component_server(module_id: String!) on FRAGMENT_SPREAD
|
|
28
28
|
|
|
29
|
-
directive @
|
|
30
|
-
|
|
31
|
-
directive @live_query(
|
|
32
|
-
enabled: Boolean = true
|
|
33
|
-
polling_interval: Int
|
|
34
|
-
config_id: String
|
|
35
|
-
partial: Boolean
|
|
36
|
-
event_stream: String
|
|
37
|
-
) on QUERY
|
|
29
|
+
directive @client_polling(interval: Int) on QUERY
|
|
38
30
|
|
|
39
31
|
type Query {
|
|
40
32
|
checkinSearchQuery(query: CheckinSearchInput): CheckinSearchResult
|
|
@@ -60,6 +52,63 @@ type Query {
|
|
|
60
52
|
fetch__NonNodeStory(input_fetch_id: ID!): NonNodeStory
|
|
61
53
|
nonNodeStory(id: ID!): NonNodeStory
|
|
62
54
|
userOrPage(id: ID!): UserOrPage
|
|
55
|
+
bicycle: Bicycle
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
type Bicycle implements Node {
|
|
59
|
+
actor: Actor
|
|
60
|
+
actors: [Actor]
|
|
61
|
+
actorCount: Int
|
|
62
|
+
address: StreetAddress
|
|
63
|
+
allPhones: [Phone]
|
|
64
|
+
author: User
|
|
65
|
+
backgroundImage: Image
|
|
66
|
+
birthdate: Date
|
|
67
|
+
body: Text
|
|
68
|
+
canViewerComment: Boolean
|
|
69
|
+
canViewerLike: Boolean
|
|
70
|
+
comments(
|
|
71
|
+
after: ID
|
|
72
|
+
before: ID
|
|
73
|
+
first: Int
|
|
74
|
+
last: Int
|
|
75
|
+
orderby: String
|
|
76
|
+
): CommentsConnection
|
|
77
|
+
doesViewerLike: Boolean
|
|
78
|
+
emailAddresses: [String]
|
|
79
|
+
feedback: Feedback
|
|
80
|
+
firstName(if: Boolean, unless: Boolean): String
|
|
81
|
+
friends(
|
|
82
|
+
after: ID
|
|
83
|
+
before: ID
|
|
84
|
+
first: Int
|
|
85
|
+
last: Int
|
|
86
|
+
orderby: [String]
|
|
87
|
+
find: String
|
|
88
|
+
isViewerFriend: Boolean
|
|
89
|
+
if: Boolean
|
|
90
|
+
unless: Boolean
|
|
91
|
+
traits: [PersonalityTraits]
|
|
92
|
+
): FriendsConnection
|
|
93
|
+
hometown: Page
|
|
94
|
+
id: ID!
|
|
95
|
+
lastName: String
|
|
96
|
+
likers(first: Int): LikersOfContentConnection
|
|
97
|
+
likeSentence: Text
|
|
98
|
+
message: Text
|
|
99
|
+
name: String
|
|
100
|
+
profilePicture(size: [Int], preset: PhotoSize): Image
|
|
101
|
+
segments(first: Int): Segments
|
|
102
|
+
screennames: [Screenname]
|
|
103
|
+
subscribeStatus: String
|
|
104
|
+
subscribers(first: Int): SubscribersConnection
|
|
105
|
+
topLevelComments(first: Int): TopLevelCommentsConnection
|
|
106
|
+
tracking: String
|
|
107
|
+
url(relative: Boolean, site: String): String
|
|
108
|
+
websites: [String]
|
|
109
|
+
username: String
|
|
110
|
+
viewerSavedState: String
|
|
111
|
+
wheels: Int
|
|
63
112
|
}
|
|
64
113
|
|
|
65
114
|
union UserOrPage = User | Page
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "relay-test-utils-internal",
|
|
3
3
|
"description": "Internal utilities for testing Relay.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "21.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.25.0",
|
|
19
19
|
"fbjs": "^3.0.2",
|
|
20
|
-
"relay-runtime": "
|
|
20
|
+
"relay-runtime": "21.0.0"
|
|
21
21
|
},
|
|
22
22
|
"directories": {
|
|
23
23
|
"": "./"
|
package/printAST.js.flow
CHANGED
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
* prop: value,
|
|
22
22
|
* }
|
|
23
23
|
*/
|
|
24
|
-
function printAST(ast:
|
|
24
|
+
function printAST(ast: unknown): string {
|
|
25
25
|
return printASTImpl(ast, '');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function printASTImpl(ast:
|
|
28
|
+
function printASTImpl(ast: unknown, indent: string): string {
|
|
29
29
|
switch (typeof ast) {
|
|
30
30
|
case 'undefined':
|
|
31
31
|
return 'undefined';
|
|
@@ -33,6 +33,8 @@ function printASTImpl(ast: mixed, indent: string): string {
|
|
|
33
33
|
if (ast === null) {
|
|
34
34
|
return 'null';
|
|
35
35
|
} else if (Array.isArray(ast)) {
|
|
36
|
+
/* $FlowFixMe[invalid-compare] Error discovered during Constant
|
|
37
|
+
* Condition roll out. See https://fburl.com/workplace/4oq3zi07. */
|
|
36
38
|
if (ast.length === 0) {
|
|
37
39
|
return '[]';
|
|
38
40
|
}
|
package/simpleClone.js.flow
CHANGED
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
*/
|
|
19
19
|
function simpleClone<T>(value: T): T {
|
|
20
20
|
if (Array.isArray(value)) {
|
|
21
|
-
// $FlowFixMe[incompatible-
|
|
21
|
+
// $FlowFixMe[incompatible-type]
|
|
22
22
|
return value.map(simpleClone);
|
|
23
23
|
} else if (value != null && typeof value === 'object') {
|
|
24
|
-
const result: {[string]:
|
|
24
|
+
const result: {[string]: unknown} = {};
|
|
25
25
|
for (const key in value) {
|
|
26
26
|
result[key] = simpleClone(value[key]);
|
|
27
27
|
}
|
|
28
|
-
// $FlowFixMe[incompatible-
|
|
28
|
+
// $FlowFixMe[incompatible-type]
|
|
29
29
|
return result;
|
|
30
30
|
} else {
|
|
31
31
|
return value;
|
|
@@ -23,12 +23,12 @@ import type {OperationDescriptor} from '../relay-runtime/store/RelayStoreTypes';
|
|
|
23
23
|
* should use `isOperationRetained` for new tests as it is much less error-prone.
|
|
24
24
|
*/
|
|
25
25
|
function trackRetentionForEnvironment(environment: IEnvironment): {
|
|
26
|
-
release_DEPRECATED: JestMockFn<[
|
|
26
|
+
release_DEPRECATED: JestMockFn<[unknown], void>,
|
|
27
27
|
isOperationRetained: OperationDescriptor => boolean,
|
|
28
28
|
} {
|
|
29
|
-
const retainCountsByOperation = new Map<
|
|
29
|
+
const retainCountsByOperation = new Map<unknown, number>();
|
|
30
30
|
|
|
31
|
-
const release = jest.fn((id:
|
|
31
|
+
const release = jest.fn((id: unknown) => {
|
|
32
32
|
const existing = retainCountsByOperation.get(id) ?? NaN;
|
|
33
33
|
if (existing === 1) {
|
|
34
34
|
retainCountsByOperation.delete(id);
|