@mui/internal-test-utils 2.0.16 → 2.0.18-canary.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/CHANGELOG.md +11 -3
- package/LICENSE +1 -1
- package/README.md +52 -6
- package/chaiPlugin.d.ts +0 -1
- package/chaiPlugin.js +47 -34
- package/components.js +2 -1
- package/configure.d.ts +9 -0
- package/configure.js +16 -0
- package/createDescribe.d.ts +10 -3
- package/createDescribe.js +11 -4
- package/createRenderer.d.ts +109 -107
- package/createRenderer.js +71 -52
- package/describeConformance.d.ts +1 -5
- package/describeConformance.js +13 -8
- package/env.d.ts +9 -1
- package/env.js +13 -3
- package/esm/chaiPlugin.d.ts +0 -1
- package/esm/chaiPlugin.js +46 -34
- package/esm/components.js +2 -1
- package/esm/configure.d.ts +9 -0
- package/esm/configure.js +9 -0
- package/esm/createDescribe.d.ts +10 -3
- package/esm/createDescribe.js +10 -2
- package/esm/createRenderer.d.ts +109 -107
- package/esm/createRenderer.js +53 -47
- package/esm/describeConformance.d.ts +1 -5
- package/esm/describeConformance.js +13 -8
- package/esm/env.d.ts +9 -1
- package/esm/env.js +11 -3
- package/esm/flushMicrotasks.d.ts +1 -1
- package/esm/flushMicrotasks.js +1 -1
- package/esm/index.d.ts +4 -12
- package/esm/index.js +6 -15
- package/esm/initMatchers.d.ts +5 -1
- package/esm/initMatchers.js +5 -2
- package/esm/setupVitest.d.ts +8 -1
- package/esm/setupVitest.js +87 -21
- package/flushMicrotasks.d.ts +1 -1
- package/flushMicrotasks.js +1 -1
- package/index.d.ts +4 -12
- package/index.js +13 -27
- package/initMatchers.d.ts +5 -1
- package/initMatchers.js +21 -2
- package/package.json +28 -17
- package/setupVitest.d.ts +8 -1
- package/setupVitest.js +93 -21
- package/createDOM.d.ts +0 -2
- package/createDOM.js +0 -49
- package/createRenderer.test.d.ts +0 -1
- package/esm/createDOM.d.ts +0 -2
- package/esm/createDOM.js +0 -47
- package/esm/createRenderer.test.d.ts +0 -1
- package/esm/fireDiscreteEvent.d.ts +0 -6
- package/esm/fireDiscreteEvent.js +0 -68
- package/esm/init.d.ts +0 -1
- package/esm/init.js +0 -13
- package/esm/initMatchers.test.d.ts +0 -1
- package/esm/reactMajor.d.ts +0 -2
- package/esm/reactMajor.js +0 -2
- package/esm/setup.d.ts +0 -1
- package/esm/setup.js +0 -8
- package/esm/setupVitestBrowser.d.ts +0 -1
- package/esm/setupVitestBrowser.js +0 -30
- package/fireDiscreteEvent.d.ts +0 -6
- package/fireDiscreteEvent.js +0 -79
- package/init.d.ts +0 -1
- package/init.js +0 -15
- package/initMatchers.test.d.ts +0 -1
- package/reactMajor.d.ts +0 -2
- package/reactMajor.js +0 -9
- package/setup.d.ts +0 -1
- package/setup.js +0 -10
- package/setupVitestBrowser.d.ts +0 -1
- package/setupVitestBrowser.js +0 -34
- /package/{chai.types.d.ts → chaiTypes.d.ts} +0 -0
- /package/{chai.types.js → chaiTypes.js} +0 -0
- /package/esm/{chai.types.d.ts → chaiTypes.d.ts} +0 -0
- /package/esm/{chai.types.js → chaiTypes.js} +0 -0
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MUI Public
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Mono-repository for the MUI organization with code that can be public.
|
|
4
|
+
See https://github.com/mui/mui-private for code that needs to be private.
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## Documentation
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
You can [read the Infra documentation here](./docs/README.md).
|
|
9
|
+
|
|
10
|
+
## Applications
|
|
11
|
+
|
|
12
|
+
### [tools-public.mui.com](https://tools-public.mui.com/)
|
|
13
|
+
|
|
14
|
+
- Folder: `/apps/tools-public/`
|
|
15
|
+
- Hosting: https://dashboard.render.com/web/srv-d08mooq4d50c73fso49g
|
|
16
|
+
- [Docs](./apps/tools-public/#readme)
|
|
17
|
+
|
|
18
|
+
Internal public Toolpad apps that run the operations of MUI, built using https://github.com/mui/toolpad.
|
|
19
|
+
|
|
20
|
+
### [Code infra dashboard](https://frontend-public.mui.com/)
|
|
21
|
+
|
|
22
|
+
- URL: [frontend-public.mui.com](https://frontend-public.mui.com/)
|
|
23
|
+
- Folder: `/apps/code-infra-dashboard/`
|
|
24
|
+
- Hosting: https://app.netlify.com/sites/mui-frontend-public/overview
|
|
25
|
+
- [Docs](./apps/code-infra-dashboard/#readme)
|
|
26
|
+
|
|
27
|
+
## Packages
|
|
28
|
+
|
|
29
|
+
### [docs-infra](./packages/docs-infra/)
|
|
30
|
+
|
|
31
|
+
- Folder: `/packages/docs-infra/`
|
|
32
|
+
- [Docs](./packages/docs-infra/README.md)
|
|
33
|
+
|
|
34
|
+
### [code-infra](./packages/code-infra/)
|
|
35
|
+
|
|
36
|
+
- Folder: `/packages/code-infra/`
|
|
37
|
+
- [Docs](./packages/code-infra/README.md)
|
|
38
|
+
|
|
39
|
+
## Versioning
|
|
40
|
+
|
|
41
|
+
Steps:
|
|
42
|
+
|
|
43
|
+
1. Checkout latest master
|
|
44
|
+
1. Run `pnpm release:prepare`
|
|
45
|
+
1. Run `pnpm release:version`
|
|
46
|
+
1. Open PR with the changes
|
|
47
|
+
|
|
48
|
+
## Publishing
|
|
49
|
+
|
|
50
|
+
Steps:
|
|
51
|
+
|
|
52
|
+
1. Merge versioning PR
|
|
53
|
+
1. Checkout release commit on master
|
|
54
|
+
1. Run `pnpm release:prepare`
|
|
55
|
+
1. Run `pnpm release:publish`
|
package/chaiPlugin.d.ts
CHANGED
package/chaiPlugin.js
CHANGED
|
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
|
-
var _pure = require("@testing-library/react/pure");
|
|
9
|
+
var _pure = require("@testing-library/react/pure.js");
|
|
10
10
|
var _domAccessibilityApi = require("dom-accessibility-api");
|
|
11
11
|
var _formatUtil = _interopRequireDefault(require("format-util"));
|
|
12
12
|
var _string = require("es-toolkit/string");
|
|
13
13
|
var _assertionError = require("assertion-error");
|
|
14
|
-
require("./chai.types");
|
|
15
14
|
var _env = require("./env");
|
|
15
|
+
// eslint-disable-next-line import/extensions
|
|
16
|
+
|
|
16
17
|
// chai#utils.elToString that looks like stringified elements in testing-library
|
|
17
18
|
function elementToString(element) {
|
|
18
19
|
if (typeof element?.nodeType === 'number') {
|
|
@@ -147,7 +148,7 @@ const chaiPlugin = (chaiAPI, utils) => {
|
|
|
147
148
|
chaiAPI.Assertion.addMethod('toHaveComputedStyle', function toHaveComputedStyle(expectedStyleUnnormalized) {
|
|
148
149
|
const element = utils.flag(this, 'object');
|
|
149
150
|
if (element?.nodeType !== 1) {
|
|
150
|
-
// Same pre-condition for negated and unnegated
|
|
151
|
+
// Same pre-condition for negated and unnegated assertion
|
|
151
152
|
throw new _assertionError.AssertionError(`Expected an Element but got ${String(element)}`);
|
|
152
153
|
}
|
|
153
154
|
const computedStyle = element.ownerDocument.defaultView.getComputedStyle(element);
|
|
@@ -166,19 +167,17 @@ const chaiPlugin = (chaiAPI, utils) => {
|
|
|
166
167
|
}
|
|
167
168
|
});
|
|
168
169
|
function addConsoleMatcher(matcherName, methodName) {
|
|
169
|
-
/**
|
|
170
|
-
* @param {string[]} expectedMessages
|
|
171
|
-
*/
|
|
172
170
|
function matcher(expectedMessagesInput = []) {
|
|
173
171
|
// documented pattern to get the actual value of the assertion
|
|
174
172
|
// eslint-disable-next-line no-underscore-dangle
|
|
175
173
|
const callback = this._obj;
|
|
176
174
|
if (process.env.NODE_ENV !== 'production') {
|
|
177
|
-
const expectedMessages =
|
|
175
|
+
const expectedMessages = Array.isArray(expectedMessagesInput) ? expectedMessagesInput.slice() : [expectedMessagesInput];
|
|
178
176
|
const unexpectedMessages = [];
|
|
179
177
|
// TODO Remove type once MUI X enables noImplicitAny
|
|
180
178
|
let caughtError = null;
|
|
181
|
-
|
|
179
|
+
let result = null;
|
|
180
|
+
this.assert(expectedMessages.length > 0, `Expected to call console.${methodName} but didn't provide messages. ` + `If you don't expect any messages prefer \`expect().not.${matcherName}();\`.`, `Expected no call to console.${methodName} while also expecting messages. ` + "If you want to make sure a certain message isn't logged prefer the positive. " + 'By expecting certain messages you automatically expect that no other messages are logged',
|
|
182
181
|
// Not interested in a diff but the typings require the 4th parameter.
|
|
183
182
|
undefined);
|
|
184
183
|
|
|
@@ -204,7 +203,7 @@ const chaiPlugin = (chaiAPI, utils) => {
|
|
|
204
203
|
let message = null;
|
|
205
204
|
if (expectedMessage === undefined) {
|
|
206
205
|
message = `Expected no more error messages but got:\n"${actualMessage}"`;
|
|
207
|
-
} else if (!actualMessage.includes(expectedMessage)) {
|
|
206
|
+
} else if (typeof expectedMessage === 'string' && !actualMessage.includes(expectedMessage) || expectedMessage instanceof RegExp && !expectedMessage.test(actualMessage)) {
|
|
208
207
|
message = `Expected #${messagesMatched} "${expectedMessage}" to be included in \n"${actualMessage}"`;
|
|
209
208
|
}
|
|
210
209
|
if (message !== null) {
|
|
@@ -225,13 +224,10 @@ const chaiPlugin = (chaiAPI, utils) => {
|
|
|
225
224
|
// eslint-disable-next-line no-console
|
|
226
225
|
console[methodName] = consoleMatcher;
|
|
227
226
|
try {
|
|
228
|
-
callback();
|
|
227
|
+
result = callback();
|
|
229
228
|
} catch (error) {
|
|
230
229
|
caughtError = error;
|
|
231
230
|
} finally {
|
|
232
|
-
// eslint-disable-next-line no-console
|
|
233
|
-
console[methodName] = originalMethod;
|
|
234
|
-
|
|
235
231
|
// unexpected thrown error takes precedence over unexpected console call
|
|
236
232
|
if (caughtError !== null) {
|
|
237
233
|
// not the same pattern as described in the block because we don't rethrow in the catch
|
|
@@ -248,31 +244,48 @@ const chaiPlugin = (chaiAPI, utils) => {
|
|
|
248
244
|
});
|
|
249
245
|
return `\n\n - ${formattedMessages.join('\n\n- ')}`;
|
|
250
246
|
};
|
|
251
|
-
const
|
|
247
|
+
const report = () => {
|
|
248
|
+
const shouldHaveWarned = utils.flag(this, 'negate') !== true;
|
|
252
249
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
250
|
+
// unreachable from expect().not.toWarnDev(messages)
|
|
251
|
+
if (unexpectedMessages.length > 0) {
|
|
252
|
+
const unexpectedMessageRecordedMessage = `Recorded unexpected console.${methodName} calls: ${formatMessages(unexpectedMessages)}`;
|
|
253
|
+
// chai will duplicate the stack frames from the unexpected calls in their assertion error
|
|
254
|
+
// it's not ideal but the test failure is located the second to last stack frame
|
|
255
|
+
// and the origin of the call is the second stackframe in the stack
|
|
256
|
+
this.assert(
|
|
257
|
+
// force chai to always trigger an assertion error
|
|
258
|
+
!shouldHaveWarned, unexpectedMessageRecordedMessage, unexpectedMessageRecordedMessage,
|
|
259
|
+
// Not interested in a diff but the typings require the 4th parameter.
|
|
260
|
+
undefined);
|
|
261
|
+
}
|
|
262
|
+
if (shouldHaveWarned) {
|
|
263
|
+
this.assert(remainingMessages.length === 0, `Could not match the following console.${methodName} calls. ` + `Make sure previous actions didn't call console.${methodName} by wrapping them in expect(() => {}).not.${matcherName}(): ${formatMessages(remainingMessages)}`, `Impossible state reached in \`expect().${matcherName}()\`. ` + `This is a bug in the matcher.`,
|
|
264
|
+
// Not interested in a diff but the typings require the 4th parameter.
|
|
265
|
+
undefined);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
if (result && typeof result === 'object' && 'then' in result && typeof result.then === 'function') {
|
|
269
|
+
// Handle async callbacks
|
|
270
|
+
result = Promise.resolve(result).then(value => {
|
|
271
|
+
report();
|
|
272
|
+
return value;
|
|
273
|
+
}).finally(() => {
|
|
274
|
+
// eslint-disable-next-line no-console
|
|
275
|
+
console[methodName] = originalMethod;
|
|
276
|
+
});
|
|
277
|
+
} else {
|
|
278
|
+
// eslint-disable-next-line no-console
|
|
279
|
+
console[methodName] = originalMethod;
|
|
280
|
+
report();
|
|
269
281
|
}
|
|
270
282
|
}
|
|
271
|
-
|
|
272
|
-
// nothing to do in prod
|
|
273
|
-
// If there are still console calls than our test setup throws.
|
|
274
|
-
callback();
|
|
283
|
+
return result;
|
|
275
284
|
}
|
|
285
|
+
|
|
286
|
+
// nothing to do in prod
|
|
287
|
+
// If there are still console calls than our test setup throws.
|
|
288
|
+
return callback();
|
|
276
289
|
}
|
|
277
290
|
chaiAPI.Assertion.addMethod(matcherName, matcher);
|
|
278
291
|
}
|
package/components.js
CHANGED
package/configure.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Configuration {
|
|
2
|
+
/**
|
|
3
|
+
* The emotion wrapper is optional.
|
|
4
|
+
* If your repository uses emotion, install `@emotion/react` and `@emotion/cache` and set this to true.
|
|
5
|
+
*/
|
|
6
|
+
emotion: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const config: Configuration;
|
|
9
|
+
export declare function configure(newConfig?: Partial<Configuration>): void;
|
package/configure.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.config = void 0;
|
|
7
|
+
exports.configure = configure;
|
|
8
|
+
const defaultConfig = {
|
|
9
|
+
emotion: false
|
|
10
|
+
};
|
|
11
|
+
const config = exports.config = {
|
|
12
|
+
...defaultConfig
|
|
13
|
+
};
|
|
14
|
+
function configure(newConfig = {}) {
|
|
15
|
+
Object.assign(config, newConfig);
|
|
16
|
+
}
|
package/createDescribe.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
type MUIDescribe<P extends any[]> = {
|
|
1
|
+
export type MUIDescribe<P extends any[]> = {
|
|
2
2
|
(...args: P): void;
|
|
3
3
|
skip: (...args: P) => void;
|
|
4
4
|
only: (...args: P) => void;
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Create a custom describe function with chainable skip and only methods.
|
|
8
|
+
* It is used to group conformance tests but still make the focusable/skippable.
|
|
9
|
+
*
|
|
10
|
+
* @param message - The message to display for the describe block.
|
|
11
|
+
* @param callback - The callback function containing the tests.
|
|
12
|
+
* @returns A custom describe function with skip and only methods.
|
|
13
|
+
*/
|
|
14
|
+
export default function createDescribe<P extends any[]>(message: string, callback: (...args: P) => void): MUIDescribe<P>;
|
package/createDescribe.js
CHANGED
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = createDescribe;
|
|
7
7
|
var _vitest = require("vitest");
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Create a custom describe function with chainable skip and only methods.
|
|
10
|
+
* It is used to group conformance tests but still make the focusable/skippable.
|
|
11
|
+
*
|
|
12
|
+
* @param message - The message to display for the describe block.
|
|
13
|
+
* @param callback - The callback function containing the tests.
|
|
14
|
+
* @returns A custom describe function with skip and only methods.
|
|
15
|
+
*/
|
|
16
|
+
function createDescribe(message, callback) {
|
|
9
17
|
const muiDescribe = (...args) => {
|
|
10
18
|
(0, _vitest.describe)(message, () => {
|
|
11
19
|
callback(...args);
|
|
@@ -22,5 +30,4 @@ var _default = (message, callback) => {
|
|
|
22
30
|
});
|
|
23
31
|
};
|
|
24
32
|
return muiDescribe;
|
|
25
|
-
}
|
|
26
|
-
exports.default = _default;
|
|
33
|
+
}
|