@modern-js/main-doc 2.52.0 → 2.54.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. package/docs/en/configure/app/server/ssr.mdx +2 -0
  2. package/docs/en/guides/advanced-features/bff/index.mdx +1 -1
  3. package/docs/en/guides/advanced-features/code-split.mdx +4 -4
  4. package/docs/en/guides/advanced-features/ssr/index.mdx +1 -0
  5. package/docs/en/guides/basic-features/routes.mdx +3 -3
  6. package/docs/en/guides/get-started/introduction.mdx +1 -1
  7. package/docs/en/guides/get-started/tech-stack.mdx +0 -6
  8. package/docs/en/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
  9. package/docs/en/guides/topic-detail/generator/create/config.mdx +0 -6
  10. package/docs/en/guides/topic-detail/generator/create/option.md +0 -5
  11. package/docs/en/guides/topic-detail/generator/create/use.mdx +1 -10
  12. package/docs/en/guides/topic-detail/generator/new/config.md +0 -29
  13. package/docs/en/guides/topic-detail/generator/new/use.md +1 -21
  14. package/docs/zh/configure/app/server/ssr.mdx +2 -0
  15. package/docs/zh/guides/advanced-features/bff/index.mdx +2 -2
  16. package/docs/zh/guides/advanced-features/code-split.mdx +5 -5
  17. package/docs/zh/guides/advanced-features/rspack-start.mdx +1 -1
  18. package/docs/zh/guides/advanced-features/ssr/index.mdx +2 -1
  19. package/docs/zh/guides/advanced-features/ssr/usage.mdx +2 -2
  20. package/docs/zh/guides/basic-features/data/data-fetch.mdx +2 -2
  21. package/docs/zh/guides/basic-features/data/data-write.mdx +1 -2
  22. package/docs/zh/guides/basic-features/mock.mdx +1 -1
  23. package/docs/zh/guides/basic-features/routes.mdx +6 -6
  24. package/docs/zh/guides/get-started/introduction.mdx +1 -1
  25. package/docs/zh/guides/get-started/tech-stack.mdx +0 -6
  26. package/docs/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
  27. package/docs/zh/guides/topic-detail/generator/create/config.mdx +0 -6
  28. package/docs/zh/guides/topic-detail/generator/create/option.md +0 -5
  29. package/docs/zh/guides/topic-detail/generator/create/use.mdx +1 -10
  30. package/docs/zh/guides/topic-detail/generator/new/config.md +0 -31
  31. package/docs/zh/guides/topic-detail/generator/new/use.md +1 -21
  32. package/package.json +5 -5
  33. package/docs/en/apis/app/runtime/testing/_category_.json +0 -4
  34. package/docs/en/apis/app/runtime/testing/act.mdx +0 -35
  35. package/docs/en/apis/app/runtime/testing/cleanup.mdx +0 -40
  36. package/docs/en/apis/app/runtime/testing/render.mdx +0 -71
  37. package/docs/en/apis/app/runtime/testing/renderApp.mdx +0 -34
  38. package/docs/en/configure/app/testing/_category_.json +0 -4
  39. package/docs/en/configure/app/testing/transformer.mdx +0 -17
  40. package/docs/en/configure/app/tools/jest.mdx +0 -40
  41. package/docs/en/guides/advanced-features/testing.mdx +0 -47
  42. package/docs/en/guides/topic-detail/changesets/_category_.json +0 -4
  43. package/docs/en/guides/topic-detail/changesets/add.mdx +0 -125
  44. package/docs/en/guides/topic-detail/changesets/changelog.mdx +0 -238
  45. package/docs/en/guides/topic-detail/changesets/commit.mdx +0 -269
  46. package/docs/en/guides/topic-detail/changesets/config.mdx +0 -147
  47. package/docs/en/guides/topic-detail/changesets/github.mdx +0 -175
  48. package/docs/en/guides/topic-detail/changesets/introduce.mdx +0 -56
  49. package/docs/en/guides/topic-detail/changesets/release-note.mdx +0 -274
  50. package/docs/en/guides/topic-detail/changesets/release-pre.mdx +0 -49
  51. package/docs/en/guides/topic-detail/changesets/release.mdx +0 -229
  52. package/docs/en/guides/topic-detail/model/test-model.mdx +0 -45
  53. package/docs/zh/apis/app/runtime/testing/_category_.json +0 -4
  54. package/docs/zh/apis/app/runtime/testing/act.mdx +0 -35
  55. package/docs/zh/apis/app/runtime/testing/cleanup.mdx +0 -40
  56. package/docs/zh/apis/app/runtime/testing/render.mdx +0 -71
  57. package/docs/zh/apis/app/runtime/testing/renderApp.mdx +0 -32
  58. package/docs/zh/configure/app/testing/_category_.json +0 -4
  59. package/docs/zh/configure/app/testing/transformer.mdx +0 -19
  60. package/docs/zh/configure/app/tools/jest.mdx +0 -40
  61. package/docs/zh/guides/advanced-features/testing.mdx +0 -47
  62. package/docs/zh/guides/topic-detail/changesets/_category_.json +0 -4
  63. package/docs/zh/guides/topic-detail/changesets/add.mdx +0 -126
  64. package/docs/zh/guides/topic-detail/changesets/changelog.mdx +0 -238
  65. package/docs/zh/guides/topic-detail/changesets/commit.mdx +0 -269
  66. package/docs/zh/guides/topic-detail/changesets/config.mdx +0 -147
  67. package/docs/zh/guides/topic-detail/changesets/github.mdx +0 -175
  68. package/docs/zh/guides/topic-detail/changesets/introduce.mdx +0 -56
  69. package/docs/zh/guides/topic-detail/changesets/release-note.mdx +0 -274
  70. package/docs/zh/guides/topic-detail/changesets/release-pre.mdx +0 -50
  71. package/docs/zh/guides/topic-detail/changesets/release.mdx +0 -231
  72. package/docs/zh/guides/topic-detail/model/test-model.mdx +0 -45
  73. package/docs/zh/guides/topic-detail/monorepo/_category_.json +0 -4
  74. package/docs/zh/guides/topic-detail/monorepo/create-sub-project.mdx +0 -53
  75. package/docs/zh/guides/topic-detail/monorepo/intro.mdx +0 -14
  76. package/docs/zh/guides/topic-detail/monorepo/publish.mdx +0 -69
  77. package/docs/zh/guides/topic-detail/monorepo/sub-project-interface.mdx +0 -143
