relay-test-utils-internal 13.1.0 → 14.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/consoleError.js.flow +70 -0
- package/consoleErrorsAndWarnings.js.flow +134 -0
- package/consoleWarning.js.flow +70 -0
- package/index.js +1 -1
- package/index.js.flow +23 -1
- package/lib/consoleError.js +63 -0
- package/lib/consoleErrorsAndWarnings.js +116 -0
- package/lib/consoleWarning.js +63 -0
- package/lib/index.js +35 -12
- package/lib/testschema.graphql +0 -26
- package/lib/trackRetentionForEnvironment.js +65 -0
- package/lib/warnings.js +19 -63
- package/package.json +2 -2
- package/relay-test-utils-internal.js +2 -2
- package/relay-test-utils-internal.min.js +2 -2
- package/simpleClone.js.flow +1 -1
- package/trackRetentionForEnvironment.js.flow +65 -0
- package/warnings.js.flow +28 -61
@@ -0,0 +1,70 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
* @flow strict-local
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
/* global jest */
|
15
|
+
|
16
|
+
import type {WillFireOptions} from './consoleErrorsAndWarnings';
|
17
|
+
|
18
|
+
const {createConsoleInterceptionSystem} = require('./consoleErrorsAndWarnings');
|
19
|
+
|
20
|
+
const consoleErrorsSystem = createConsoleInterceptionSystem(
|
21
|
+
'error',
|
22
|
+
'expectConsoleError',
|
23
|
+
impl => {
|
24
|
+
jest.spyOn(console, 'error').mockImplementation(impl);
|
25
|
+
},
|
26
|
+
);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Mocks console.error so that errors printed to the console are instead thrown.
|
30
|
+
* Any expected errors need to be explicitly expected with `expectConsoleErrorWillFire(message)`.
|
31
|
+
*
|
32
|
+
* NOTE: This should be called on top of a test file. The test should NOT
|
33
|
+
* use `jest.resetModules()` or manually mock `console`.
|
34
|
+
*/
|
35
|
+
function disallowConsoleErrors(): void {
|
36
|
+
consoleErrorsSystem.disallowMessages();
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Expect an error with the given message. If the message isn't fired in the
|
41
|
+
* current test, the test will fail.
|
42
|
+
*/
|
43
|
+
function expectConsoleErrorWillFire(
|
44
|
+
message: string,
|
45
|
+
options?: WillFireOptions,
|
46
|
+
): void {
|
47
|
+
consoleErrorsSystem.expectMessageWillFire(message, options);
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Expect the callback `fn` to print an error with the message, and otherwise fail.
|
52
|
+
*/
|
53
|
+
function expectConsoleError<T>(message: string, fn: () => T): T {
|
54
|
+
return consoleErrorsSystem.expectMessage(message, fn);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Expect the callback `fn` to trigger all console errors (in sequence),
|
59
|
+
* and otherwise fail.
|
60
|
+
*/
|
61
|
+
function expectConsoleErrorsMany<T>(messages: Array<string>, fn: () => T): T {
|
62
|
+
return consoleErrorsSystem.expectMessageMany(messages, fn);
|
63
|
+
}
|
64
|
+
|
65
|
+
module.exports = {
|
66
|
+
disallowConsoleErrors,
|
67
|
+
expectConsoleErrorWillFire,
|
68
|
+
expectConsoleError,
|
69
|
+
expectConsoleErrorsMany,
|
70
|
+
};
|
@@ -0,0 +1,134 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
* @flow strict-local
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
/* global afterEach */
|
15
|
+
|
16
|
+
export type WillFireOptions = {
|
17
|
+
count?: number,
|
18
|
+
optional?: boolean,
|
19
|
+
};
|
20
|
+
|
21
|
+
type API = $ReadOnly<{|
|
22
|
+
disallowMessages: () => void,
|
23
|
+
expectMessageWillFire: (string, void | WillFireOptions) => void,
|
24
|
+
expectMessage: <T>(string, () => T) => T,
|
25
|
+
expectMessageMany: <T>(Array<string>, () => T) => T,
|
26
|
+
|}>;
|
27
|
+
|
28
|
+
const originalConsoleError = console.error;
|
29
|
+
|
30
|
+
function createConsoleInterceptionSystem(
|
31
|
+
typename: string,
|
32
|
+
expectFunctionName: string,
|
33
|
+
setUpMock: ((string) => void) => void,
|
34
|
+
): API {
|
35
|
+
let installed = false;
|
36
|
+
const expectedMessages: Array<string> = [];
|
37
|
+
const optionalMessages: Array<string> = [];
|
38
|
+
const contextualExpectedMessage: Array<string> = [];
|
39
|
+
|
40
|
+
const typenameCap = typename.charAt(0).toUpperCase() + typename.slice(1);
|
41
|
+
const typenameCapPlural = typenameCap + 's';
|
42
|
+
const installerName = `disallow${typenameCap}s`;
|
43
|
+
|
44
|
+
function handleMessage(message: string): void {
|
45
|
+
const index = expectedMessages.findIndex(expected =>
|
46
|
+
message.startsWith(expected),
|
47
|
+
);
|
48
|
+
const optionalIndex = optionalMessages.findIndex(expected =>
|
49
|
+
message.startsWith(expected),
|
50
|
+
);
|
51
|
+
if (
|
52
|
+
contextualExpectedMessage.length > 0 &&
|
53
|
+
message.startsWith(contextualExpectedMessage[0])
|
54
|
+
) {
|
55
|
+
contextualExpectedMessage.shift();
|
56
|
+
} else if (index >= 0) {
|
57
|
+
expectedMessages.splice(index, 1);
|
58
|
+
} else if (optionalIndex >= 0) {
|
59
|
+
optionalMessages.splice(optionalIndex, 1);
|
60
|
+
} else {
|
61
|
+
// log to console in case the error gets swallowed somewhere
|
62
|
+
originalConsoleError(`Unexpected ${typenameCap}: ` + message);
|
63
|
+
throw new Error(`${typenameCap}: ` + message);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
function disallowMessages(): void {
|
68
|
+
if (installed) {
|
69
|
+
throw new Error(`${installerName} should be called only once.`);
|
70
|
+
}
|
71
|
+
installed = true;
|
72
|
+
setUpMock(handleMessage);
|
73
|
+
|
74
|
+
afterEach(() => {
|
75
|
+
optionalMessages.length = 0;
|
76
|
+
contextualExpectedMessage.length = 0;
|
77
|
+
if (expectedMessages.length > 0) {
|
78
|
+
const error = new Error(
|
79
|
+
`Some ${expectedMessages.length} expected ${typename}s where not triggered:\n\n` +
|
80
|
+
Array.from(expectedMessages, message => ` * ${message}`).join(
|
81
|
+
'\n',
|
82
|
+
) +
|
83
|
+
'\n',
|
84
|
+
);
|
85
|
+
expectedMessages.length = 0;
|
86
|
+
throw error;
|
87
|
+
}
|
88
|
+
});
|
89
|
+
}
|
90
|
+
|
91
|
+
function expectMessageWillFire(
|
92
|
+
message: string,
|
93
|
+
options?: WillFireOptions,
|
94
|
+
): void {
|
95
|
+
if (!installed) {
|
96
|
+
throw new Error(
|
97
|
+
`${installerName} needs to be called before expect${typenameCapPlural}WillFire`,
|
98
|
+
);
|
99
|
+
}
|
100
|
+
const optional = options?.optional === true; // avoid "sketchy null check"
|
101
|
+
for (let i = 0; i < (options?.count ?? 1); i++) {
|
102
|
+
(optional ? optionalMessages : expectedMessages).push(message);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
function expectMessage<T>(message: string, fn: () => T): T {
|
107
|
+
return expectMessageMany([message], fn);
|
108
|
+
}
|
109
|
+
|
110
|
+
function expectMessageMany<T>(messages: Array<string>, fn: () => T): T {
|
111
|
+
if (contextualExpectedMessage.length > 0) {
|
112
|
+
throw new Error(`Cannot nest ${expectFunctionName}() calls.`);
|
113
|
+
}
|
114
|
+
contextualExpectedMessage.push(...messages);
|
115
|
+
const result = fn();
|
116
|
+
if (contextualExpectedMessage.length > 0) {
|
117
|
+
const notFired = contextualExpectedMessage.toString();
|
118
|
+
contextualExpectedMessage.length = 0;
|
119
|
+
throw new Error(`Expected ${typename} in callback: ${notFired}`);
|
120
|
+
}
|
121
|
+
return result;
|
122
|
+
}
|
123
|
+
|
124
|
+
return {
|
125
|
+
disallowMessages,
|
126
|
+
expectMessageWillFire,
|
127
|
+
expectMessage,
|
128
|
+
expectMessageMany,
|
129
|
+
};
|
130
|
+
}
|
131
|
+
|
132
|
+
module.exports = {
|
133
|
+
createConsoleInterceptionSystem,
|
134
|
+
};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
* @flow strict-local
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
/* global jest */
|
15
|
+
|
16
|
+
import type {WillFireOptions} from './consoleErrorsAndWarnings';
|
17
|
+
|
18
|
+
const {createConsoleInterceptionSystem} = require('./consoleErrorsAndWarnings');
|
19
|
+
|
20
|
+
const consoleWarningsSystem = createConsoleInterceptionSystem(
|
21
|
+
'warning',
|
22
|
+
'expectConsoleWarning',
|
23
|
+
impl => {
|
24
|
+
jest.spyOn(console, 'warn').mockImplementation(impl);
|
25
|
+
},
|
26
|
+
);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Mocks console.warn so that warnings printed to the console are instead thrown.
|
30
|
+
* Any expected warnings need to be explicitly expected with `expectConsoleWarningWillFire(message)`.
|
31
|
+
*
|
32
|
+
* NOTE: This should be called on top of a test file. The test should NOT
|
33
|
+
* use `jest.resetModules()` or manually mock `console`.
|
34
|
+
*/
|
35
|
+
function disallowConsoleWarnings(): void {
|
36
|
+
consoleWarningsSystem.disallowMessages();
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Expect a warning with the given message. If the message isn't fired in the
|
41
|
+
* current test, the test will fail.
|
42
|
+
*/
|
43
|
+
function expectConsoleWarningWillFire(
|
44
|
+
message: string,
|
45
|
+
options?: WillFireOptions,
|
46
|
+
): void {
|
47
|
+
consoleWarningsSystem.expectMessageWillFire(message, options);
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Expect the callback `fn` to print a warning with the message, and otherwise fail.
|
52
|
+
*/
|
53
|
+
function expectConsoleWarning<T>(message: string, fn: () => T): T {
|
54
|
+
return consoleWarningsSystem.expectMessage(message, fn);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Expect the callback `fn` to trigger all console warnings (in sequence),
|
59
|
+
* and otherwise fail.
|
60
|
+
*/
|
61
|
+
function expectConsoleWarningsMany<T>(messages: Array<string>, fn: () => T): T {
|
62
|
+
return consoleWarningsSystem.expectMessageMany(messages, fn);
|
63
|
+
}
|
64
|
+
|
65
|
+
module.exports = {
|
66
|
+
disallowConsoleWarnings,
|
67
|
+
expectConsoleWarningWillFire,
|
68
|
+
expectConsoleWarning,
|
69
|
+
expectConsoleWarningsMany,
|
70
|
+
};
|
package/index.js
CHANGED
package/index.js.flow
CHANGED
@@ -12,6 +12,18 @@
|
|
12
12
|
|
13
13
|
'use strict';
|
14
14
|
|
15
|
+
const {
|
16
|
+
disallowConsoleErrors,
|
17
|
+
expectConsoleError,
|
18
|
+
expectConsoleErrorsMany,
|
19
|
+
expectConsoleErrorWillFire,
|
20
|
+
} = require('./consoleError');
|
21
|
+
const {
|
22
|
+
disallowConsoleWarnings,
|
23
|
+
expectConsoleWarning,
|
24
|
+
expectConsoleWarningsMany,
|
25
|
+
expectConsoleWarningWillFire,
|
26
|
+
} = require('./consoleWarning');
|
15
27
|
const describeWithFeatureFlags = require('./describeWithFeatureFlags');
|
16
28
|
const {
|
17
29
|
FIXTURE_TAG,
|
@@ -20,6 +32,7 @@ const {
|
|
20
32
|
const Matchers = require('./Matchers');
|
21
33
|
const printAST = require('./printAST');
|
22
34
|
const simpleClone = require('./simpleClone');
|
35
|
+
const trackRetentionForEnvironment = require('./trackRetentionForEnvironment');
|
23
36
|
const {
|
24
37
|
disallowWarnings,
|
25
38
|
expectToWarn,
|
@@ -50,14 +63,23 @@ module.exports = {
|
|
50
63
|
cannotReadPropertyOfUndefined__DEPRECATED,
|
51
64
|
createMockEnvironment,
|
52
65
|
describeWithFeatureFlags,
|
66
|
+
disallowConsoleErrors,
|
67
|
+
disallowConsoleWarnings,
|
68
|
+
disallowWarnings,
|
69
|
+
expectConsoleError,
|
70
|
+
expectConsoleErrorsMany,
|
71
|
+
expectConsoleErrorWillFire,
|
72
|
+
expectConsoleWarningWillFire,
|
73
|
+
expectConsoleWarning,
|
74
|
+
expectConsoleWarningsMany,
|
53
75
|
expectToWarn,
|
54
76
|
expectToWarnMany,
|
55
77
|
expectWarningWillFire,
|
56
|
-
disallowWarnings,
|
57
78
|
FIXTURE_TAG,
|
58
79
|
generateTestsFromFixtures,
|
59
80
|
matchers: Matchers,
|
60
81
|
printAST,
|
61
82
|
simpleClone,
|
83
|
+
trackRetentionForEnvironment,
|
62
84
|
unwrapContainer,
|
63
85
|
};
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
/* global jest */
|
13
|
+
|
14
|
+
var _require = require('./consoleErrorsAndWarnings'),
|
15
|
+
createConsoleInterceptionSystem = _require.createConsoleInterceptionSystem;
|
16
|
+
|
17
|
+
var consoleErrorsSystem = createConsoleInterceptionSystem('error', 'expectConsoleError', function (impl) {
|
18
|
+
jest.spyOn(console, 'error').mockImplementation(impl);
|
19
|
+
});
|
20
|
+
/**
|
21
|
+
* Mocks console.error so that errors printed to the console are instead thrown.
|
22
|
+
* Any expected errors need to be explicitly expected with `expectConsoleErrorWillFire(message)`.
|
23
|
+
*
|
24
|
+
* NOTE: This should be called on top of a test file. The test should NOT
|
25
|
+
* use `jest.resetModules()` or manually mock `console`.
|
26
|
+
*/
|
27
|
+
|
28
|
+
function disallowConsoleErrors() {
|
29
|
+
consoleErrorsSystem.disallowMessages();
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Expect an error with the given message. If the message isn't fired in the
|
33
|
+
* current test, the test will fail.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
function expectConsoleErrorWillFire(message, options) {
|
38
|
+
consoleErrorsSystem.expectMessageWillFire(message, options);
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* Expect the callback `fn` to print an error with the message, and otherwise fail.
|
42
|
+
*/
|
43
|
+
|
44
|
+
|
45
|
+
function expectConsoleError(message, fn) {
|
46
|
+
return consoleErrorsSystem.expectMessage(message, fn);
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Expect the callback `fn` to trigger all console errors (in sequence),
|
50
|
+
* and otherwise fail.
|
51
|
+
*/
|
52
|
+
|
53
|
+
|
54
|
+
function expectConsoleErrorsMany(messages, fn) {
|
55
|
+
return consoleErrorsSystem.expectMessageMany(messages, fn);
|
56
|
+
}
|
57
|
+
|
58
|
+
module.exports = {
|
59
|
+
disallowConsoleErrors: disallowConsoleErrors,
|
60
|
+
expectConsoleErrorWillFire: expectConsoleErrorWillFire,
|
61
|
+
expectConsoleError: expectConsoleError,
|
62
|
+
expectConsoleErrorsMany: expectConsoleErrorsMany
|
63
|
+
};
|
@@ -0,0 +1,116 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
/* global afterEach */
|
13
|
+
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
15
|
+
|
16
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
17
|
+
|
18
|
+
var originalConsoleError = console.error;
|
19
|
+
|
20
|
+
function createConsoleInterceptionSystem(typename, expectFunctionName, setUpMock) {
|
21
|
+
var installed = false;
|
22
|
+
var expectedMessages = [];
|
23
|
+
var optionalMessages = [];
|
24
|
+
var contextualExpectedMessage = [];
|
25
|
+
var typenameCap = typename.charAt(0).toUpperCase() + typename.slice(1);
|
26
|
+
var typenameCapPlural = typenameCap + 's';
|
27
|
+
var installerName = "disallow".concat(typenameCap, "s");
|
28
|
+
|
29
|
+
function handleMessage(message) {
|
30
|
+
var index = expectedMessages.findIndex(function (expected) {
|
31
|
+
return message.startsWith(expected);
|
32
|
+
});
|
33
|
+
var optionalIndex = optionalMessages.findIndex(function (expected) {
|
34
|
+
return message.startsWith(expected);
|
35
|
+
});
|
36
|
+
|
37
|
+
if (contextualExpectedMessage.length > 0 && message.startsWith(contextualExpectedMessage[0])) {
|
38
|
+
contextualExpectedMessage.shift();
|
39
|
+
} else if (index >= 0) {
|
40
|
+
expectedMessages.splice(index, 1);
|
41
|
+
} else if (optionalIndex >= 0) {
|
42
|
+
optionalMessages.splice(optionalIndex, 1);
|
43
|
+
} else {
|
44
|
+
// log to console in case the error gets swallowed somewhere
|
45
|
+
originalConsoleError("Unexpected ".concat(typenameCap, ": ") + message);
|
46
|
+
throw new Error("".concat(typenameCap, ": ") + message);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
function disallowMessages() {
|
51
|
+
if (installed) {
|
52
|
+
throw new Error("".concat(installerName, " should be called only once."));
|
53
|
+
}
|
54
|
+
|
55
|
+
installed = true;
|
56
|
+
setUpMock(handleMessage);
|
57
|
+
afterEach(function () {
|
58
|
+
optionalMessages.length = 0;
|
59
|
+
contextualExpectedMessage.length = 0;
|
60
|
+
|
61
|
+
if (expectedMessages.length > 0) {
|
62
|
+
var error = new Error("Some ".concat(expectedMessages.length, " expected ").concat(typename, "s where not triggered:\n\n") + Array.from(expectedMessages, function (message) {
|
63
|
+
return " * ".concat(message);
|
64
|
+
}).join('\n') + '\n');
|
65
|
+
expectedMessages.length = 0;
|
66
|
+
throw error;
|
67
|
+
}
|
68
|
+
});
|
69
|
+
}
|
70
|
+
|
71
|
+
function expectMessageWillFire(message, options) {
|
72
|
+
if (!installed) {
|
73
|
+
throw new Error("".concat(installerName, " needs to be called before expect").concat(typenameCapPlural, "WillFire"));
|
74
|
+
}
|
75
|
+
|
76
|
+
var optional = (options === null || options === void 0 ? void 0 : options.optional) === true; // avoid "sketchy null check"
|
77
|
+
|
78
|
+
for (var i = 0; i < ((_options$count = options === null || options === void 0 ? void 0 : options.count) !== null && _options$count !== void 0 ? _options$count : 1); i++) {
|
79
|
+
var _options$count;
|
80
|
+
|
81
|
+
(optional ? optionalMessages : expectedMessages).push(message);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
function expectMessage(message, fn) {
|
86
|
+
return expectMessageMany([message], fn);
|
87
|
+
}
|
88
|
+
|
89
|
+
function expectMessageMany(messages, fn) {
|
90
|
+
if (contextualExpectedMessage.length > 0) {
|
91
|
+
throw new Error("Cannot nest ".concat(expectFunctionName, "() calls."));
|
92
|
+
}
|
93
|
+
|
94
|
+
contextualExpectedMessage.push.apply(contextualExpectedMessage, (0, _toConsumableArray2["default"])(messages));
|
95
|
+
var result = fn();
|
96
|
+
|
97
|
+
if (contextualExpectedMessage.length > 0) {
|
98
|
+
var notFired = contextualExpectedMessage.toString();
|
99
|
+
contextualExpectedMessage.length = 0;
|
100
|
+
throw new Error("Expected ".concat(typename, " in callback: ").concat(notFired));
|
101
|
+
}
|
102
|
+
|
103
|
+
return result;
|
104
|
+
}
|
105
|
+
|
106
|
+
return {
|
107
|
+
disallowMessages: disallowMessages,
|
108
|
+
expectMessageWillFire: expectMessageWillFire,
|
109
|
+
expectMessage: expectMessage,
|
110
|
+
expectMessageMany: expectMessageMany
|
111
|
+
};
|
112
|
+
}
|
113
|
+
|
114
|
+
module.exports = {
|
115
|
+
createConsoleInterceptionSystem: createConsoleInterceptionSystem
|
116
|
+
};
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @emails oncall+relay
|
8
|
+
*
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
/* global jest */
|
13
|
+
|
14
|
+
var _require = require('./consoleErrorsAndWarnings'),
|
15
|
+
createConsoleInterceptionSystem = _require.createConsoleInterceptionSystem;
|
16
|
+
|
17
|
+
var consoleWarningsSystem = createConsoleInterceptionSystem('warning', 'expectConsoleWarning', function (impl) {
|
18
|
+
jest.spyOn(console, 'warn').mockImplementation(impl);
|
19
|
+
});
|
20
|
+
/**
|
21
|
+
* Mocks console.warn so that warnings printed to the console are instead thrown.
|
22
|
+
* Any expected warnings need to be explicitly expected with `expectConsoleWarningWillFire(message)`.
|
23
|
+
*
|
24
|
+
* NOTE: This should be called on top of a test file. The test should NOT
|
25
|
+
* use `jest.resetModules()` or manually mock `console`.
|
26
|
+
*/
|
27
|
+
|
28
|
+
function disallowConsoleWarnings() {
|
29
|
+
consoleWarningsSystem.disallowMessages();
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Expect a warning with the given message. If the message isn't fired in the
|
33
|
+
* current test, the test will fail.
|
34
|
+
*/
|
35
|
+
|
36
|
+
|
37
|
+
function expectConsoleWarningWillFire(message, options) {
|
38
|
+
consoleWarningsSystem.expectMessageWillFire(message, options);
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* Expect the callback `fn` to print a warning with the message, and otherwise fail.
|
42
|
+
*/
|
43
|
+
|
44
|
+
|
45
|
+
function expectConsoleWarning(message, fn) {
|
46
|
+
return consoleWarningsSystem.expectMessage(message, fn);
|
47
|
+
}
|
48
|
+
/**
|
49
|
+
* Expect the callback `fn` to trigger all console warnings (in sequence),
|
50
|
+
* and otherwise fail.
|
51
|
+
*/
|
52
|
+
|
53
|
+
|
54
|
+
function expectConsoleWarningsMany(messages, fn) {
|
55
|
+
return consoleWarningsSystem.expectMessageMany(messages, fn);
|
56
|
+
}
|
57
|
+
|
58
|
+
module.exports = {
|
59
|
+
disallowConsoleWarnings: disallowConsoleWarnings,
|
60
|
+
expectConsoleWarningWillFire: expectConsoleWarningWillFire,
|
61
|
+
expectConsoleWarning: expectConsoleWarning,
|
62
|
+
expectConsoleWarningsMany: expectConsoleWarningsMany
|
63
|
+
};
|
package/lib/index.js
CHANGED
@@ -10,11 +10,23 @@
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
11
11
|
'use strict';
|
12
12
|
|
13
|
+
var _require = require('./consoleError'),
|
14
|
+
disallowConsoleErrors = _require.disallowConsoleErrors,
|
15
|
+
expectConsoleError = _require.expectConsoleError,
|
16
|
+
expectConsoleErrorsMany = _require.expectConsoleErrorsMany,
|
17
|
+
expectConsoleErrorWillFire = _require.expectConsoleErrorWillFire;
|
18
|
+
|
19
|
+
var _require2 = require('./consoleWarning'),
|
20
|
+
disallowConsoleWarnings = _require2.disallowConsoleWarnings,
|
21
|
+
expectConsoleWarning = _require2.expectConsoleWarning,
|
22
|
+
expectConsoleWarningsMany = _require2.expectConsoleWarningsMany,
|
23
|
+
expectConsoleWarningWillFire = _require2.expectConsoleWarningWillFire;
|
24
|
+
|
13
25
|
var describeWithFeatureFlags = require('./describeWithFeatureFlags');
|
14
26
|
|
15
|
-
var
|
16
|
-
FIXTURE_TAG =
|
17
|
-
generateTestsFromFixtures =
|
27
|
+
var _require3 = require('./generateTestsFromFixtures'),
|
28
|
+
FIXTURE_TAG = _require3.FIXTURE_TAG,
|
29
|
+
generateTestsFromFixtures = _require3.generateTestsFromFixtures;
|
18
30
|
|
19
31
|
var Matchers = require('./Matchers');
|
20
32
|
|
@@ -22,15 +34,17 @@ var printAST = require('./printAST');
|
|
22
34
|
|
23
35
|
var simpleClone = require('./simpleClone');
|
24
36
|
|
25
|
-
var
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
var trackRetentionForEnvironment = require('./trackRetentionForEnvironment');
|
38
|
+
|
39
|
+
var _require4 = require('./warnings'),
|
40
|
+
disallowWarnings = _require4.disallowWarnings,
|
41
|
+
expectToWarn = _require4.expectToWarn,
|
42
|
+
expectToWarnMany = _require4.expectToWarnMany,
|
43
|
+
expectWarningWillFire = _require4.expectWarningWillFire;
|
30
44
|
|
31
|
-
var
|
32
|
-
createMockEnvironment =
|
33
|
-
unwrapContainer =
|
45
|
+
var _require5 = require('relay-test-utils'),
|
46
|
+
createMockEnvironment = _require5.createMockEnvironment,
|
47
|
+
unwrapContainer = _require5.unwrapContainer; // Apparently, in node v16 (because now they are using V8 V9.something)
|
34
48
|
// the content of the TypeError has changed, and now some of our tests
|
35
49
|
// stated to fail.
|
36
50
|
// This is a temporary work-around to make test pass, but we need to
|
@@ -53,14 +67,23 @@ module.exports = {
|
|
53
67
|
cannotReadPropertyOfUndefined__DEPRECATED: cannotReadPropertyOfUndefined__DEPRECATED,
|
54
68
|
createMockEnvironment: createMockEnvironment,
|
55
69
|
describeWithFeatureFlags: describeWithFeatureFlags,
|
70
|
+
disallowConsoleErrors: disallowConsoleErrors,
|
71
|
+
disallowConsoleWarnings: disallowConsoleWarnings,
|
72
|
+
disallowWarnings: disallowWarnings,
|
73
|
+
expectConsoleError: expectConsoleError,
|
74
|
+
expectConsoleErrorsMany: expectConsoleErrorsMany,
|
75
|
+
expectConsoleErrorWillFire: expectConsoleErrorWillFire,
|
76
|
+
expectConsoleWarningWillFire: expectConsoleWarningWillFire,
|
77
|
+
expectConsoleWarning: expectConsoleWarning,
|
78
|
+
expectConsoleWarningsMany: expectConsoleWarningsMany,
|
56
79
|
expectToWarn: expectToWarn,
|
57
80
|
expectToWarnMany: expectToWarnMany,
|
58
81
|
expectWarningWillFire: expectWarningWillFire,
|
59
|
-
disallowWarnings: disallowWarnings,
|
60
82
|
FIXTURE_TAG: FIXTURE_TAG,
|
61
83
|
generateTestsFromFixtures: generateTestsFromFixtures,
|
62
84
|
matchers: Matchers,
|
63
85
|
printAST: printAST,
|
64
86
|
simpleClone: simpleClone,
|
87
|
+
trackRetentionForEnvironment: trackRetentionForEnvironment,
|
65
88
|
unwrapContainer: unwrapContainer
|
66
89
|
};
|
package/lib/testschema.graphql
CHANGED
@@ -143,28 +143,23 @@ type Subscription {
|
|
143
143
|
}
|
144
144
|
|
145
145
|
input ActorSubscribeInput {
|
146
|
-
clientMutationId: String
|
147
146
|
subscribeeId: ID
|
148
147
|
}
|
149
148
|
|
150
149
|
input ActorNameChangeInput {
|
151
|
-
clientMutationId: String
|
152
150
|
newName: String
|
153
151
|
}
|
154
152
|
|
155
153
|
input ApplicationRequestDeleteAllInput {
|
156
|
-
clientMutationId: String
|
157
154
|
deletedRequestIds: [ID]
|
158
155
|
}
|
159
156
|
|
160
157
|
input CommentCreateInput {
|
161
|
-
clientMutationId: String
|
162
158
|
feedbackId: ID
|
163
159
|
feedback: CommentfeedbackFeedback
|
164
160
|
}
|
165
161
|
|
166
162
|
input CommentsCreateInput {
|
167
|
-
clientMutationId: String
|
168
163
|
feedbackId: ID
|
169
164
|
feedback: [CommentfeedbackFeedback]
|
170
165
|
}
|
@@ -178,40 +173,33 @@ input FeedbackcommentComment {
|
|
178
173
|
}
|
179
174
|
|
180
175
|
input CommentCreateSubscriptionInput {
|
181
|
-
clientSubscriptionId: String
|
182
176
|
feedbackId: ID
|
183
177
|
text: String
|
184
178
|
}
|
185
179
|
|
186
180
|
input CommentDeleteInput {
|
187
|
-
clientMutationId: String
|
188
181
|
commentId: ID
|
189
182
|
}
|
190
183
|
|
191
184
|
input CommentsDeleteInput {
|
192
|
-
clientMutationId: String
|
193
185
|
commentIds: [ID]
|
194
186
|
}
|
195
187
|
|
196
188
|
input FeedbackLikeInput {
|
197
|
-
clientMutationId: String
|
198
189
|
feedbackId: ID
|
199
190
|
}
|
200
191
|
|
201
192
|
input FeedbackLikeInputStrict {
|
202
193
|
userID: ID!
|
203
|
-
clientMutationId: ID!
|
204
194
|
feedbackId: ID!
|
205
195
|
description: String
|
206
196
|
}
|
207
197
|
|
208
198
|
input NodeSaveStateInput {
|
209
|
-
clientMutationId: String
|
210
199
|
nodeId: ID
|
211
200
|
}
|
212
201
|
|
213
202
|
input UpdateAllSeenStateInput {
|
214
|
-
clientMutationId: String
|
215
203
|
storyIds: [ID]
|
216
204
|
}
|
217
205
|
|
@@ -221,22 +209,18 @@ input LocationInput {
|
|
221
209
|
}
|
222
210
|
|
223
211
|
type setLocationResponsePayload {
|
224
|
-
clientMutationId: String
|
225
212
|
viewer: Viewer
|
226
213
|
}
|
227
214
|
|
228
215
|
type ActorSubscribeResponsePayload {
|
229
|
-
clientMutationId: String
|
230
216
|
subscribee: Actor
|
231
217
|
}
|
232
218
|
|
233
219
|
type ActorNameChangePayload {
|
234
|
-
clientMutationId: String
|
235
220
|
actor: Actor
|
236
221
|
}
|
237
222
|
|
238
223
|
type ApplicationRequestDeleteAllResponsePayload {
|
239
|
-
clientMutationId: String
|
240
224
|
deletedRequestIds: [ID]
|
241
225
|
}
|
242
226
|
|
@@ -250,7 +234,6 @@ input CheckinSearchInput {
|
|
250
234
|
}
|
251
235
|
|
252
236
|
input StoryUpdateInput {
|
253
|
-
clientMutationId: String
|
254
237
|
body: InputText
|
255
238
|
}
|
256
239
|
|
@@ -334,7 +317,6 @@ type ConfigCreateSubscriptResponsePayload {
|
|
334
317
|
}
|
335
318
|
|
336
319
|
type CommentCreateResponsePayload {
|
337
|
-
clientMutationId: String
|
338
320
|
comment: Comment
|
339
321
|
feedback: Feedback
|
340
322
|
feedbackCommentEdge: CommentsEdge
|
@@ -342,7 +324,6 @@ type CommentCreateResponsePayload {
|
|
342
324
|
}
|
343
325
|
|
344
326
|
type CommentsCreateResponsePayload {
|
345
|
-
clientMutationId: String
|
346
327
|
comments: [Comment]
|
347
328
|
feedback: [Feedback]
|
348
329
|
feedbackCommentEdges: [CommentsEdge]
|
@@ -350,19 +331,16 @@ type CommentsCreateResponsePayload {
|
|
350
331
|
}
|
351
332
|
|
352
333
|
type CommentDeleteResponsePayload {
|
353
|
-
clientMutationId: String
|
354
334
|
deletedCommentId: ID
|
355
335
|
feedback: Feedback
|
356
336
|
}
|
357
337
|
|
358
338
|
type CommentsDeleteResponsePayload {
|
359
|
-
clientMutationId: String
|
360
339
|
deletedCommentIds: [ID]
|
361
340
|
feedback: Feedback
|
362
341
|
}
|
363
342
|
|
364
343
|
type StoryUpdateResponsePayload {
|
365
|
-
clientMutationId: String
|
366
344
|
story: Story
|
367
345
|
}
|
368
346
|
|
@@ -478,8 +456,6 @@ type Feedback implements Node & HasJsField {
|
|
478
456
|
}
|
479
457
|
|
480
458
|
type FeedbackLikeResponsePayload {
|
481
|
-
clientMutationId: String
|
482
|
-
clientSubscriptionId: String
|
483
459
|
feedback: Feedback
|
484
460
|
}
|
485
461
|
|
@@ -938,13 +914,11 @@ type TopLevelCommentsConnection {
|
|
938
914
|
}
|
939
915
|
|
940
916
|
input UnfriendInput {
|
941
|
-
clientMutationId: String
|
942
917
|
friendId: ID
|
943
918
|
}
|
944
919
|
|
945
920
|
type UnfriendResponsePayload {
|
946
921
|
actor: Actor
|
947
|
-
clientMutationId: String
|
948
922
|
formerFriend: User
|
949
923
|
}
|
950
924
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
// flowlint ambiguous-object-type:error
|
11
|
+
'use strict';
|
12
|
+
/* global jest */
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Takes an environment and augments it with a mock implementation of `retain`
|
16
|
+
* that tracks what operations are currently retained. Also returns the Jest mock
|
17
|
+
* `release` function for backwards-compatibility with existing tests, but you
|
18
|
+
* should use `isOperationRetained` for new tests as it is much less error-prone.
|
19
|
+
*/
|
20
|
+
function trackRetentionForEnvironment(environment) {
|
21
|
+
var retainCountsByOperation = new Map();
|
22
|
+
var release = jest.fn(function (id) {
|
23
|
+
var _retainCountsByOperat;
|
24
|
+
|
25
|
+
var existing = (_retainCountsByOperat = retainCountsByOperation.get(id)) !== null && _retainCountsByOperat !== void 0 ? _retainCountsByOperat : NaN;
|
26
|
+
|
27
|
+
if (existing === 1) {
|
28
|
+
retainCountsByOperation["delete"](id);
|
29
|
+
} else {
|
30
|
+
retainCountsByOperation.set(id, existing - 1);
|
31
|
+
}
|
32
|
+
}); // $FlowFixMe[cannot-write] safe to do for mocking
|
33
|
+
|
34
|
+
environment.retain = jest.fn(function (operation) {
|
35
|
+
var _retainCountsByOperat2;
|
36
|
+
|
37
|
+
var id = operation.request.identifier;
|
38
|
+
var existing = (_retainCountsByOperat2 = retainCountsByOperation.get(id)) !== null && _retainCountsByOperat2 !== void 0 ? _retainCountsByOperat2 : 0;
|
39
|
+
retainCountsByOperation.set(id, existing + 1);
|
40
|
+
var released = false;
|
41
|
+
return {
|
42
|
+
dispose: function dispose() {
|
43
|
+
if (!released) {
|
44
|
+
release(id);
|
45
|
+
}
|
46
|
+
|
47
|
+
released = true;
|
48
|
+
}
|
49
|
+
};
|
50
|
+
});
|
51
|
+
|
52
|
+
function isOperationRetained(operation) {
|
53
|
+
var _retainCountsByOperat3;
|
54
|
+
|
55
|
+
var id = operation.request.identifier;
|
56
|
+
return ((_retainCountsByOperat3 = retainCountsByOperation.get(id)) !== null && _retainCountsByOperat3 !== void 0 ? _retainCountsByOperat3 : 0) > 0;
|
57
|
+
}
|
58
|
+
|
59
|
+
return {
|
60
|
+
release_DEPRECATED: release,
|
61
|
+
isOperationRetained: isOperationRetained
|
62
|
+
};
|
63
|
+
}
|
64
|
+
|
65
|
+
module.exports = trackRetentionForEnvironment;
|
package/lib/warnings.js
CHANGED
@@ -9,29 +9,12 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
'use strict';
|
12
|
-
/* global jest
|
12
|
+
/* global jest */
|
13
13
|
|
14
|
-
var
|
14
|
+
var _require = require('./consoleErrorsAndWarnings'),
|
15
|
+
createConsoleInterceptionSystem = _require.createConsoleInterceptionSystem;
|
15
16
|
|
16
|
-
var
|
17
|
-
|
18
|
-
var installed = false;
|
19
|
-
var expectedWarnings = [];
|
20
|
-
var contextualExpectedWarning = [];
|
21
|
-
/**
|
22
|
-
* Mocks the `warning` module to turn warnings into errors. Any expected
|
23
|
-
* warnings need to be explicitly expected with `expectWarningWillFire(message)`.
|
24
|
-
*
|
25
|
-
* NOTE: This should be called on top of a test file. The test should NOT
|
26
|
-
* use `jest.resetModules()` or manually mock `warning`.
|
27
|
-
*/
|
28
|
-
|
29
|
-
function disallowWarnings() {
|
30
|
-
if (installed) {
|
31
|
-
throw new Error('`disallowWarnings` should be called at most once');
|
32
|
-
}
|
33
|
-
|
34
|
-
installed = true;
|
17
|
+
var warningsSystem = createConsoleInterceptionSystem('warning', 'expectToWarn', function (impl) {
|
35
18
|
jest.mock("fbjs/lib/warning", function () {
|
36
19
|
return jest.fn(function (condition, format) {
|
37
20
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
@@ -43,31 +26,21 @@ function disallowWarnings() {
|
|
43
26
|
var message = format.replace(/%s/g, function () {
|
44
27
|
return String(args[argIndex++]);
|
45
28
|
});
|
46
|
-
|
47
|
-
|
48
|
-
if (contextualExpectedWarning.length > 0 && contextualExpectedWarning[0] === message) {
|
49
|
-
contextualExpectedWarning.shift();
|
50
|
-
} else if (index >= 0) {
|
51
|
-
expectedWarnings.splice(index, 1);
|
52
|
-
} else {
|
53
|
-
// log to console in case the error gets swallowed somewhere
|
54
|
-
console.error('Unexpected Warning: ' + message);
|
55
|
-
throw new Error('Warning: ' + message);
|
56
|
-
}
|
29
|
+
impl(message);
|
57
30
|
}
|
58
31
|
});
|
59
32
|
});
|
60
|
-
|
61
|
-
|
33
|
+
});
|
34
|
+
/**
|
35
|
+
* Mocks the `warning` module to turn warnings into errors. Any expected
|
36
|
+
* warnings need to be explicitly expected with `expectWarningWillFire(message)`.
|
37
|
+
*
|
38
|
+
* NOTE: This should be called on top of a test file. The test should NOT
|
39
|
+
* use `jest.resetModules()` or manually mock `warning`.
|
40
|
+
*/
|
62
41
|
|
63
|
-
|
64
|
-
|
65
|
-
return " * ".concat(message);
|
66
|
-
}).join('\n') + '\n');
|
67
|
-
expectedWarnings.length = 0;
|
68
|
-
throw error;
|
69
|
-
}
|
70
|
-
});
|
42
|
+
function disallowWarnings() {
|
43
|
+
warningsSystem.disallowMessages();
|
71
44
|
}
|
72
45
|
/**
|
73
46
|
* Expect a warning with the given message. If the message isn't fired in the
|
@@ -75,12 +48,8 @@ function disallowWarnings() {
|
|
75
48
|
*/
|
76
49
|
|
77
50
|
|
78
|
-
function expectWarningWillFire(message) {
|
79
|
-
|
80
|
-
throw new Error('`disallowWarnings` needs to be called before `expectWarningWillFire`');
|
81
|
-
}
|
82
|
-
|
83
|
-
expectedWarnings.push(message);
|
51
|
+
function expectWarningWillFire(message, options) {
|
52
|
+
warningsSystem.expectMessageWillFire(message, options);
|
84
53
|
}
|
85
54
|
/**
|
86
55
|
* Expect the callback `fn` to trigger the warning message and otherwise fail.
|
@@ -88,7 +57,7 @@ function expectWarningWillFire(message) {
|
|
88
57
|
|
89
58
|
|
90
59
|
function expectToWarn(message, fn) {
|
91
|
-
return
|
60
|
+
return warningsSystem.expectMessage(message, fn);
|
92
61
|
}
|
93
62
|
/**
|
94
63
|
* Expect the callback `fn` to trigger all warning messages (in sequence)
|
@@ -97,20 +66,7 @@ function expectToWarn(message, fn) {
|
|
97
66
|
|
98
67
|
|
99
68
|
function expectToWarnMany(messages, fn) {
|
100
|
-
|
101
|
-
throw new Error('Cannot nest `expectToWarn()` calls.');
|
102
|
-
}
|
103
|
-
|
104
|
-
contextualExpectedWarning.push.apply(contextualExpectedWarning, (0, _toConsumableArray2["default"])(messages));
|
105
|
-
var result = fn();
|
106
|
-
|
107
|
-
if (contextualExpectedWarning.length > 0) {
|
108
|
-
var notFired = contextualExpectedWarning.toString();
|
109
|
-
contextualExpectedWarning.length = 0;
|
110
|
-
throw new Error("Expected callback to warn: ".concat(notFired));
|
111
|
-
}
|
112
|
-
|
113
|
-
return result;
|
69
|
+
return warningsSystem.expectMessageMany(messages, fn);
|
114
70
|
}
|
115
71
|
|
116
72
|
module.exports = {
|
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": "14.0.0",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay"
|
@@ -17,7 +17,7 @@
|
|
17
17
|
"dependencies": {
|
18
18
|
"@babel/runtime": "^7.0.0",
|
19
19
|
"fbjs": "^3.0.2",
|
20
|
-
"relay-runtime": "
|
20
|
+
"relay-runtime": "14.0.0"
|
21
21
|
},
|
22
22
|
"directories": {
|
23
23
|
"": "./"
|
@@ -1,4 +1,4 @@
|
|
1
1
|
/**
|
2
|
-
* Relay
|
2
|
+
* Relay v14.0.0
|
3
3
|
*/
|
4
|
-
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=2)}([function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n){e.exports=require("relay-runtime")},function(e,n,t){"use strict";var r=t(3),o=t(5),i=o.FIXTURE_TAG,a=o.generateTestsFromFixtures,c=t(10),u=t(12),s=t(14),f=t(15),l=f.disallowWarnings,p=f.expectToWarn,d=f.expectToWarnMany,g=f.expectWarningWillFire,h=t(17),x=h.createMockEnvironment,y=h.unwrapContainer;e.exports={cannotReadPropertyOfUndefined__DEPRECATED:function(e){return process.version.match(/^v16\.(.+)$/)?"Cannot read properties of undefined (reading '".concat(e,"')"):"Cannot read property '".concat(e,"' of undefined")},createMockEnvironment:x,describeWithFeatureFlags:r,expectToWarn:p,expectToWarnMany:d,expectWarningWillFire:g,disallowWarnings:l,FIXTURE_TAG:i,generateTestsFromFixtures:a,matchers:c,printAST:u,simpleClone:s,unwrapContainer:y}},function(e,n,t){"use strict";var r=t(0)(t(4));e.exports=function(e,n,o){describe.each(e)("".concat(n," - Feature flags: %o"),(function(e){var n;beforeEach((function(){var o=t(1).RelayFeatureFlags;n=(0,r.default)({},o),Object.assign(o,e)})),afterEach((function(){var e=t(1).RelayFeatureFlags;Object.assign(e,n)})),o()}))}},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n,t){"use strict";var r=t(0)(t(6)),o=t(7),i=t(8),a=t(9),c=Symbol.for("FIXTURE_TAG");expect.addSnapshotSerializer({print:function(e){return Object.keys(e).map((function(n){return"~~~~~~~~~~ ".concat(n.toUpperCase()," ~~~~~~~~~~\n").concat(e[n])})).join("\n")},test:function(e){return e&&!0===e[c]}}),e.exports={generateTestsFromFixtures:function(e,n){var t=i.readdirSync(e);test("has fixtures in ".concat(e),(function(){expect(t.length>0).toBe(!0)}));var u=t.filter((function(e){return e.startsWith("only.")}));u.length&&(test.skip.each(t.filter((function(e){return!e.startsWith("only.")})))("matches expected output: %s",(function(){})),t=u),test.each(t)("matches expected output: %s",(function(t){var u,s=i.readFileSync(a.join(e,t),"utf8"),f=o(s,n,t);expect((u={},(0,r.default)(u,c,!0),(0,r.default)(u,"input",s),(0,r.default)(u,"output",f),u)).toMatchSnapshot()}))},FIXTURE_TAG:c}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n,t){"use strict";e.exports=function(e,n,t){if(/^# *expected-to-throw/.test(e)||/\.error\.\w+$/.test(t)){var r;try{r=n(e)}catch(e){return"THROWN EXCEPTION:\n\n".concat(e.toString())}throw new Error("Expected test file '".concat(t,"' to throw, but it passed:\n").concat(r))}return n(e)}},function(e,n){e.exports=require("fs")},function(e,n){e.exports=require("path")},function(e,n,t){"use strict";e.exports={toBeDeeplyFrozen:function(e){return function e(n){if(expect(Object.isFrozen(n)).toBe(!0),Array.isArray(n))n.forEach((function(n){return e(n)}));else if("object"==typeof n&&null!==n)for(var t in n)e(n[t])}(e),{pass:!0}},toWarn:function(e,n){var r=this.isNot;function o(e){return e instanceof RegExp?e.toString():JSON.stringify(e)}function i(e){return"["+e.map(o).join(", ")+"]"}function a(e){return e.length?e.map((function(e){return i([!!e[0]].concat(e.slice(1)))})).join(", "):"[]"}var c=t(11);if(!c.mock)throw new Error("toWarn(): Requires `jest.mock('warning')`.");var u=c.mock.calls.length;e();var s=c.mock.calls.slice(u);return n?(Array.isArray(n)||(n=[n]),{pass:!!s.find((function(e){return e.length===n.length+1&&e.every((function(e,t){if(!t)return!e;var r=n[t-1];return r instanceof RegExp?r.test(e):e===r}))})),message:function(){return"Expected ".concat(r?"not ":"","to warn: ")+"".concat(i([!1].concat(n))," but ")+"`warning` received the following calls: "+"".concat(a(s),".")}}):{pass:!!s.filter((function(e){return!e[0]})).length,message:function(){return"Expected ".concat(r?"not ":"","to warn but ")+"`warning` received the following calls: "+"".concat(a(s),".")}}}}},function(e,n){e.exports=require("fbjs/lib/warning")},function(e,n,t){"use strict";var r=t(0)(t(13));e.exports=function(e){return function e(n,t){switch(typeof n){case"undefined":return"undefined";case"object":if(null===n)return"null";if(Array.isArray(n)){if(0===n.length)return"[]";var o,i="[\n",a=t+" ",c=(0,r.default)(n);try{for(c.s();!(o=c.n()).done;){var u=o.value;i+=a+e(u,a)+",\n"}}catch(e){c.e(e)}finally{c.f()}return i+=t+"]"}if("string"==typeof n.kind){for(var s="".concat(n.kind," {\n"),f=t+" ",l=0,p=Object.entries(n);l<p.length;l++){var d=p[l],g=d[0],h=d[1];"kind"!==g&&(s+="".concat(f).concat(g,": ").concat(e(h,f),",\n"))}return s+=t+"}"}if("function"==typeof n.toJSON)return e(n.toJSON(),t);for(var x="{\n",y=t+" ",b=0,v=Object.entries(n);b<v.length;b++){var w=v[b],m=w[0],E=w[1];x+="".concat(y).concat(JSON.stringify(m),": ").concat(e(E,y),",\n")}return x+=t+"}";case"string":case"number":case"boolean":return JSON.stringify(n,null,2).replace("\n","\n"+t);default:throw new Error("printAST doesn't handle values where "+"typeof value === '".concat(typeof n,"'."))}}(e,"")}},function(e,n){e.exports=require("@babel/runtime/helpers/createForOfIteratorHelper")},function(e,n,t){"use strict";e.exports=function e(n){if(Array.isArray(n))return n.map(e);if(null!=n&&"object"==typeof n){var t={};for(var r in n)t[r]=e(n[r]);return t}return n}},function(e,n,t){"use strict";var r=t(0)(t(16)),o=!1,i=[],a=[];function c(e,n){if(a.length>0)throw new Error("Cannot nest `expectToWarn()` calls.");a.push.apply(a,(0,r.default)(e));var t=n();if(a.length>0){var o=a.toString();throw a.length=0,new Error("Expected callback to warn: ".concat(o))}return t}e.exports={disallowWarnings:function(){if(o)throw new Error("`disallowWarnings` should be called at most once");o=!0,jest.mock("fbjs/lib/warning",(function(){return jest.fn((function(e,n){for(var t=arguments.length,r=new Array(t>2?t-2:0),o=2;o<t;o++)r[o-2]=arguments[o];if(!e){var c=0,u=n.replace(/%s/g,(function(){return String(r[c++])})),s=i.indexOf(u);if(a.length>0&&a[0]===u)a.shift();else{if(!(s>=0))throw console.error("Unexpected Warning: "+u),new Error("Warning: "+u);i.splice(s,1)}}}))})),afterEach((function(){if(a.length=0,i.length>0){var e=new Error("Some expected warnings where not triggered:\n\n"+Array.from(i,(function(e){return" * ".concat(e)})).join("\n")+"\n");throw i.length=0,e}}))},expectWarningWillFire:function(e){if(!o)throw new Error("`disallowWarnings` needs to be called before `expectWarningWillFire`");i.push(e)},expectToWarn:function(e,n){return c([e],n)},expectToWarnMany:c}},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n){e.exports=require("relay-test-utils")}]);
|
4
|
+
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=3)}([function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n,t){"use strict";var r=t(0)(t(5)),o=console.error;e.exports={createConsoleInterceptionSystem:function(e,n,t){var i=!1,c=[],a=[],s=[],u=e.charAt(0).toUpperCase()+e.slice(1),l=u+"s",f="disallow".concat(u,"s");function p(e){var n=c.findIndex((function(n){return e.startsWith(n)})),t=a.findIndex((function(n){return e.startsWith(n)}));if(s.length>0&&e.startsWith(s[0]))s.shift();else if(n>=0)c.splice(n,1);else{if(!(t>=0))throw o("Unexpected ".concat(u,": ")+e),new Error("".concat(u,": ")+e);a.splice(t,1)}}function d(t,o){if(s.length>0)throw new Error("Cannot nest ".concat(n,"() calls."));s.push.apply(s,(0,r.default)(t));var i=o();if(s.length>0){var c=s.toString();throw s.length=0,new Error("Expected ".concat(e," in callback: ").concat(c))}return i}return{disallowMessages:function(){if(i)throw new Error("".concat(f," should be called only once."));i=!0,t(p),afterEach((function(){if(a.length=0,s.length=0,c.length>0){var n=new Error("Some ".concat(c.length," expected ").concat(e,"s where not triggered:\n\n")+Array.from(c,(function(e){return" * ".concat(e)})).join("\n")+"\n");throw c.length=0,n}}))},expectMessageWillFire:function(e,n){if(!i)throw new Error("".concat(f," needs to be called before expect").concat(l,"WillFire"));for(var t=!0===(null==n?void 0:n.optional),r=0;r<(null!==(o=null==n?void 0:n.count)&&void 0!==o?o:1);r++){var o;(t?a:c).push(e)}},expectMessage:function(e,n){return d([e],n)},expectMessageMany:d}}}},function(e,n){e.exports=require("relay-runtime")},function(e,n,t){"use strict";var r=t(4),o=r.disallowConsoleErrors,i=r.expectConsoleError,c=r.expectConsoleErrorsMany,a=r.expectConsoleErrorWillFire,s=t(6),u=s.disallowConsoleWarnings,l=s.expectConsoleWarning,f=s.expectConsoleWarningsMany,p=s.expectConsoleWarningWillFire,d=t(7),g=t(9),x=g.FIXTURE_TAG,h=g.generateTestsFromFixtures,y=t(14),v=t(16),w=t(18),b=t(19),m=t(20),W=m.disallowWarnings,E=m.expectToWarn,C=m.expectToWarnMany,M=m.expectWarningWillFire,F=t(21),j=F.createMockEnvironment,S=F.unwrapContainer;e.exports={cannotReadPropertyOfUndefined__DEPRECATED:function(e){return process.version.match(/^v16\.(.+)$/)?"Cannot read properties of undefined (reading '".concat(e,"')"):"Cannot read property '".concat(e,"' of undefined")},createMockEnvironment:j,describeWithFeatureFlags:d,disallowConsoleErrors:o,disallowConsoleWarnings:u,disallowWarnings:W,expectConsoleError:i,expectConsoleErrorsMany:c,expectConsoleErrorWillFire:a,expectConsoleWarningWillFire:p,expectConsoleWarning:l,expectConsoleWarningsMany:f,expectToWarn:E,expectToWarnMany:C,expectWarningWillFire:M,FIXTURE_TAG:x,generateTestsFromFixtures:h,matchers:y,printAST:v,simpleClone:w,trackRetentionForEnvironment:b,unwrapContainer:S}},function(e,n,t){"use strict";var r=(0,t(1).createConsoleInterceptionSystem)("error","expectConsoleError",(function(e){jest.spyOn(console,"error").mockImplementation(e)}));e.exports={disallowConsoleErrors:function(){r.disallowMessages()},expectConsoleErrorWillFire:function(e,n){r.expectMessageWillFire(e,n)},expectConsoleError:function(e,n){return r.expectMessage(e,n)},expectConsoleErrorsMany:function(e,n){return r.expectMessageMany(e,n)}}},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n,t){"use strict";var r=(0,t(1).createConsoleInterceptionSystem)("warning","expectConsoleWarning",(function(e){jest.spyOn(console,"warn").mockImplementation(e)}));e.exports={disallowConsoleWarnings:function(){r.disallowMessages()},expectConsoleWarningWillFire:function(e,n){r.expectMessageWillFire(e,n)},expectConsoleWarning:function(e,n){return r.expectMessage(e,n)},expectConsoleWarningsMany:function(e,n){return r.expectMessageMany(e,n)}}},function(e,n,t){"use strict";var r=t(0)(t(8));e.exports=function(e,n,o){describe.each(e)("".concat(n," - Feature flags: %o"),(function(e){var n;beforeEach((function(){var o=t(2).RelayFeatureFlags;n=(0,r.default)({},o),Object.assign(o,e)})),afterEach((function(){var e=t(2).RelayFeatureFlags;Object.assign(e,n)})),o()}))}},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n,t){"use strict";var r=t(0)(t(10)),o=t(11),i=t(12),c=t(13),a=Symbol.for("FIXTURE_TAG");expect.addSnapshotSerializer({print:function(e){return Object.keys(e).map((function(n){return"~~~~~~~~~~ ".concat(n.toUpperCase()," ~~~~~~~~~~\n").concat(e[n])})).join("\n")},test:function(e){return e&&!0===e[a]}}),e.exports={generateTestsFromFixtures:function(e,n){var t=i.readdirSync(e);test("has fixtures in ".concat(e),(function(){expect(t.length>0).toBe(!0)}));var s=t.filter((function(e){return e.startsWith("only.")}));s.length&&(test.skip.each(t.filter((function(e){return!e.startsWith("only.")})))("matches expected output: %s",(function(){})),t=s),test.each(t)("matches expected output: %s",(function(t){var s,u=i.readFileSync(c.join(e,t),"utf8"),l=o(u,n,t);expect((s={},(0,r.default)(s,a,!0),(0,r.default)(s,"input",u),(0,r.default)(s,"output",l),s)).toMatchSnapshot()}))},FIXTURE_TAG:a}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n,t){"use strict";e.exports=function(e,n,t){if(/^# *expected-to-throw/.test(e)||/\.error\.\w+$/.test(t)){var r;try{r=n(e)}catch(e){return"THROWN EXCEPTION:\n\n".concat(e.toString())}throw new Error("Expected test file '".concat(t,"' to throw, but it passed:\n").concat(r))}return n(e)}},function(e,n){e.exports=require("fs")},function(e,n){e.exports=require("path")},function(e,n,t){"use strict";e.exports={toBeDeeplyFrozen:function(e){return function e(n){if(expect(Object.isFrozen(n)).toBe(!0),Array.isArray(n))n.forEach((function(n){return e(n)}));else if("object"==typeof n&&null!==n)for(var t in n)e(n[t])}(e),{pass:!0}},toWarn:function(e,n){var r=this.isNot;function o(e){return e instanceof RegExp?e.toString():JSON.stringify(e)}function i(e){return"["+e.map(o).join(", ")+"]"}function c(e){return e.length?e.map((function(e){return i([!!e[0]].concat(e.slice(1)))})).join(", "):"[]"}var a=t(15);if(!a.mock)throw new Error("toWarn(): Requires `jest.mock('warning')`.");var s=a.mock.calls.length;e();var u=a.mock.calls.slice(s);return n?(Array.isArray(n)||(n=[n]),{pass:!!u.find((function(e){return e.length===n.length+1&&e.every((function(e,t){if(!t)return!e;var r=n[t-1];return r instanceof RegExp?r.test(e):e===r}))})),message:function(){return"Expected ".concat(r?"not ":"","to warn: ")+"".concat(i([!1].concat(n))," but ")+"`warning` received the following calls: "+"".concat(c(u),".")}}):{pass:!!u.filter((function(e){return!e[0]})).length,message:function(){return"Expected ".concat(r?"not ":"","to warn but ")+"`warning` received the following calls: "+"".concat(c(u),".")}}}}},function(e,n){e.exports=require("fbjs/lib/warning")},function(e,n,t){"use strict";var r=t(0)(t(17));e.exports=function(e){return function e(n,t){switch(typeof n){case"undefined":return"undefined";case"object":if(null===n)return"null";if(Array.isArray(n)){if(0===n.length)return"[]";var o,i="[\n",c=t+" ",a=(0,r.default)(n);try{for(a.s();!(o=a.n()).done;){var s=o.value;i+=c+e(s,c)+",\n"}}catch(e){a.e(e)}finally{a.f()}return i+=t+"]"}if("string"==typeof n.kind){for(var u="".concat(n.kind," {\n"),l=t+" ",f=0,p=Object.entries(n);f<p.length;f++){var d=p[f],g=d[0],x=d[1];"kind"!==g&&(u+="".concat(l).concat(g,": ").concat(e(x,l),",\n"))}return u+=t+"}"}if("function"==typeof n.toJSON)return e(n.toJSON(),t);for(var h="{\n",y=t+" ",v=0,w=Object.entries(n);v<w.length;v++){var b=w[v],m=b[0],W=b[1];h+="".concat(y).concat(JSON.stringify(m),": ").concat(e(W,y),",\n")}return h+=t+"}";case"string":case"number":case"boolean":return JSON.stringify(n,null,2).replace("\n","\n"+t);default:throw new Error("printAST doesn't handle values where "+"typeof value === '".concat(typeof n,"'."))}}(e,"")}},function(e,n){e.exports=require("@babel/runtime/helpers/createForOfIteratorHelper")},function(e,n,t){"use strict";e.exports=function e(n){if(Array.isArray(n))return n.map(e);if(null!=n&&"object"==typeof n){var t={};for(var r in n)t[r]=e(n[r]);return t}return n}},function(e,n,t){"use strict";e.exports=function(e){var n=new Map,t=jest.fn((function(e){var t,r=null!==(t=n.get(e))&&void 0!==t?t:NaN;1===r?n.delete(e):n.set(e,r-1)}));return e.retain=jest.fn((function(e){var r,o=e.request.identifier,i=null!==(r=n.get(o))&&void 0!==r?r:0;n.set(o,i+1);var c=!1;return{dispose:function(){c||t(o),c=!0}}})),{release_DEPRECATED:t,isOperationRetained:function(e){var t,r=e.request.identifier;return(null!==(t=n.get(r))&&void 0!==t?t:0)>0}}}},function(e,n,t){"use strict";var r=(0,t(1).createConsoleInterceptionSystem)("warning","expectToWarn",(function(e){jest.mock("fbjs/lib/warning",(function(){return jest.fn((function(n,t){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];if(!n){var c=0,a=t.replace(/%s/g,(function(){return String(o[c++])}));e(a)}}))}))}));e.exports={disallowWarnings:function(){r.disallowMessages()},expectWarningWillFire:function(e,n){r.expectMessageWillFire(e,n)},expectToWarn:function(e,n){return r.expectMessage(e,n)},expectToWarnMany:function(e,n){return r.expectMessageMany(e,n)}}},function(e,n){e.exports=require("relay-test-utils")}]);
|
@@ -1,9 +1,9 @@
|
|
1
1
|
/**
|
2
|
-
* Relay
|
2
|
+
* Relay v14.0.0
|
3
3
|
*
|
4
4
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
5
5
|
*
|
6
6
|
* This source code is licensed under the MIT license found in the
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
8
8
|
*/
|
9
|
-
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=2)}([function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n){e.exports=require("relay-runtime")},function(e,n,t){"use strict";var r=t(3),o=t(5),i=o.FIXTURE_TAG,a=o.generateTestsFromFixtures,c=t(10),u=t(12),s=t(14),f=t(15),l=f.disallowWarnings,p=f.expectToWarn,d=f.expectToWarnMany,g=f.expectWarningWillFire,h=t(17),x=h.createMockEnvironment,y=h.unwrapContainer;e.exports={cannotReadPropertyOfUndefined__DEPRECATED:function(e){return process.version.match(/^v16\.(.+)$/)?"Cannot read properties of undefined (reading '".concat(e,"')"):"Cannot read property '".concat(e,"' of undefined")},createMockEnvironment:x,describeWithFeatureFlags:r,expectToWarn:p,expectToWarnMany:d,expectWarningWillFire:g,disallowWarnings:l,FIXTURE_TAG:i,generateTestsFromFixtures:a,matchers:c,printAST:u,simpleClone:s,unwrapContainer:y}},function(e,n,t){"use strict";var r=t(0)(t(4));e.exports=function(e,n,o){describe.each(e)("".concat(n," - Feature flags: %o"),(function(e){var n;beforeEach((function(){var o=t(1).RelayFeatureFlags;n=(0,r.default)({},o),Object.assign(o,e)})),afterEach((function(){var e=t(1).RelayFeatureFlags;Object.assign(e,n)})),o()}))}},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n,t){"use strict";var r=t(0)(t(6)),o=t(7),i=t(8),a=t(9),c=Symbol.for("FIXTURE_TAG");expect.addSnapshotSerializer({print:function(e){return Object.keys(e).map((function(n){return"~~~~~~~~~~ ".concat(n.toUpperCase()," ~~~~~~~~~~\n").concat(e[n])})).join("\n")},test:function(e){return e&&!0===e[c]}}),e.exports={generateTestsFromFixtures:function(e,n){var t=i.readdirSync(e);test("has fixtures in ".concat(e),(function(){expect(t.length>0).toBe(!0)}));var u=t.filter((function(e){return e.startsWith("only.")}));u.length&&(test.skip.each(t.filter((function(e){return!e.startsWith("only.")})))("matches expected output: %s",(function(){})),t=u),test.each(t)("matches expected output: %s",(function(t){var u,s=i.readFileSync(a.join(e,t),"utf8"),f=o(s,n,t);expect((u={},(0,r.default)(u,c,!0),(0,r.default)(u,"input",s),(0,r.default)(u,"output",f),u)).toMatchSnapshot()}))},FIXTURE_TAG:c}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n,t){"use strict";e.exports=function(e,n,t){if(/^# *expected-to-throw/.test(e)||/\.error\.\w+$/.test(t)){var r;try{r=n(e)}catch(e){return"THROWN EXCEPTION:\n\n".concat(e.toString())}throw new Error("Expected test file '".concat(t,"' to throw, but it passed:\n").concat(r))}return n(e)}},function(e,n){e.exports=require("fs")},function(e,n){e.exports=require("path")},function(e,n,t){"use strict";e.exports={toBeDeeplyFrozen:function(e){return function e(n){if(expect(Object.isFrozen(n)).toBe(!0),Array.isArray(n))n.forEach((function(n){return e(n)}));else if("object"==typeof n&&null!==n)for(var t in n)e(n[t])}(e),{pass:!0}},toWarn:function(e,n){var r=this.isNot;function o(e){return e instanceof RegExp?e.toString():JSON.stringify(e)}function i(e){return"["+e.map(o).join(", ")+"]"}function a(e){return e.length?e.map((function(e){return i([!!e[0]].concat(e.slice(1)))})).join(", "):"[]"}var c=t(11);if(!c.mock)throw new Error("toWarn(): Requires `jest.mock('warning')`.");var u=c.mock.calls.length;e();var s=c.mock.calls.slice(u);return n?(Array.isArray(n)||(n=[n]),{pass:!!s.find((function(e){return e.length===n.length+1&&e.every((function(e,t){if(!t)return!e;var r=n[t-1];return r instanceof RegExp?r.test(e):e===r}))})),message:function(){return"Expected ".concat(r?"not ":"","to warn: ")+"".concat(i([!1].concat(n))," but ")+"`warning` received the following calls: "+"".concat(a(s),".")}}):{pass:!!s.filter((function(e){return!e[0]})).length,message:function(){return"Expected ".concat(r?"not ":"","to warn but ")+"`warning` received the following calls: "+"".concat(a(s),".")}}}}},function(e,n){e.exports=require("fbjs/lib/warning")},function(e,n,t){"use strict";var r=t(0)(t(13));e.exports=function(e){return function e(n,t){switch(typeof n){case"undefined":return"undefined";case"object":if(null===n)return"null";if(Array.isArray(n)){if(0===n.length)return"[]";var o,i="[\n",a=t+" ",c=(0,r.default)(n);try{for(c.s();!(o=c.n()).done;){var u=o.value;i+=a+e(u,a)+",\n"}}catch(e){c.e(e)}finally{c.f()}return i+=t+"]"}if("string"==typeof n.kind){for(var s="".concat(n.kind," {\n"),f=t+" ",l=0,p=Object.entries(n);l<p.length;l++){var d=p[l],g=d[0],h=d[1];"kind"!==g&&(s+="".concat(f).concat(g,": ").concat(e(h,f),",\n"))}return s+=t+"}"}if("function"==typeof n.toJSON)return e(n.toJSON(),t);for(var x="{\n",y=t+" ",b=0,v=Object.entries(n);b<v.length;b++){var w=v[b],m=w[0],E=w[1];x+="".concat(y).concat(JSON.stringify(m),": ").concat(e(E,y),",\n")}return x+=t+"}";case"string":case"number":case"boolean":return JSON.stringify(n,null,2).replace("\n","\n"+t);default:throw new Error("printAST doesn't handle values where "+"typeof value === '".concat(typeof n,"'."))}}(e,"")}},function(e,n){e.exports=require("@babel/runtime/helpers/createForOfIteratorHelper")},function(e,n,t){"use strict";e.exports=function e(n){if(Array.isArray(n))return n.map(e);if(null!=n&&"object"==typeof n){var t={};for(var r in n)t[r]=e(n[r]);return t}return n}},function(e,n,t){"use strict";var r=t(0)(t(16)),o=!1,i=[],a=[];function c(e,n){if(a.length>0)throw new Error("Cannot nest `expectToWarn()` calls.");a.push.apply(a,(0,r.default)(e));var t=n();if(a.length>0){var o=a.toString();throw a.length=0,new Error("Expected callback to warn: ".concat(o))}return t}e.exports={disallowWarnings:function(){if(o)throw new Error("`disallowWarnings` should be called at most once");o=!0,jest.mock("fbjs/lib/warning",(function(){return jest.fn((function(e,n){for(var t=arguments.length,r=new Array(t>2?t-2:0),o=2;o<t;o++)r[o-2]=arguments[o];if(!e){var c=0,u=n.replace(/%s/g,(function(){return String(r[c++])})),s=i.indexOf(u);if(a.length>0&&a[0]===u)a.shift();else{if(!(s>=0))throw console.error("Unexpected Warning: "+u),new Error("Warning: "+u);i.splice(s,1)}}}))})),afterEach((function(){if(a.length=0,i.length>0){var e=new Error("Some expected warnings where not triggered:\n\n"+Array.from(i,(function(e){return" * ".concat(e)})).join("\n")+"\n");throw i.length=0,e}}))},expectWarningWillFire:function(e){if(!o)throw new Error("`disallowWarnings` needs to be called before `expectWarningWillFire`");i.push(e)},expectToWarn:function(e,n){return c([e],n)},expectToWarnMany:c}},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n){e.exports=require("relay-test-utils")}]);
|
9
|
+
module.exports=function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=3)}([function(e,n){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,n,t){"use strict";var r=t(0)(t(5)),o=console.error;e.exports={createConsoleInterceptionSystem:function(e,n,t){var i=!1,c=[],a=[],s=[],u=e.charAt(0).toUpperCase()+e.slice(1),l=u+"s",f="disallow".concat(u,"s");function p(e){var n=c.findIndex((function(n){return e.startsWith(n)})),t=a.findIndex((function(n){return e.startsWith(n)}));if(s.length>0&&e.startsWith(s[0]))s.shift();else if(n>=0)c.splice(n,1);else{if(!(t>=0))throw o("Unexpected ".concat(u,": ")+e),new Error("".concat(u,": ")+e);a.splice(t,1)}}function d(t,o){if(s.length>0)throw new Error("Cannot nest ".concat(n,"() calls."));s.push.apply(s,(0,r.default)(t));var i=o();if(s.length>0){var c=s.toString();throw s.length=0,new Error("Expected ".concat(e," in callback: ").concat(c))}return i}return{disallowMessages:function(){if(i)throw new Error("".concat(f," should be called only once."));i=!0,t(p),afterEach((function(){if(a.length=0,s.length=0,c.length>0){var n=new Error("Some ".concat(c.length," expected ").concat(e,"s where not triggered:\n\n")+Array.from(c,(function(e){return" * ".concat(e)})).join("\n")+"\n");throw c.length=0,n}}))},expectMessageWillFire:function(e,n){if(!i)throw new Error("".concat(f," needs to be called before expect").concat(l,"WillFire"));for(var t=!0===(null==n?void 0:n.optional),r=0;r<(null!==(o=null==n?void 0:n.count)&&void 0!==o?o:1);r++){var o;(t?a:c).push(e)}},expectMessage:function(e,n){return d([e],n)},expectMessageMany:d}}}},function(e,n){e.exports=require("relay-runtime")},function(e,n,t){"use strict";var r=t(4),o=r.disallowConsoleErrors,i=r.expectConsoleError,c=r.expectConsoleErrorsMany,a=r.expectConsoleErrorWillFire,s=t(6),u=s.disallowConsoleWarnings,l=s.expectConsoleWarning,f=s.expectConsoleWarningsMany,p=s.expectConsoleWarningWillFire,d=t(7),g=t(9),x=g.FIXTURE_TAG,h=g.generateTestsFromFixtures,y=t(14),v=t(16),w=t(18),b=t(19),m=t(20),W=m.disallowWarnings,E=m.expectToWarn,C=m.expectToWarnMany,M=m.expectWarningWillFire,F=t(21),j=F.createMockEnvironment,S=F.unwrapContainer;e.exports={cannotReadPropertyOfUndefined__DEPRECATED:function(e){return process.version.match(/^v16\.(.+)$/)?"Cannot read properties of undefined (reading '".concat(e,"')"):"Cannot read property '".concat(e,"' of undefined")},createMockEnvironment:j,describeWithFeatureFlags:d,disallowConsoleErrors:o,disallowConsoleWarnings:u,disallowWarnings:W,expectConsoleError:i,expectConsoleErrorsMany:c,expectConsoleErrorWillFire:a,expectConsoleWarningWillFire:p,expectConsoleWarning:l,expectConsoleWarningsMany:f,expectToWarn:E,expectToWarnMany:C,expectWarningWillFire:M,FIXTURE_TAG:x,generateTestsFromFixtures:h,matchers:y,printAST:v,simpleClone:w,trackRetentionForEnvironment:b,unwrapContainer:S}},function(e,n,t){"use strict";var r=(0,t(1).createConsoleInterceptionSystem)("error","expectConsoleError",(function(e){jest.spyOn(console,"error").mockImplementation(e)}));e.exports={disallowConsoleErrors:function(){r.disallowMessages()},expectConsoleErrorWillFire:function(e,n){r.expectMessageWillFire(e,n)},expectConsoleError:function(e,n){return r.expectMessage(e,n)},expectConsoleErrorsMany:function(e,n){return r.expectMessageMany(e,n)}}},function(e,n){e.exports=require("@babel/runtime/helpers/toConsumableArray")},function(e,n,t){"use strict";var r=(0,t(1).createConsoleInterceptionSystem)("warning","expectConsoleWarning",(function(e){jest.spyOn(console,"warn").mockImplementation(e)}));e.exports={disallowConsoleWarnings:function(){r.disallowMessages()},expectConsoleWarningWillFire:function(e,n){r.expectMessageWillFire(e,n)},expectConsoleWarning:function(e,n){return r.expectMessage(e,n)},expectConsoleWarningsMany:function(e,n){return r.expectMessageMany(e,n)}}},function(e,n,t){"use strict";var r=t(0)(t(8));e.exports=function(e,n,o){describe.each(e)("".concat(n," - Feature flags: %o"),(function(e){var n;beforeEach((function(){var o=t(2).RelayFeatureFlags;n=(0,r.default)({},o),Object.assign(o,e)})),afterEach((function(){var e=t(2).RelayFeatureFlags;Object.assign(e,n)})),o()}))}},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,n,t){"use strict";var r=t(0)(t(10)),o=t(11),i=t(12),c=t(13),a=Symbol.for("FIXTURE_TAG");expect.addSnapshotSerializer({print:function(e){return Object.keys(e).map((function(n){return"~~~~~~~~~~ ".concat(n.toUpperCase()," ~~~~~~~~~~\n").concat(e[n])})).join("\n")},test:function(e){return e&&!0===e[a]}}),e.exports={generateTestsFromFixtures:function(e,n){var t=i.readdirSync(e);test("has fixtures in ".concat(e),(function(){expect(t.length>0).toBe(!0)}));var s=t.filter((function(e){return e.startsWith("only.")}));s.length&&(test.skip.each(t.filter((function(e){return!e.startsWith("only.")})))("matches expected output: %s",(function(){})),t=s),test.each(t)("matches expected output: %s",(function(t){var s,u=i.readFileSync(c.join(e,t),"utf8"),l=o(u,n,t);expect((s={},(0,r.default)(s,a,!0),(0,r.default)(s,"input",u),(0,r.default)(s,"output",l),s)).toMatchSnapshot()}))},FIXTURE_TAG:a}},function(e,n){e.exports=require("@babel/runtime/helpers/defineProperty")},function(e,n,t){"use strict";e.exports=function(e,n,t){if(/^# *expected-to-throw/.test(e)||/\.error\.\w+$/.test(t)){var r;try{r=n(e)}catch(e){return"THROWN EXCEPTION:\n\n".concat(e.toString())}throw new Error("Expected test file '".concat(t,"' to throw, but it passed:\n").concat(r))}return n(e)}},function(e,n){e.exports=require("fs")},function(e,n){e.exports=require("path")},function(e,n,t){"use strict";e.exports={toBeDeeplyFrozen:function(e){return function e(n){if(expect(Object.isFrozen(n)).toBe(!0),Array.isArray(n))n.forEach((function(n){return e(n)}));else if("object"==typeof n&&null!==n)for(var t in n)e(n[t])}(e),{pass:!0}},toWarn:function(e,n){var r=this.isNot;function o(e){return e instanceof RegExp?e.toString():JSON.stringify(e)}function i(e){return"["+e.map(o).join(", ")+"]"}function c(e){return e.length?e.map((function(e){return i([!!e[0]].concat(e.slice(1)))})).join(", "):"[]"}var a=t(15);if(!a.mock)throw new Error("toWarn(): Requires `jest.mock('warning')`.");var s=a.mock.calls.length;e();var u=a.mock.calls.slice(s);return n?(Array.isArray(n)||(n=[n]),{pass:!!u.find((function(e){return e.length===n.length+1&&e.every((function(e,t){if(!t)return!e;var r=n[t-1];return r instanceof RegExp?r.test(e):e===r}))})),message:function(){return"Expected ".concat(r?"not ":"","to warn: ")+"".concat(i([!1].concat(n))," but ")+"`warning` received the following calls: "+"".concat(c(u),".")}}):{pass:!!u.filter((function(e){return!e[0]})).length,message:function(){return"Expected ".concat(r?"not ":"","to warn but ")+"`warning` received the following calls: "+"".concat(c(u),".")}}}}},function(e,n){e.exports=require("fbjs/lib/warning")},function(e,n,t){"use strict";var r=t(0)(t(17));e.exports=function(e){return function e(n,t){switch(typeof n){case"undefined":return"undefined";case"object":if(null===n)return"null";if(Array.isArray(n)){if(0===n.length)return"[]";var o,i="[\n",c=t+" ",a=(0,r.default)(n);try{for(a.s();!(o=a.n()).done;){var s=o.value;i+=c+e(s,c)+",\n"}}catch(e){a.e(e)}finally{a.f()}return i+=t+"]"}if("string"==typeof n.kind){for(var u="".concat(n.kind," {\n"),l=t+" ",f=0,p=Object.entries(n);f<p.length;f++){var d=p[f],g=d[0],x=d[1];"kind"!==g&&(u+="".concat(l).concat(g,": ").concat(e(x,l),",\n"))}return u+=t+"}"}if("function"==typeof n.toJSON)return e(n.toJSON(),t);for(var h="{\n",y=t+" ",v=0,w=Object.entries(n);v<w.length;v++){var b=w[v],m=b[0],W=b[1];h+="".concat(y).concat(JSON.stringify(m),": ").concat(e(W,y),",\n")}return h+=t+"}";case"string":case"number":case"boolean":return JSON.stringify(n,null,2).replace("\n","\n"+t);default:throw new Error("printAST doesn't handle values where "+"typeof value === '".concat(typeof n,"'."))}}(e,"")}},function(e,n){e.exports=require("@babel/runtime/helpers/createForOfIteratorHelper")},function(e,n,t){"use strict";e.exports=function e(n){if(Array.isArray(n))return n.map(e);if(null!=n&&"object"==typeof n){var t={};for(var r in n)t[r]=e(n[r]);return t}return n}},function(e,n,t){"use strict";e.exports=function(e){var n=new Map,t=jest.fn((function(e){var t,r=null!==(t=n.get(e))&&void 0!==t?t:NaN;1===r?n.delete(e):n.set(e,r-1)}));return e.retain=jest.fn((function(e){var r,o=e.request.identifier,i=null!==(r=n.get(o))&&void 0!==r?r:0;n.set(o,i+1);var c=!1;return{dispose:function(){c||t(o),c=!0}}})),{release_DEPRECATED:t,isOperationRetained:function(e){var t,r=e.request.identifier;return(null!==(t=n.get(r))&&void 0!==t?t:0)>0}}}},function(e,n,t){"use strict";var r=(0,t(1).createConsoleInterceptionSystem)("warning","expectToWarn",(function(e){jest.mock("fbjs/lib/warning",(function(){return jest.fn((function(n,t){for(var r=arguments.length,o=new Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];if(!n){var c=0,a=t.replace(/%s/g,(function(){return String(o[c++])}));e(a)}}))}))}));e.exports={disallowWarnings:function(){r.disallowMessages()},expectWarningWillFire:function(e,n){r.expectMessageWillFire(e,n)},expectToWarn:function(e,n){return r.expectMessage(e,n)},expectToWarnMany:function(e,n){return r.expectMessageMany(e,n)}}},function(e,n){e.exports=require("relay-test-utils")}]);
|
package/simpleClone.js.flow
CHANGED
@@ -22,7 +22,7 @@ function simpleClone<T>(value: T): T {
|
|
22
22
|
// $FlowFixMe[incompatible-return]
|
23
23
|
return value.map(simpleClone);
|
24
24
|
} else if (value != null && typeof value === 'object') {
|
25
|
-
const result = {};
|
25
|
+
const result: {[string]: mixed} = {};
|
26
26
|
for (const key in value) {
|
27
27
|
result[key] = simpleClone(value[key]);
|
28
28
|
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
* @flow
|
8
|
+
* @format
|
9
|
+
*/
|
10
|
+
|
11
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
|
13
|
+
'use strict';
|
14
|
+
|
15
|
+
/* global jest */
|
16
|
+
|
17
|
+
import type {IEnvironment} from '../relay-runtime';
|
18
|
+
import type {OperationDescriptor} from '../relay-runtime/store/RelayStoreTypes';
|
19
|
+
|
20
|
+
/**
|
21
|
+
* Takes an environment and augments it with a mock implementation of `retain`
|
22
|
+
* that tracks what operations are currently retained. Also returns the Jest mock
|
23
|
+
* `release` function for backwards-compatibility with existing tests, but you
|
24
|
+
* should use `isOperationRetained` for new tests as it is much less error-prone.
|
25
|
+
*/
|
26
|
+
function trackRetentionForEnvironment(environment: IEnvironment): {|
|
27
|
+
release_DEPRECATED: JestMockFn<[mixed], void>,
|
28
|
+
isOperationRetained: OperationDescriptor => boolean,
|
29
|
+
|} {
|
30
|
+
const retainCountsByOperation = new Map();
|
31
|
+
|
32
|
+
const release = jest.fn(id => {
|
33
|
+
const existing = retainCountsByOperation.get(id) ?? NaN;
|
34
|
+
if (existing === 1) {
|
35
|
+
retainCountsByOperation.delete(id);
|
36
|
+
} else {
|
37
|
+
retainCountsByOperation.set(id, existing - 1);
|
38
|
+
}
|
39
|
+
});
|
40
|
+
|
41
|
+
// $FlowFixMe[cannot-write] safe to do for mocking
|
42
|
+
environment.retain = jest.fn(operation => {
|
43
|
+
const id = operation.request.identifier;
|
44
|
+
const existing = retainCountsByOperation.get(id) ?? 0;
|
45
|
+
retainCountsByOperation.set(id, existing + 1);
|
46
|
+
let released = false;
|
47
|
+
return {
|
48
|
+
dispose: () => {
|
49
|
+
if (!released) {
|
50
|
+
release(id);
|
51
|
+
}
|
52
|
+
released = true;
|
53
|
+
},
|
54
|
+
};
|
55
|
+
});
|
56
|
+
|
57
|
+
function isOperationRetained(operation: OperationDescriptor) {
|
58
|
+
const id = operation.request.identifier;
|
59
|
+
return (retainCountsByOperation.get(id) ?? 0) > 0;
|
60
|
+
}
|
61
|
+
|
62
|
+
return {release_DEPRECATED: release, isOperationRetained};
|
63
|
+
}
|
64
|
+
|
65
|
+
module.exports = trackRetentionForEnvironment;
|
package/warnings.js.flow
CHANGED
@@ -11,11 +11,27 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
/* global jest
|
14
|
+
/* global jest */
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
const
|
16
|
+
import type {WillFireOptions} from './consoleErrorsAndWarnings';
|
17
|
+
|
18
|
+
const {createConsoleInterceptionSystem} = require('./consoleErrorsAndWarnings');
|
19
|
+
|
20
|
+
const warningsSystem = createConsoleInterceptionSystem(
|
21
|
+
'warning',
|
22
|
+
'expectToWarn',
|
23
|
+
impl => {
|
24
|
+
jest.mock('warning', () =>
|
25
|
+
jest.fn((condition, format, ...args) => {
|
26
|
+
if (!condition) {
|
27
|
+
let argIndex = 0;
|
28
|
+
const message = format.replace(/%s/g, () => String(args[argIndex++]));
|
29
|
+
impl(message);
|
30
|
+
}
|
31
|
+
}),
|
32
|
+
);
|
33
|
+
},
|
34
|
+
);
|
19
35
|
|
20
36
|
/**
|
21
37
|
* Mocks the `warning` module to turn warnings into errors. Any expected
|
@@ -25,64 +41,25 @@ const contextualExpectedWarning: Array<string> = [];
|
|
25
41
|
* use `jest.resetModules()` or manually mock `warning`.
|
26
42
|
*/
|
27
43
|
function disallowWarnings(): void {
|
28
|
-
|
29
|
-
throw new Error('`disallowWarnings` should be called at most once');
|
30
|
-
}
|
31
|
-
installed = true;
|
32
|
-
jest.mock('warning', () => {
|
33
|
-
return jest.fn((condition, format, ...args) => {
|
34
|
-
if (!condition) {
|
35
|
-
let argIndex = 0;
|
36
|
-
const message = format.replace(/%s/g, () => String(args[argIndex++]));
|
37
|
-
const index = expectedWarnings.indexOf(message);
|
38
|
-
|
39
|
-
if (
|
40
|
-
contextualExpectedWarning.length > 0 &&
|
41
|
-
contextualExpectedWarning[0] === message
|
42
|
-
) {
|
43
|
-
contextualExpectedWarning.shift();
|
44
|
-
} else if (index >= 0) {
|
45
|
-
expectedWarnings.splice(index, 1);
|
46
|
-
} else {
|
47
|
-
// log to console in case the error gets swallowed somewhere
|
48
|
-
console.error('Unexpected Warning: ' + message);
|
49
|
-
throw new Error('Warning: ' + message);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
});
|
53
|
-
});
|
54
|
-
afterEach(() => {
|
55
|
-
contextualExpectedWarning.length = 0;
|
56
|
-
if (expectedWarnings.length > 0) {
|
57
|
-
const error = new Error(
|
58
|
-
'Some expected warnings where not triggered:\n\n' +
|
59
|
-
Array.from(expectedWarnings, message => ` * ${message}`).join('\n') +
|
60
|
-
'\n',
|
61
|
-
);
|
62
|
-
expectedWarnings.length = 0;
|
63
|
-
throw error;
|
64
|
-
}
|
65
|
-
});
|
44
|
+
warningsSystem.disallowMessages();
|
66
45
|
}
|
67
46
|
|
68
47
|
/**
|
69
48
|
* Expect a warning with the given message. If the message isn't fired in the
|
70
49
|
* current test, the test will fail.
|
71
50
|
*/
|
72
|
-
function expectWarningWillFire(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
78
|
-
expectedWarnings.push(message);
|
51
|
+
function expectWarningWillFire(
|
52
|
+
message: string,
|
53
|
+
options?: WillFireOptions,
|
54
|
+
): void {
|
55
|
+
warningsSystem.expectMessageWillFire(message, options);
|
79
56
|
}
|
80
57
|
|
81
58
|
/**
|
82
59
|
* Expect the callback `fn` to trigger the warning message and otherwise fail.
|
83
60
|
*/
|
84
61
|
function expectToWarn<T>(message: string, fn: () => T): T {
|
85
|
-
return
|
62
|
+
return warningsSystem.expectMessage(message, fn);
|
86
63
|
}
|
87
64
|
|
88
65
|
/**
|
@@ -90,17 +67,7 @@ function expectToWarn<T>(message: string, fn: () => T): T {
|
|
90
67
|
* or otherwise fail.
|
91
68
|
*/
|
92
69
|
function expectToWarnMany<T>(messages: Array<string>, fn: () => T): T {
|
93
|
-
|
94
|
-
throw new Error('Cannot nest `expectToWarn()` calls.');
|
95
|
-
}
|
96
|
-
contextualExpectedWarning.push(...messages);
|
97
|
-
const result = fn();
|
98
|
-
if (contextualExpectedWarning.length > 0) {
|
99
|
-
const notFired = contextualExpectedWarning.toString();
|
100
|
-
contextualExpectedWarning.length = 0;
|
101
|
-
throw new Error(`Expected callback to warn: ${notFired}`);
|
102
|
-
}
|
103
|
-
return result;
|
70
|
+
return warningsSystem.expectMessageMany(messages, fn);
|
104
71
|
}
|
105
72
|
|
106
73
|
module.exports = {
|