diff --git a/.prettierignore b/.prettierignore index a0cca8ad07..db6c48a736 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,14 @@ -**/dist -**/build -**/buildServer -**/buildClient +# Ignore all files by default +* +# Allow docs in complete-react-case to be checked +!complete-react-case/**/*.md +# Allow runtime plugin to be checked +!runtime-plugins/remote-control/app1/pick-remote.js +# Allow test files and config +!test/index.spec.js +!jest.config.cjs +# Ignore build artifacts inside included folders +complete-react-case/**/dist +complete-react-case/**/build +complete-react-case/**/buildServer +complete-react-case/**/buildClient diff --git a/complete-react-case/README.md b/complete-react-case/README.md index 9d31994f5c..75e1f85bf4 100644 --- a/complete-react-case/README.md +++ b/complete-react-case/README.md @@ -10,7 +10,7 @@ A complete Webpack Module Federation Case with React. It is a low-level or basic app, which exposes libraries like `react`, `react-dom`. -It is a pure `remote` +It is a pure `remote`. ## component-app @@ -20,7 +20,7 @@ It is both host and remote. ## main-app -the top-level app, which depends on `lib-app` and `component-app`. +The top-level app, which depends on `lib-app` and `component-app`. It is a pure host. @@ -29,12 +29,12 @@ It is a pure host. - `pnpm install` - `pnpm run start` -after all the commands done, open your browser at `http://localhost:3002`, open the dev-tool's network tab to see resources loading details +After running these commands, open your browser at `http://localhost:3002` and open the DevTools network tab to see resource loading details. # Running Cypress E2E Tests -To run tests in interactive mode, run `npm run cypress:debug` from the root directory of the project. It will open Cypress Test Runner and allow to run tests in interactive mode. [More info about "How to run tests"](../../cypress-e2e/README.md#how-to-run-tests) +To run tests in interactive mode, run `pnpm run cypress:debug` from the root directory of the project. It will open Cypress Test Runner and allow tests to run in interactive mode. [More info about "How to run tests"](../../cypress-e2e/README.md#how-to-run-tests) -To build app and run test in headless mode, run `yarn e2e:ci`. It will build app and run tests for this workspace in headless mode. If tets failed cypress will create `cypress` directory in sample root folder with screenshots and videos. +To build the app and run tests in headless mode, run `pnpm run e2e:ci`. It will build the app and run tests for this workspace in headless mode. If tests fail, Cypress will create a `cypress` directory in the sample root folder with screenshots and videos. -["Best Practices, Rules amd more interesting information here](../../cypress-e2e/README.md) +[Best practices, rules and more interesting information here](../../cypress-e2e/README.md) diff --git a/complete-react-case/README_zh-cn.md b/complete-react-case/README_zh-cn.md index 85d5da905c..4a28349c74 100644 --- a/complete-react-case/README_zh-cn.md +++ b/complete-react-case/README_zh-cn.md @@ -8,22 +8,28 @@ ## lib-app -底层 App,暴露了一些库模块:`react`,`react-dom`。它是一个纯粹的 remote +底层 App,暴露了一些库模块:`react`,`react-dom`。它是一个纯粹的 `remote`。 ## component-app 组件层 App,依赖`lib-app`暴露的`react`、`react-dom`模块,也暴露了一些组件如对话框`Dialog`、按钮`Button`给另一个 app:`main-app` -它既是 host 也是 remote +它既是 `host` 也是 `remote`。 ## main-app -上层 App,依赖`lib-app`和`component-app`应用。它也是一个纯粹 host。 +上层 App,依赖`lib-app`和`component-app`应用。它也是一个纯粹的 `host`。 # 如何使用 -- `npm install` -- `npx lerna bootstrap` -- `npm run start` +- `pnpm install` +- `pnpm run start` -执行完上述命令,打开浏览器,输入`http://localhost:3002` 查看页面结果。 +执行完上述命令,打开浏览器,输入 `http://localhost:3002` 查看页面结果。 + +# 运行 Cypress E2E 测试 + +- 在仓库根目录运行 `pnpm run cypress:debug` 可以以交互模式运行测试。想了解更多内容,可参阅[《如何运行测试》](../../cypress-e2e/README.md#how-to-run-tests)。 +- 构建应用并在无界面模式下运行测试,可执行 `pnpm run e2e:ci`。如果测试失败,Cypress 会在示例根目录下创建 `cypress` 目录,包含截图和视频。 + +[最佳实践、规则和更多信息请参阅](../../cypress-e2e/README.md) diff --git a/jest.config.cjs b/jest.config.cjs new file mode 100644 index 0000000000..b54c71fb5f --- /dev/null +++ b/jest.config.cjs @@ -0,0 +1,4 @@ +module.exports = { + testEnvironment: 'node', + roots: ['/test'], +}; diff --git a/package.json b/package.json index 061785f6be..c6d0e3619a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "submodules": "git pull --recurse-submodules", "prettier": "prettier --write \"**/*.{js,jsx,json,md,ts,tsx}\"", "prettier:check": "prettier --list-different \"**/*.{js,jsx,json,md,ts,tsx}\"", - "test": "jest test/index.spec.js --maxWorkers=2", + "test": "jest --config=jest.config.cjs --maxWorkers=2", "cypress:debug": "cypress open --e2e --config-file cypress-e2e/config/cypress.config.ts --browser=chrome", "cypress:run": "cypress run --config-file cypress-e2e/config/cypress.config.ts --browser=chrome", "report:generate": "allure generate ./cypress/results/allure-results --clean -o ./cypress/report", diff --git a/runtime-plugins/remote-control/app1/pick-remote.js b/runtime-plugins/remote-control/app1/pick-remote.js index ef5e19e69a..6438cbf4d6 100644 --- a/runtime-plugins/remote-control/app1/pick-remote.js +++ b/runtime-plugins/remote-control/app1/pick-remote.js @@ -8,7 +8,7 @@ const map = { app2: 'http://localhost:3003/remoteEntry.js', }; -const CustomPlugin = (): FederationRuntimePlugin => ({ +const CustomPlugin = () => ({ name: 'backend-remote-control', beforeInit: args => { store.name = args.options.name; diff --git a/test/index.spec.js b/test/index.spec.js new file mode 100644 index 0000000000..3fb1c23ad1 --- /dev/null +++ b/test/index.spec.js @@ -0,0 +1,5 @@ +const sum = (a, b) => a + b; + +test('basic arithmetic works', () => { + expect(sum(1, 2)).toBe(3); +});