@mui/internal-test-utils 2.0.16 → 2.0.18-canary.1

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +11 -3
  2. package/LICENSE +1 -1
  3. package/README.md +52 -6
  4. package/chaiPlugin.d.ts +0 -1
  5. package/chaiPlugin.js +47 -34
  6. package/components.js +2 -1
  7. package/configure.d.ts +9 -0
  8. package/configure.js +16 -0
  9. package/createDescribe.d.ts +10 -3
  10. package/createDescribe.js +11 -4
  11. package/createRenderer.d.ts +109 -107
  12. package/createRenderer.js +71 -52
  13. package/describeConformance.d.ts +1 -5
  14. package/describeConformance.js +13 -8
  15. package/env.d.ts +9 -1
  16. package/env.js +13 -3
  17. package/esm/chaiPlugin.d.ts +0 -1
  18. package/esm/chaiPlugin.js +46 -34
  19. package/esm/components.js +2 -1
  20. package/esm/configure.d.ts +9 -0
  21. package/esm/configure.js +9 -0
  22. package/esm/createDescribe.d.ts +10 -3
  23. package/esm/createDescribe.js +10 -2
  24. package/esm/createRenderer.d.ts +109 -107
  25. package/esm/createRenderer.js +53 -47
  26. package/esm/describeConformance.d.ts +1 -5
  27. package/esm/describeConformance.js +13 -8
  28. package/esm/env.d.ts +9 -1
  29. package/esm/env.js +11 -3
  30. package/esm/flushMicrotasks.d.ts +1 -1
  31. package/esm/flushMicrotasks.js +1 -1
  32. package/esm/index.d.ts +4 -12
  33. package/esm/index.js +6 -15
  34. package/esm/initMatchers.d.ts +5 -1
  35. package/esm/initMatchers.js +5 -2
  36. package/esm/setupVitest.d.ts +8 -1
  37. package/esm/setupVitest.js +87 -21
  38. package/flushMicrotasks.d.ts +1 -1
  39. package/flushMicrotasks.js +1 -1
  40. package/index.d.ts +4 -12
  41. package/index.js +13 -27
  42. package/initMatchers.d.ts +5 -1
  43. package/initMatchers.js +21 -2
  44. package/package.json +31 -20
  45. package/setupVitest.d.ts +8 -1
  46. package/setupVitest.js +93 -21
  47. package/createDOM.d.ts +0 -2
  48. package/createDOM.js +0 -49
  49. package/createRenderer.test.d.ts +0 -1
  50. package/esm/createDOM.d.ts +0 -2
  51. package/esm/createDOM.js +0 -47
  52. package/esm/createRenderer.test.d.ts +0 -1
  53. package/esm/fireDiscreteEvent.d.ts +0 -6
  54. package/esm/fireDiscreteEvent.js +0 -68
  55. package/esm/init.d.ts +0 -1
  56. package/esm/init.js +0 -13
  57. package/esm/initMatchers.test.d.ts +0 -1
  58. package/esm/reactMajor.d.ts +0 -2
  59. package/esm/reactMajor.js +0 -2
  60. package/esm/setup.d.ts +0 -1
  61. package/esm/setup.js +0 -8
  62. package/esm/setupVitestBrowser.d.ts +0 -1
  63. package/esm/setupVitestBrowser.js +0 -30
  64. package/fireDiscreteEvent.d.ts +0 -6
  65. package/fireDiscreteEvent.js +0 -79
  66. package/init.d.ts +0 -1
  67. package/init.js +0 -15
  68. package/initMatchers.test.d.ts +0 -1
  69. package/reactMajor.d.ts +0 -2
  70. package/reactMajor.js +0 -9
  71. package/setup.d.ts +0 -1
  72. package/setup.js +0 -10
  73. package/setupVitestBrowser.d.ts +0 -1
  74. package/setupVitestBrowser.js +0 -34
  75. /package/{chai.types.d.ts → chaiTypes.d.ts} +0 -0
  76. /package/{chai.types.js → chaiTypes.js} +0 -0
  77. /package/esm/{chai.types.d.ts → chaiTypes.d.ts} +0 -0
  78. /package/esm/{chai.types.js → chaiTypes.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
- # Changelog
1
+ # Versions
2
2
 
3
- ## 1.0.0
3
+ ## 2.0.8
4
4
 
5
- Initial release as an npm package.
5
+ Test release
6
+
7
+ ## 2.0.7
8
+
9
+ Test release
10
+
11
+ ## 2.0.6
12
+
13
+ Changelog start
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014 Call-Em-All
3
+ Copyright (c) 2019 Material-UI SAS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,9 +1,55 @@
1
- # @mui/internal-test-utils
1
+ # MUI Public
2
2
 
3
- This package contains test runner initialization functions and common tests shared between MUI packages.
4
- This is an internal package not meant for general use.
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
- ## Release
6
+ ## Documentation
7
7
 
8
- 1. Build the project: `pnpm build`
9
- 2. Publish the build artifacts to npm: `pnpm release:publish`
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
@@ -1,4 +1,3 @@
1
1
  import * as chai from 'chai';
2
- import "./chai.types.js";
3
2
  declare const chaiPlugin: Parameters<typeof chai.use>[0];
4
3
  export default chaiPlugin;
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 assertion
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 = typeof expectedMessagesInput === 'string' ? [expectedMessagesInput] : expectedMessagesInput.slice();
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
- 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.` + 'Expected no call to console.error but provided 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',
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 shouldHaveWarned = utils.flag(this, 'negate') !== true;
247
+ const report = () => {
248
+ const shouldHaveWarned = utils.flag(this, 'negate') !== true;
252
249
 
253
- // unreachable from expect().not.toWarnDev(messages)
254
- if (unexpectedMessages.length > 0) {
255
- const unexpectedMessageRecordedMessage = `Recorded unexpected console.${methodName} calls: ${formatMessages(unexpectedMessages)}`;
256
- // chai will duplicate the stack frames from the unexpected calls in their assertion error
257
- // it's not ideal but the test failure is located the second to last stack frame
258
- // and the origin of the call is the second stackframe in the stack
259
- this.assert(
260
- // force chai to always trigger an assertion error
261
- !shouldHaveWarned, unexpectedMessageRecordedMessage, unexpectedMessageRecordedMessage,
262
- // Not interested in a diff but the typings require the 4th parameter.
263
- undefined);
264
- }
265
- if (shouldHaveWarned) {
266
- 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.`,
267
- // Not interested in a diff but the typings require the 4th parameter.
268
- undefined);
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
- } else {
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
@@ -61,4 +61,5 @@ const RenderCounter = exports.RenderCounter = /*#__PURE__*/React.forwardRef(func
61
61
  },
62
62
  children: children
63
63
  });
64
- });
64
+ });
65
+ if (process.env.NODE_ENV !== "production") RenderCounter.displayName = "RenderCounter";
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
+ }
@@ -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
- declare const _default: <P extends any[]>(message: string, callback: (...args: P) => void) => MUIDescribe<P>;
7
- export default _default;
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 = void 0;
6
+ exports.default = createDescribe;
7
7
  var _vitest = require("vitest");
8
- var _default = (message, callback) => {
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
+ }