package/package.json CHANGED
@@ -15,17 +15,17 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.52.0",
18
+ "version": "2.54.0",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org/",
21
21
  "access": "public",
22
22
  "provenance": true
23
23
  },
24
24
  "dependencies": {
25
- "@modern-js/sandpack-react": "2.52.0"
25
+ "@modern-js/sandpack-react": "2.54.0"
26
26
  },
27
27
  "peerDependencies": {
28
- "@modern-js/builder-doc": "^2.52.0"
28
+ "@modern-js/builder-doc": "^2.54.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "classnames": "^2",
@@ -39,8 +39,8 @@
39
39
  "@rspress/shared": "1.18.2",
40
40
  "@types/node": "^16",
41
41
  "@types/fs-extra": "9.0.13",
42
- "@modern-js/builder-doc": "2.52.0",
43
- "@modern-js/doc-plugin-auto-sidebar": "2.52.0"
42
+ "@modern-js/doc-plugin-auto-sidebar": "2.54.0",
43
+ "@modern-js/builder-doc": "2.54.0"
44
44
  },
45
45
  "scripts": {
46
46
  "dev": "rspress dev",
@@ -1,4 +0,0 @@
1
- {
2
- "label": "Testing API",
3
- "position": 11
4
- }
@@ -1,35 +0,0 @@
1
- ---
2
- title: act
3
- ---
4
- # act
5
-
6
- Used to ensure that behaviors such as rendering, events, data fetching, etc. have been applied to the DOM.
7
-
8
- ## Usage
9
-
10
- ```ts
11
- import { act } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- ## Function Signature
15
-
16
- `act` is the same as [react-dom/test-utils act function](https://reactjs.org/docs/testing-recipes.html#act).
17
-
18
- ## Example
19
-
20
- ```tsx
21
- import ReactDOM from 'react-dom';
22
- import { act } from '@modern-js/runtime/testing';
23
- import { Foo } from '@/components/Foo';
24
-
25
- describe('test act', () => {
26
- it('it should be foo', () => {
27
- const el = document.createElement('div');
28
- act(() => {
29
- ReactDOM.render(<Foo />, el);
30
- });
31
-
32
- expect(el.innerHTML).toBe('<div>Foo</div>');
33
- });
34
- });
35
- ```
@@ -1,40 +0,0 @@
1
- ---
2
- title: cleanup
3
- sidebar_position: 3
4
- ---
5
- # cleanup
6
-
7
- Used to uninstall all currently rendered components.
8
-
9
- ## Usage
10
-
11
- ```ts
12
- import { cleanup } from '@modenr-js/runtime/testing';
13
- ```
14
-
15
- ## Function Signature
16
-
17
- `function cleanup(): void`
18
-
19
- ## Example
20
-
21
- :::info
22
- Note that if you are using a testing framework that supports afterEach and it is injected into your testing environment (such as mocha, Jest, and Jasmine), **will execute `cleanup`** in the afterEach hook by default. Otherwise, you will need to do manual cleanup after each test.
23
-
24
- :::
25
-
26
- For example, if you use the [ava](https://github.com/avajs/ava) test framework, then you need to use the `test.after Each` hook like this.
27
-
28
- ```tsx
29
- import { cleanup, render } from '@modern-js/runtime/testing';
30
- import test from 'ava';
31
-
32
- test.afterEach(cleanup);
33
-
34
- test('renders into document', () => {
35
- render(<div />);
36
- // ...
37
- });
38
-
39
- // ... more tests ...
40
- ```
@@ -1,71 +0,0 @@
1
- ---
2
- title: render
3
- ---
4
- # render
5
-
6
- Used to render the component in the test case.
7
-
8
- ## Usage
9
-
10
- ```ts
11
- import { render } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- ## Function Signature
15
-
16
- ```ts
17
- type Options = {
18
- container: DOMElement;
19
- baseElement: DOMElement;
20
- hydrate: boolean;
21
- warpper: React.ComponentType<{children: ReactNode}>;
22
- queries: any;
23
- };
24
-
25
- type RenderResult = {
26
- {...queries}: any;
27
- container: DOMElement;
28
- baseElement: DOMElement;
29
- debug: function;
30
- rerender: function;
31
- unmount: function;
32
- asFragment: function;
33
- }
34
-
35
- function render(ui: React.ReactElement<any>, options: Options): RenderResult;
36
- ```
37
-
38
- ### Input
39
-
40
- - `ui`: the React component that needs to be rendered.
41
- - `options`: render options.
42
- - `container`: the dom which component mounted. by default create a `div` element, and auto append to `document.body`. the default value is `document.body.append(document.createElement('div'))`.
43
- - `baseElement`: Used to specify the `basename` used in `queries`. If `container` is specified, the default value is the value of `container`, otherwise it is `document.body`.
44
- - `hydrate`: If set to `true`, the [ReactDOM.hydrate](https://react.dev/reference/react-dom/hydrate) rendering component is used. The default value is `false`.
45
- - `wrapper`: a react component that can be used to customize rendering logic.
46
- - `queries`: customize some own `queries`.
47
-
48
- ### Return Value
49
-
50
- - `{...queries}`: all available [queries](https://testing-library.com/docs/queries/about/).
51
- - `container`: the DOM element that React component mounted.
52
- - `baseElement`
53
- - `debug`
54
- - `rerender`: if you want to test some scene when a rendered component is updated, you can use rerender for reality.
55
- - `unmount`: unmount rendered components. This API is helpful if you want to test what happens after the component is unmounted.
56
- - `asFragment`: return the [DocumentFragment](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment) of rendered component. used to test the response of the DOM structure after the react event is triggered.
57
-
58
- ## Example
59
-
60
- ```ts
61
- import { render } from '@modern-js/runtime/testing';
62
- import App from './App';
63
-
64
- test('renders a message', () => {
65
- const { container, getByText } = render(<App />);
66
- expect(getByText('Hello, world!')).toBeInTheDocument();
67
- expect(container.firstChild).toMatchInlineSnapshot(`
68
- <h1>Hello, World!</h1>
69
- `);
70
- });
71
- ```
@@ -1,34 +0,0 @@
1
- ---
2
- title: renderApp
3
- ---
4
- # renderApp
5
-
6
- The `render` function is used to test normal components, and the `renderApp` function is used to test App components.
7
-
8
- ## Usage
9
-
10
- ```ts
11
- import { renderApp } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- App components refer to components that contain some Modern.js contexts, such as App root components, Containers using Models, etc.
15
-
16
- For the testing of such components, you can use the `renderApp` function, which will automatically wrap the context information according to the current `modern.config.js`.
17
-
18
- ## Function Signature
19
-
20
- `renderApp` is the same as [render](./render.mdx).
21
-
22
- ## Example
23
-
24
- ```ts
25
- import { renderApp } from '@modern-js/runtime/testing';
26
- import App from './App';
27
-
28
- describe('test', () => {
29
- it('test App', () => {
30
- const { getByText } = renderApp(<App />);
31
- expect(getByText('Hello Modern!')).toBeInTheDocument();
32
- });
33
- });
34
- ```
@@ -1,4 +0,0 @@
1
- {
2
- "label": "testing",
3
- "position": 10
4
- }
@@ -1,17 +0,0 @@
1
- ---
2
- title: testing.transformer
3
- sidebar_label: transformer
4
- sidebar_position: 1
5
- ---
6
- # transformer
7
-
8
- - **Type:** `'babel-jest' | 'ts-jest'`
9
- - **Default:** `babel-jest`
10
-
11
- First need to run `new` command to enable [Unit Test / Integration Test] features.
12
-
13
- Configure the compilation tool used during test execution. By default, `babel-jest` is used. You can configure it to use either [babel-jest](https://www.npmjs.com/package/babel-jest) or [ts-jest](https://github.com/kulshekhar/ts-jest).
14
-
15
- :::info Additional
16
- `babel-jest` can compile TypeScript files but does not perform type checking. If you want to perform type checking on your TypeScript files while running test cases, you can use `ts-jest`.
17
- :::
@@ -1,40 +0,0 @@
1
- ---
2
- sidebar_label: jest
3
- ---
4
-
5
- # tools.jest
6
-
7
- - **Type:** `Object | Function`
8
- - **Default:** `{}`
9
-
10
- :::caution Caution
11
- First you need to enable the "Unit Test" function using [new](/apis/app/commands#modern-new) command.
12
-
13
- :::
14
-
15
- Corresponding to the configuration of [Jest](https://jestjs.io/docs/configuration), when of type `Object`, all underlying configurations supported by Jest can be configured.
16
-
17
- ```js title=modern.config.js
18
- export default defineConfig({
19
- tools: {
20
- jest: {
21
- testTimeout: 10000,
22
- },
23
- },
24
- });
25
- ```
26
-
27
- When the value is of type `Function`, the default configuration is passed in as the first parameter and a new Jest configuration object needs to be returned.
28
-
29
- ```js title=modern.config.js
30
- export default defineConfig({
31
- tools: {
32
- jest: options => {
33
- return {
34
- ...options,
35
- testTimeout: 10000,
36
- };
37
- },
38
- },
39
- });
40
- ```
@@ -1,47 +0,0 @@
1
- ---
2
- sidebar_position: 14
3
- ---
4
-
5
- # Using Jest
6
-
7
- Modern.js integrates the testing capabilities of [Jest](https://jestjs.io/) by default.
8
-
9
- First need to execute `pnpm run new` to enable "unit test/integration test" features:
10
-
11
- ```bash
12
- ? Please select the operation you want: Enable features
13
- ? Please select the feature name: Enable Unit Test / Integration Test
14
- ```
15
-
16
- After executing the above command, the `"test": "modern test"` command will be added in `package.json` automatically.
17
-
18
- After registering the `@modern-js/plugin-testing` plugin in `modern.config.ts`, you can use the testing features:
19
-
20
- ```ts title="modern.config.ts"
21
- import { testingPlugin } from '@modern-js/plugin-testing';
22
-
23
- export default defineConfig({
24
- plugins: [..., testingPlugin()],
25
- });
26
- ```
27
-
28
- ## Test file
29
-
30
- Modern.js default recognized test file paths are: `<rootDir>/src/**/*.test.[jt]s?(x)` and `<rootDir>/tests/**/*.test.[jt]s?(x)`.
31
-
32
- If you need to customize the test directory, you can configure it with [tools.jest](/configure/app/tools/jest).
33
-
34
- ## Usage
35
-
36
- Modern.js test support [testing-library](https://testing-library.com/docs/). API can be imported from `@modern-js/runtime/testing`.
37
-
38
- ```ts
39
- import { render, screen } from '@modern-js/runtime/testing';
40
- ```
41
-
42
- Other testing APIs supported by Modern.js can be referred to [here](/apis/app/runtime/testing/cleanup).
43
-
44
- ## transform
45
-
46
- By default, Modern.js testing uses [babel-jest](https://www.npmjs.com/package/babel-jest) for source code compilation. If you need to use [ts-jest](https://github.com/kulshekhar/ts-jest), you can configure it through [testing.transform](/configure/app/testing/transformer).
47
-
@@ -1,4 +0,0 @@
1
- {
2
- "label": "Package Version Management",
3
- "position": 5
4
- }
@@ -1,125 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # Add Changesets
6
-
7
- When we finish development, we need to add a changeset to declare the current changes for version releases.
8
-
9
- ## Information
10
-
11
- A changeset includes:
12
-
13
- - Which packages are affected by this change.
14
-
15
- - The type of version for this change, which complies with the [semver](https://semver.org/) specification.
16
-
17
- - Changelog information for this change.
18
-
19
- ## Steps
20
-
21
- :::info
22
- The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
23
- :::
24
-
25
- ### Modern.js Module
26
-
27
- #### Run the change command in the root directory:
28
-
29
- ```bash
30
- pnpm run change
31
- ```
32
-
33
- #### Select the type of version for this change
34
-
35
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-select-version.png)
36
-
37
- #### Fill in the changelog information
38
-
39
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-input-changelog.png)
40
-
41
- After running, a corresponding changeset file will be created in the `.changeset` directory of the project, and the file content is as follows:
42
-
43
- ```markdown
44
- ---
45
- 'module-changeset': patch
46
- ---
47
-
48
- feat: test module solution changeset
49
- ```
50
-
51
- This file contains all the information of the changeset.
52
-
53
- ### Monorepo
54
-
55
- There are three NPM module packages in the monorepo, `module-1`, `module-2`, and `module-3`.
56
-
57
- #### Run the change command in the root directory
58
-
59
- ```bash
60
- pnpm run change
61
- ```
62
-
63
- #### Select the list of packages to upgrade for this change
64
-
65
- Changesets will categorize the packages in the Monorepo into two categories, `changed packages` and `unchanged packages`, based on the current code changes (`git diff Head...baseBranch`), making it easy for users to choose.
66
-
67
- Use the space key to select the corresponding package or category, and then press Enter after the selection is completed:
68
-
69
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-select-packages.png)
70
-
71
- #### Select the packages corresponding to different version types
72
-
73
- Changesets will ask about the `major` and `minor` types. If there are packages that have not selected these two types, the `patch` type will be used by default.
74
-
75
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-auto-select-patch.png)
76
-
77
- #### Fill in the changelog information
78
-
79
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-input-changelog-monorepo.png)
80
-
81
- After running, a corresponding changeset file will be created in the `.changeset` directory of the project, and the file content is as follows:
82
-
83
- ```markdown
84
- ---
85
- 'module-2': minor
86
- 'module-3': patch
87
- ---
88
-
89
- feat: test-changeset
90
- ```
91
-
92
- This file contains all the information of the changeset, and different packages will be marked according to the selected version type.
93
-
94
- ## Parameters
95
-
96
- The `change` command supports the following parameters:
97
-
98
- - `--empty`: Adds an empty changeset.
99
-
100
- ```bash
101
- pnpm run change --empty
102
- ```
103
-
104
- After running, an empty changeset file will be created in the `.changeset` directory of the project, and the file content is as follows:
105
-
106
- ```markdown
107
- ---
108
- ---
109
- ```
110
-
111
- - `--open`: When using this parameter, the system default editor will be opened for filling in the changelog.
112
-
113
- ## Notes
114
-
115
- - Not all changes require changesets
116
-
117
- If the current change is to modify some infrastructure of the repository, such as CI, testing, etc., there is no need to add changesets, or an empty changeset can be added.
118
-
119
- - Multiple changesets can be submitted in one pull request
120
-
121
- When a pull request has multiple feature developments or bug fixes, multiple `pnpm run change` commands can be executed to add multiple changeset files. Each file selects the corresponding packages for the feature and adds change information.
122
-
123
- - When creating a changeset, all packages related to the feature need to be selected
124
-
125
- When creating a changeset in a Monorepo, all related packages to the feature need to be selected to avoid some packages not being published when releasing.