@modern-js/main-doc 2.52.0 → 2.53.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. package/docs/en/guides/basic-features/routes.mdx +2 -2
  2. package/docs/en/guides/get-started/tech-stack.mdx +0 -6
  3. package/docs/en/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
  4. package/docs/en/guides/topic-detail/generator/create/option.md +0 -5
  5. package/docs/en/guides/topic-detail/generator/create/use.mdx +1 -10
  6. package/docs/en/guides/topic-detail/generator/new/config.md +0 -29
  7. package/docs/en/guides/topic-detail/generator/new/use.md +0 -20
  8. package/docs/zh/guides/basic-features/routes.mdx +2 -2
  9. package/docs/zh/guides/get-started/tech-stack.mdx +0 -6
  10. package/docs/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
  11. package/docs/zh/guides/topic-detail/generator/create/option.md +0 -5
  12. package/docs/zh/guides/topic-detail/generator/create/use.mdx +1 -10
  13. package/docs/zh/guides/topic-detail/generator/new/config.md +0 -31
  14. package/docs/zh/guides/topic-detail/generator/new/use.md +0 -20
  15. package/package.json +5 -5
  16. package/docs/en/apis/app/runtime/testing/_category_.json +0 -4
  17. package/docs/en/apis/app/runtime/testing/act.mdx +0 -35
  18. package/docs/en/apis/app/runtime/testing/cleanup.mdx +0 -40
  19. package/docs/en/apis/app/runtime/testing/render.mdx +0 -71
  20. package/docs/en/apis/app/runtime/testing/renderApp.mdx +0 -34
  21. package/docs/en/configure/app/testing/_category_.json +0 -4
  22. package/docs/en/configure/app/testing/transformer.mdx +0 -17
  23. package/docs/en/configure/app/tools/jest.mdx +0 -40
  24. package/docs/en/guides/advanced-features/testing.mdx +0 -47
  25. package/docs/en/guides/topic-detail/changesets/_category_.json +0 -4
  26. package/docs/en/guides/topic-detail/changesets/add.mdx +0 -125
  27. package/docs/en/guides/topic-detail/changesets/changelog.mdx +0 -238
  28. package/docs/en/guides/topic-detail/changesets/commit.mdx +0 -269
  29. package/docs/en/guides/topic-detail/changesets/config.mdx +0 -147
  30. package/docs/en/guides/topic-detail/changesets/github.mdx +0 -175
  31. package/docs/en/guides/topic-detail/changesets/introduce.mdx +0 -56
  32. package/docs/en/guides/topic-detail/changesets/release-note.mdx +0 -274
  33. package/docs/en/guides/topic-detail/changesets/release-pre.mdx +0 -49
  34. package/docs/en/guides/topic-detail/changesets/release.mdx +0 -229
  35. package/docs/en/guides/topic-detail/model/test-model.mdx +0 -45
  36. package/docs/zh/apis/app/runtime/testing/_category_.json +0 -4
  37. package/docs/zh/apis/app/runtime/testing/act.mdx +0 -35
  38. package/docs/zh/apis/app/runtime/testing/cleanup.mdx +0 -40
  39. package/docs/zh/apis/app/runtime/testing/render.mdx +0 -71
  40. package/docs/zh/apis/app/runtime/testing/renderApp.mdx +0 -32
  41. package/docs/zh/configure/app/testing/_category_.json +0 -4
  42. package/docs/zh/configure/app/testing/transformer.mdx +0 -19
  43. package/docs/zh/configure/app/tools/jest.mdx +0 -40
  44. package/docs/zh/guides/advanced-features/testing.mdx +0 -47
  45. package/docs/zh/guides/topic-detail/changesets/_category_.json +0 -4
  46. package/docs/zh/guides/topic-detail/changesets/add.mdx +0 -126
  47. package/docs/zh/guides/topic-detail/changesets/changelog.mdx +0 -238
  48. package/docs/zh/guides/topic-detail/changesets/commit.mdx +0 -269
  49. package/docs/zh/guides/topic-detail/changesets/config.mdx +0 -147
  50. package/docs/zh/guides/topic-detail/changesets/github.mdx +0 -175
  51. package/docs/zh/guides/topic-detail/changesets/introduce.mdx +0 -56
  52. package/docs/zh/guides/topic-detail/changesets/release-note.mdx +0 -274
  53. package/docs/zh/guides/topic-detail/changesets/release-pre.mdx +0 -50
  54. package/docs/zh/guides/topic-detail/changesets/release.mdx +0 -231
  55. package/docs/zh/guides/topic-detail/model/test-model.mdx +0 -45
  56. package/docs/zh/guides/topic-detail/monorepo/_category_.json +0 -4
  57. package/docs/zh/guides/topic-detail/monorepo/create-sub-project.mdx +0 -53
  58. package/docs/zh/guides/topic-detail/monorepo/intro.mdx +0 -14
  59. package/docs/zh/guides/topic-detail/monorepo/publish.mdx +0 -69
  60. package/docs/zh/guides/topic-detail/monorepo/sub-project-interface.mdx +0 -143
@@ -1,229 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # Publishing Version
6
-
7
- When releasing a version, we need to upgrade the version of the corresponding packages based on the changeset generated during development, and run the publish command to publish them to NPM.
8
-
9
- ## Steps
10
-
11
- :::info
12
- The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
13
-
14
- :::
15
-
16
- ### Modern.js Module
17
-
18
- #### Run the bump command in the root directory
19
-
20
- ```bash
21
- pnpm run bump
22
- ```
23
-
24
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-module-bump.png)
25
-
26
- When running this command, changesets will automatically perform the following operations:
27
-
28
- - Delete all changeset files under the `.changesets` directory.
29
-
30
- - Upgrade the package version based on the changeset information.
31
-
32
- - Write changelog information to the `CHANGELOG.md` file in the root directory. The file will be automatically created if it does not exist.
33
-
34
- #### Confirm and submit the current changes
35
-
36
- ```bash
37
- git add .
38
- git commit -m "release: bump package"
39
- ```
40
-
41
- #### Run the release command in the root directory to publish the package to NPM
42
-
43
- ```bash
44
- pnpm run release
45
- ```
46
-
47
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-module-release.png)
48
-
49
- #### Push the tag to the remote repository
50
-
51
- ```bash
52
- git push --follow-tags
53
- ```
54
-
55
- ### Monorepo
56
-
57
- #### Run the bmp command in the root directory
58
-
59
- ```bash
60
- pnpm run bump
61
- ```
62
-
63
- ![](https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/changeset-monorepo-bump.png)
64
-
65
- When running this command, changesets will automatically perform the following operations:
66
-
67
- - Delete all changeset files under the `.changesets` directory.
68
-
69
- - Upgrade the version of the relevant packages based on the changeset information. In addition to the packages written in the changeset, changesets will also analyze the dependency graph of all packages in the Monorepo during running. If is required, the version will be automatically upgraded accordingly.
70
-
71
- - Write changelog to the `CHANGELOG.md` file in the directory of the package that needs to be upgraded. The file will be automatically created if it does not exist.
72
-
73
- #### Confirm and submit the current changes
74
-
75
- :::info
76
- Make sure that the automatically upgraded version meet the expected requirements. If you need to understand the version upgrade strategy, please refer to [Version Upgrade Strategy](/guides/topic-detail/changesets/release#version-upgrade-strategy).
77
- :::
78
-
79
- ```bash
80
- git add .
81
- git commit -m "release: bump package"
82
- ```
83
-
84
- #### Run the release command in the root directory to publish the package to NPM
85
-
86
- ```bash
87
- pnpm run release
88
- ```
89
-
90
- When running this command, it will sequentially determine whether the versions of all packages in the Monorepo exist on NPM. If they do not exist, the `publish` command will be run to publish them.
91
-
92
- :::warning
93
- When the dependencies between packages in the Monorepo are declared using workspace, do not directly run `npm publish` to publish the package in the corresponding subdirectory of the package. Use the `release` command instead. When publishing, the workspace declaration will be automatically removed to ensure that the NPM package is available after publishing.
94
- :::
95
-
96
- #### Push the tag to the remote repository
97
-
98
- ```bash
99
- git push --follow-tags
100
- ```
101
-
102
- ## Parameters
103
-
104
- ### Parameters for the `bump` command
105
-
106
- - `--snapshot`: Generates a timestamp-based version.
107
-
108
- ```bash
109
- pnpm run bump --snapshot canary
110
- ```
111
-
112
- After running, the corresponding upgraded version will become `0.0.0-canary-20220622092823`, and `canary` is the tag configured for snapshot. If not configured, it will directly generate the form of `0.0.0-20220622092823`.
113
-
114
- This parameter is mainly used to publish temporary test versions for testing and does not require code submission.
115
-
116
- - `--ignore`: Manually ignore some packages during publishing.
117
-
118
- For example, if you need to ignore the `module-2` package for this release:
119
-
120
- ```bash
121
- pnpm run bump --ignore module-2
122
- ```
123
-
124
- After running the command, the update of the `module-2` package will be ignored. Note that if there are packages that depend on `module-2`, the corresponding packages also need to be added to the `ignore` parameter, otherwise the `bump` command will fail.
125
-
126
- The usage for adding multiple packages is as follows:
127
-
128
- ```bash
129
- pnpm run bump --ignore module-2 --ignore module-3
130
- ```
131
-
132
- ### Parameters for the `release` command
133
-
134
- - `--otp`: Uses `npm token` to publish the package.
135
-
136
- ```bash
137
- pnpm run relese --otp <token>
138
- ```
139
-
140
- - `--tag`: Uses a specific tag for publishing, and `latest` is used by default.
141
-
142
- ```bash
143
- pnpm run release --tag <tag>
144
- ```
145
-
146
- - `--ignore-scripts`: Ignores npm scripts during publishing.
147
-
148
- When running the `publish` command, npm will automatically trigger many commands, such as `prepare` and `prepublish`. Using this parameter can ignore the running of these commands. This parameter is only supported in Monorepo using pnpm.
149
-
150
- ```bash
151
- pnpm run release --ignore-scripts
152
- ```
153
-
154
- - `--no-git-checks`: Ignores checking the current branch during publishing.
155
-
156
- By default, when running the `release` command, it will automatically check whether the current branch is a release branch, whether there are uncommitted changes, etc. Using this parameter can ignore git-related checks.
157
-
158
- ```bash
159
- pnpm run release --no-git-checks
160
- ```
161
-
162
- ## Version Upgrade Strategy
163
-
164
- ### dependencies or devDependencies
165
-
166
- - Only upgrade the patch version of the package itself for patch version
167
-
168
- For example, the following scenario exists:
169
-
170
- There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `dependencies` of `module-2`.
171
-
172
- The current changeset is the patch version upgrade of `module-1`.
173
-
174
- After running the `bump` command, only the patch version of `module-1` will be upgraded.
175
-
176
- - Upgrade the major or minor version of the package itself for major/minor version upgrades, and upgrade the patch version of the dependent packages
177
-
178
- For example, the following scenario exists:
179
-
180
- There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `dependencies` of `module-2`.
181
-
182
- The current changeset is the minor version upgrade of `module-1`.
183
-
184
- After running the `bump` command, `module-1` will upgrade the `minor` version, and `module-2` will upgrade the `patch` version number.
185
-
186
- ### peerDependencies
187
-
188
- - Upgrade the patch version of the package itself and the dependent package for patch version dependencies
189
-
190
- For example, the following scenario exists:
191
-
192
- There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `peerDependencies` of `module-2`.
193
-
194
- The current changeset is the patch version upgrade of `module-1`.
195
-
196
- After running the `bump` command, both `module-1` and `module-2` will upgrade the patch version.
197
-
198
- - Upgrade the major version of the dependent package for major/minor version upgrades of the package itself
199
-
200
- For example, the following scenario exists:
201
-
202
- There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `peerDependencies` of `module-2`.
203
-
204
- The current changeset is the minor version upgrade of `module-1`.
205
-
206
- After running the bump command, `module-1` will upgrade the `minor` version, and `module-2` will upgrade the `major` version number.
207
-
208
- - Modify the upgrade strategy for peerDependencies
209
-
210
- The upgrade strategy of `peerDependencies` can be modified by configuring `onlyUpdatePeerDependentsWhenOutOfRange`. When only the declared version type range is exceeded, the corresponding `peerDependencies` will be upgraded.
211
-
212
- ```json
213
- {
214
- "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
215
- "onlyUpdatePeerDependentsWhenOutOfRange": true
216
- },
217
- ...
218
- }
219
- ```
220
-
221
- For example, the following scenario exists:
222
-
223
- There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `peerDependencies` of `module-2`, and the version of `module-1` is declared using `^`.
224
-
225
- The current changeset is the patch or minor version upgrade of `module-1`.
226
-
227
- After running the `bump` command, only the version of `module-1` will be upgraded.
228
-
229
- Note that if the package version is in the `0.x.x` range, upgrading the `minor` version is also beyond the declared version type range.
@@ -1,45 +0,0 @@
1
- ---
2
- sidebar_position: 9
3
- title: Test Model
4
- ---
5
- # Test Model
6
-
7
- Testing is crucial for the stability of code. Here's an example using the `countModel` from [Quick Start](/guides/topic-detail/model/quick-start) to demonstrate how to perform unit testing on a Model in Modern.js.
8
-
9
- To use the testing feature, you need to first enable it. In the project root directory, execute `pnpm run new` and make the following selection:
10
-
11
- ```bash
12
- ? Please select the operation you want to perform: Enable optional features
13
- ? Enable optional features Enable "Unit Testing / Integration Testing" feature
14
- ```
15
-
16
- This will enable testing feature support.
17
-
18
- Create a new file called `count.test.ts` with the following code:
19
-
20
- ```ts
21
- import { createStore } from '@modern-js/runtime/testing';
22
- import countModel from './count';
23
-
24
- describe('test model', () => {
25
- it('count value should plus one after add', () => {
26
- const store = createStore();
27
- const [state, { add }] = store.use(countModel);
28
-
29
- expect(state).toEqual({ value: 1 });
30
-
31
- add();
32
-
33
- expect(store.use(countModel)[0]).toEqual({ value: 2 });
34
- });
35
- });
36
- ```
37
-
38
- :::info
39
- The [`createStore`](/apis/app/runtime/model/create-store) used here is imported from `@modern-js/runtime/testing`, which internally uses the configuration of [`runtime.state`](/configure/app/runtime/state) to create a `store`.
40
-
41
- :::
42
-
43
- In the test case, we create a new `store` to mount `countModel`, use `store.use` to get the State and Actions of `countModel`. Then, we call the `add` Action to update the state and assert the updated state value.
44
-
45
- Execute the `pnpm run test` command to trigger the execution of the test case.
@@ -1,4 +0,0 @@
1
- {
2
- "label": "Testing",
3
- "position": 11
4
- }
@@ -1,35 +0,0 @@
1
- ---
2
- title: act
3
- ---
4
- # act
5
-
6
- 用于确保渲染、事件、数据获取等行为已经应用在 DOM 上。
7
-
8
- ## 使用姿势
9
-
10
- ```ts
11
- import { act } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- ## 函数签名
15
-
16
- `act` 和 [react-dom/test-utils act 函数](https://reactjs.org/docs/testing-recipes.html#act) 是一致的。
17
-
18
- ## 示例
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
- 用于卸载掉当前已渲染的所有组件。
8
-
9
- ## 使用姿势
10
-
11
- ```ts
12
- import { cleanup } from '@modenr-js/runtime/testing';
13
- ```
14
-
15
- ## 函数签名
16
-
17
- `function cleanup(): void`
18
-
19
- ## 示例
20
-
21
- :::info
22
- 请注意,如果你使用的测试框架支持 afterEach,并且它被注入到你的测试环境中(如 mocha、Jest 和 Jasmine),**会默认在 afterEach 钩子里执行 `cleanup`**。否则,你将需要在每次测试后进行手动清理。
23
-
24
- :::
25
-
26
- 例如,如果你使用[ava](https://github.com/avajs/ava)测试框架,那么你需要像这样使用 test.afterEach 钩子。
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
- 用于在测试用例中渲染组件,完成测试。
7
-
8
- ## 使用姿势
9
-
10
- ```ts
11
- import { render } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- ## 函数签名
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
- ### 参数
39
-
40
- - `ui`:需要被渲染的 React 组件。
41
- - `options`:render 可选配置。
42
- - `container`:表示组件所要挂载到的 DOM 节点,默认是会创建一个 `div` 元素,并自动添加到 `document.body` 上。这个 `div` 元素就是组件要挂载的节点。默认值是 `document.body.append(document.createElement('div'))`。
43
- - `baseElement`:用于指定 `queries` 中使用到的 `basename`。如果指定了 `container`, 则默认值为 `container` 的值,否则就是 `document.body`。
44
- - `hydrate`:如果设置为 `true`,则会使用 [ReactDOM.hydrate](https://zh-hans.react.dev/reference/react-dom/hydrate) 渲染组件。默认值为 `false`。
45
- - `wrapper`:是一个 react 组件,可用于自定义渲染逻辑。
46
- - `queries`:自定义一些自己的 `queries`。
47
-
48
- ### 返回值
49
-
50
- - `{...queries}`:所有可用的 [queries](https://testing-library.com/docs/queries/about/)。
51
- - `container`:挂载 React 组件的 DOM 节点。
52
- - `baseElement`
53
- - `debug`
54
- - `rerender`:如果想测试一个已渲染的组件在其 props 更新时的一些场景,可以使用 rerender 来现实。
55
- - `unmount`:会卸载掉已渲染的组件。如果想测试组件卸载后的情况(如,绑定的事件是否在 unmount 阶段被卸载掉),那么这个 API 是很帮助的。
56
- - `asFragment`:返回当前渲染的组件的 [DocumentFragment](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment) 对象。可用于测试 react 事件触发后 DOM 结构的响应。
57
-
58
- ## 示例
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,32 +0,0 @@
1
- ---
2
- title: renderApp
3
- ---
4
- # renderApp
5
-
6
- `render` 函数用于测试普通组件,`renderApp` 函数用于测试应用组件。
7
-
8
- ## 使用姿势
9
-
10
- ```ts
11
- import { renderApp } from '@modern-js/runtime/testing';
12
- ```
13
-
14
- 应用组件指包含一些 Modern.js 上下文的组件,如 App 根组件,使用了 Model 的 Container 等。对于这类组件的测试,可以使用 `renderApp` 函数,会自动按照当前 `modern.config.js` 配置,包裹上对应的上下文信息。
15
-
16
- ## 函数签名
17
-
18
- `renderApp` 和 [render](./render.mdx) 完全一致。
19
-
20
- ## 示例
21
-
22
- ```ts
23
- import { renderApp } from '@modern-js/runtime/testing';
24
- import App from './App';
25
-
26
- describe('test', () => {
27
- it('test App', () => {
28
- const { getByText } = renderApp(<App />);
29
- expect(getByText('Hello Modern!')).toBeInTheDocument();
30
- });
31
- });
32
- ```
@@ -1,4 +0,0 @@
1
- {
2
- "label": "testing 测试",
3
- "position": 10
4
- }
@@ -1,19 +0,0 @@
1
- ---
2
- title: testing.transformer
3
- sidebar_label: transformer
4
- sidebar_position: 1
5
- ---
6
- # transformer
7
-
8
- - **类型:** `'babel-jest' | 'ts-jest'`
9
- - **默认值:** `babel-jest`
10
-
11
- :::caution Caution
12
- 请先在当前应用项目根目录使用 [new](/apis/app/commands#modern-new) 启用测试功能。
13
- :::
14
-
15
- 配置执行测试时的编译工具,默认使用 `babel-jest`。可配置为 [babel-jest](https://www.npmjs.com/package/babel-jest) 或 [ts-jest](https://github.com/kulshekhar/ts-jest)。
16
-
17
- :::info 补充信息
18
- `babel-jest` 可以编译 TS 文件,但没有类型校验。如果你希望运行测试用例的时,能对 TS 类型进行校验,可以使用 `ts-jest`。
19
- :::
@@ -1,40 +0,0 @@
1
- ---
2
- sidebar_label: jest
3
- ---
4
-
5
- # tools.jest
6
-
7
- - **类型:** `Object | Function`
8
- - **默认值:** `{}`
9
-
10
- :::caution 注意
11
- 需要先通过 `pnpm run new` 启用 单元测试 功能。
12
-
13
- :::
14
-
15
- 对应 [Jest](https://jestjs.io/docs/configuration) 的配置,当为 `Object` 类型时,可以配置 Jest 所支持的所有底层配置 。
16
-
17
- ```js title=modern.config.js
18
- export default defineConfig({
19
- tools: {
20
- jest: {
21
- testTimeout: 10000,
22
- },
23
- },
24
- });
25
- ```
26
-
27
- 值为 `Function` 类型时,默认配置作为第一个参数传入,需要返回新的 Jest 配置对象。
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
- # 使用 Jest 测试
6
-
7
- Modern.js 默认集成了 [Jest](https://jestjs.io/) 的测试能力。
8
-
9
- 我们首先需要执行 `pnpm run new` 启用「单元测试 / 集成测试」功能:
10
-
11
- ```bash
12
- ? 请选择你想要的操作 启用可选功能
13
- ? 请选择功能名称 启用「单元测试 / 集成测试」功能
14
- ```
15
-
16
- 执行上述命令后,`package.json` 中将会自动添加 `"test": "modern test"` 命令。
17
-
18
- 在 `modern.config.ts` 中注册 `@modern-js/plugin-testing` 插件后即可使用测试功能:
19
-
20
- ```ts title="modern.config.ts"
21
- import { testingPlugin } from '@modern-js/plugin-testing';
22
-
23
- export default defineConfig({
24
- ...,
25
- plugins: [..., testingPlugin()],
26
- });
27
- ```
28
-
29
- ## 测试文件
30
-
31
- Modern.js 默认识别的测试文件路径为:`<rootDir>/src/**/*.test.[jt]s?(x)` 和 `<rootDir>/tests/**/*.test.[jt]s?(x)`。
32
-
33
- 如果你需要自定义 test 目录,可通过 [tools.jest](/configure/app/tools/jest) 进行配置。
34
-
35
- ## 使用姿势
36
-
37
- Modern.js test 支持使用 [testing-library](https://testing-library.com/docs/) 相关包 API,可直接通过 `@modern-js/runtime/testing` 进行导入:
38
-
39
- ```ts
40
- import { render, screen } from '@modern-js/runtime/testing';
41
- ```
42
-
43
- 其他 Modern.js 支持的 testing API 可参考[这里](/apis/app/runtime/testing/cleanup)。
44
-
45
- ## transform
46
-
47
- Modern.js 测试默认使用 [babel-jest](https://www.npmjs.com/package/babel-jest) 进行源码编译,如果你需要使用 [ts-jest](https://github.com/kulshekhar/ts-jest),可以通过 [testing.transform](/configure/app/testing/transformer) 进行配置。
@@ -1,4 +0,0 @@
1
- {
2
- "label": "包版本管理",
3
- "position": 5
4
- }