Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion .github/scripts/ci_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ def build_plan(paths: list[str], *, full: bool = False) -> dict[str, Any]: # no
projects.update((framework, target) for framework in FRAMEWORKS for target in ('web', 'mobile'))
browsers.update(FRAMEWORKS)
networks.update(FRAMEWORKS)
elif path.startswith('ruoyi-fastapi-test/frontend/'):
elif path.startswith('ruoyi-fastapi-test/frontend/mobile-'):
projects.update((framework, 'mobile') for framework in FRAMEWORKS)
elif path == 'ruoyi-fastapi-test/frontend/request-repeat-submit.mts':
projects.update((framework, 'web') for framework in FRAMEWORKS)
elif path.startswith('ruoyi-fastapi-test/frontend/'):
projects.update((framework, target) for framework in FRAMEWORKS for target in ('web', 'mobile'))
elif path.startswith('ruoyi-fastapi-test/time-contract/'):
projects.update((framework, target) for framework in FRAMEWORKS for target in ('web', 'mobile'))
database = True
Expand Down
13 changes: 12 additions & 1 deletion .github/tests/test_ci_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,27 @@ def test_frontend_ci_commands_exist_in_every_project(framework: str, target: str
"""矩阵中的工程必须实际提供工作流调用的测试和构建命令。"""
directory = ROOT / 'ruoyi-fastapi-frontend' / framework / target
package = json.loads((directory / 'package.json').read_text(encoding='utf-8'))
required = {'test:unit', 'test:contract'}
required = {'lint', 'typecheck:tests', 'test:unit', 'test:vitest', 'test:contract'}
required.update({'build:prod', 'build:docker'} if target == 'web' else {'build:h5', 'build:mp-weixin'})
assert package['packageManager'] == 'pnpm@11.28.6'
assert (directory / 'pnpm-workspace.yaml').is_file()
assert (directory / 'pnpm-lock.yaml').is_file()
assert (directory / 'eslint.config.mjs').is_file()
if framework == 'react' and target == 'mobile':
required.update({'check:platforms', 'build:rn:android', 'build:rn:ios'})
assert required <= package['scripts'].keys()


@pytest.mark.parametrize('framework', ['vue2', 'vue3', 'react'])
@pytest.mark.parametrize('target', ['web', 'mobile'])
def test_frontend_suites_follow_vitest_typescript_naming(framework: str, target: str) -> None:
"""所有前端测试套件均使用 Vitest 的 TypeScript 测试文件名。"""
directory = ROOT / 'ruoyi-fastapi-frontend' / framework / target / 'tests'
suites = [path for path in directory.rglob('*') if '.test.' in path.name or '.spec.' in path.name]
assert suites
assert [path for path in suites if not path.name.endswith(('.test.ts', '.test.tsx'))] == []


@pytest.mark.parametrize('framework', ['vue2', 'vue3'])
def test_web_svg_assets_match_across_frameworks(framework: str) -> None:
"""三端独立打包的 SVG 应有相同的相对路径和文件内容。"""
Expand Down
16 changes: 14 additions & 2 deletions .github/tests/test_ci_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def test_mobile_change_does_not_build_other_projects_or_web_e2e(framework: str)
@pytest.mark.parametrize(
'path',
[
'ruoyi-fastapi-test/frontend/mobile-harness.mjs',
'ruoyi-fastapi-test/frontend/mobile-behavior.mjs',
'ruoyi-fastapi-test/frontend/mobile-harness.mts',
'ruoyi-fastapi-test/frontend/mobile-behavior.mts',
],
)
def test_shared_mobile_harness_runs_all_mobile_projects(path: str) -> None:
Expand All @@ -120,6 +120,18 @@ def test_shared_mobile_harness_runs_all_mobile_projects(path: str) -> None:
assert not plan['required']['e2e']


@pytest.mark.parametrize(
('filename', 'targets'),
[('request-repeat-submit.mts', ['web']), ('logout-behavior.mts', ['web', 'mobile'])],
)
def test_shared_web_and_logout_suites_select_their_consumers(filename: str, targets: list[str]) -> None:
"""共享 Vitest 用例变更触发引用这些用例的工程。"""
plan = ci.build_plan([f'ruoyi-fastapi-test/frontend/{filename}'])
assert {(row['framework'], row['target']) for row in plan['frontend_matrix']['include']} == {
(framework, target) for framework in ci.FRAMEWORKS for target in targets
}


@pytest.mark.parametrize('framework', ci.FRAMEWORKS)
def test_web_change_selects_matching_framework_and_both_databases(framework: str) -> None:
"""Web 变更使用对应框架并覆盖两类数据库。"""
Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/ci-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,26 @@ jobs:
${{ runner.os }}-node${{ matrix.node }}-${{ matrix.project.framework }}-${{ matrix.project.target }}-
- name: Install dependencies from the committed lockfile
run: pnpm install --frozen-lockfile
- name: Lint frontend source and tests
run: pnpm run lint
- name: Type-check Vitest suites and test helpers
run: pnpm run typecheck:tests
- name: Record resolved dependency versions
run: |
mkdir -p test-results
node --version > test-results/node-version.txt
if ! pnpm list --depth Infinity --json > test-results/dependency-tree.json; then
echo "Dependency tree includes peer diagnostics; inspect dependency-tree.json." >&2
fi
- name: Verify independent locale resources and runtime contracts
- name: Verify independent locale resources
run: pnpm run i18n:check > test-results/i18n.json.log
- name: Run the full Vitest suite in UTC
run: TZ=UTC pnpm run test:vitest
- name: Verify time contracts in Shanghai and New York
run: |
pnpm run i18n:check > test-results/i18n.json.log
pnpm run test:i18n
- name: Run unit and component behavior tests
run: pnpm run test:unit
- name: Verify time contracts in three host timezones
run: |
for zone in UTC Asia/Shanghai America/New_York; do
for zone in Asia/Shanghai America/New_York; do
TZ="$zone" pnpm run test:contract
done
- name: Verify Vue 2 Mobile Intl polyfills and development templates
if: matrix.project.framework == 'vue2' && matrix.project.target == 'mobile'
run: pnpm run test:bundle
- name: Build Web production and Docker targets
if: matrix.project.target == 'web'
run: |
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/ci-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,38 @@ jobs:
retention-days: 7

task-bundle:
name: Task plugin bundle
name: Plugin frontend / ${{ matrix.plugin }}
if: inputs.release
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
plugin: [task_demo, bundle_demo]
defaults:
run:
working-directory: ruoyi-fastapi-backend/plugins/examples/python/task_demo/web
working-directory: ruoyi-fastapi-backend/plugins/examples/python/${{ matrix.plugin }}/web
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: '22'
- uses: pnpm/action-setup@v5
with:
package_json_file: ruoyi-fastapi-backend/plugins/examples/python/task_demo/web/package.json
package_json_file: ruoyi-fastapi-backend/plugins/examples/python/${{ matrix.plugin }}/web/package.json
- name: Locate the pnpm store
id: pnpm-store
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v5
with:
path: ${{ steps.pnpm-store.outputs.path }}
key: ${{ runner.os }}-task-bundle-${{ hashFiles('ruoyi-fastapi-backend/plugins/examples/python/task_demo/web/pnpm-lock.yaml') }}
key: ${{ runner.os }}-${{ matrix.plugin }}-${{ hashFiles(format('ruoyi-fastapi-backend/plugins/examples/python/{0}/web/pnpm-lock.yaml', matrix.plugin)) }}
- run: pnpm install --frozen-lockfile
- run: pnpm run lint
- run: pnpm run typecheck:tests
- run: pnpm test
- run: pnpm run build
- uses: actions/upload-artifact@v6
if: matrix.plugin == 'task_demo'
with:
name: integration-task-bundle
path: ruoyi-fastapi-backend/plugins/examples/python/task_demo/web/dist/
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ RuoYi-FastAPI/
└── ruoyi-fastapi-test/ # 端到端与跨工程契约测试
```

### 前端检查与测试

进入任一前端工程目录,运行 `pnpm install --frozen-lockfile` 安装依赖。`pnpm lint` 按当前框架的规则检查代码,`pnpm typecheck:tests` 检查测试的 TypeScript 类型,`pnpm test` 单次运行全部 Vitest 用例,`pnpm test:watch` 在开发时监听变化。[前端测试说明](./ruoyi-fastapi-test/README.md)

### 国际化词库

六个前端各自在 `src/i18n/locales/<语言>/<命名空间>.json` 维护页面文案。同一功能的中英文使用相同的语义 key,并保留各语言需要的复数形式。新增词条时,按使用它的功能选择文件。
Expand Down
4 changes: 2 additions & 2 deletions ruoyi-fastapi-backend/cli/runtime/plugin/scaffold/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,14 @@ def build_readme(plugin_id: str, frontend_framework: str | None = 'vue3') -> str
- `migrations/`: database migration scripts declared in `plugin.yaml`.
- `seeds/`: initialization scripts declared in `plugin.yaml`.
- `tests/plugins/{plugin_id}/`: pytest examples for this plugin.
- frontend project `tests/plugins/{plugin_id}/`: frontend node tests for this plugin.
- frontend project `tests/plugins/{plugin_id}/`: Vitest tests for this plugin.

## Commands

```bash
ruoyi plugin check {plugin_id}
pytest tests/plugins/{plugin_id}
cd <frontend-project> && node tests/plugins/{plugin_id}/pluginView.test.js
cd <frontend-project> && pnpm exec vitest run tests/plugins/{plugin_id}/pluginView.test.ts
ruoyi plugin install {plugin_id} --dry-run
ruoyi plugin install {plugin_id} --yes
ruoyi plugin enable {plugin_id} --yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _build_frontend_files(
if options.test:
files.append(
(
plugin_root.parents[1] / 'tests' / 'plugins' / plugin_id / 'pluginView.test.js',
plugin_root.parents[1] / 'tests' / 'plugins' / plugin_id / 'pluginView.test.ts',
PluginFrontendScaffoldTemplateBuilder.build_test(plugin_id, frontend_framework),
)
)
Expand Down
24 changes: 8 additions & 16 deletions ruoyi-fastapi-backend/cli/runtime/plugin/scaffold/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def build_readme(plugin_id: str) -> str:

- `api/`: request wrappers used by plugin pages.
- `views/`: Vue pages loaded by backend menu component paths.
- `../../tests/plugins/{plugin_id}/`: frontend node tests for plugin view resolving.
- `../../tests/plugins/{plugin_id}/`: Vitest tests for plugin view resolution.

## Route Component

Expand All @@ -225,27 +225,19 @@ def build_readme(plugin_id: str) -> str:
@staticmethod
def build_test(plugin_id: str) -> str:
"""
构建前端插件 node 测试样例。
构建前端插件 Vitest 测试样例。

:param plugin_id: 插件ID
:return: 前端插件测试样例内容
"""
return f"""import assert from 'node:assert/strict'
import {{ existsSync }} from 'node:fs'
import {{ dirname, resolve }} from 'node:path'
import {{ fileURLToPath }} from 'node:url'

return f"""import {{ existsSync }} from 'node:fs'
import {{ expect, test }} from 'vitest'
import {{ resolvePluginViewPath }} from '../../../src/utils/pluginViewResolver.ts'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const frontendRoot = resolve(__dirname, '../../..')
const viewPath = resolve(frontendRoot, 'plugins', '{plugin_id}', 'views', 'index.vue')

assert.equal(resolvePluginViewPath('plugin/{plugin_id}/index'), '../../../plugins/{plugin_id}/views/index.vue')
assert.equal(existsSync(viewPath), true)

console.log('{plugin_id} plugin frontend tests passed')
test('{plugin_id} route resolves to the generated Vue page', () => {{
expect(resolvePluginViewPath('plugin/{plugin_id}/index')).toBe('../../../plugins/{plugin_id}/views/index.vue')
expect(existsSync(new URL('../../../plugins/{plugin_id}/views/index.vue', import.meta.url))).toBe(true)
}})
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ def build_readme(plugin_id: str) -> str:

- `api/`: request wrappers using the host request client.
- `views/index.tsx`: React page loaded by the backend menu `plugin/{plugin_id}/index`.
- `../../tests/plugins/{plugin_id}/pluginView.test.js`: Node.js route mapping smoke test.
- `../../tests/plugins/{plugin_id}/pluginView.test.ts`: Vitest route mapping smoke test.

From the React Web host, run:

~~~sh
node --test tests/plugins/{plugin_id}/pluginView.test.js
pnpm exec vitest run tests/plugins/{plugin_id}/pluginView.test.ts
pnpm build
~~~

Expand All @@ -232,19 +232,13 @@ def build_test(plugin_id: str) -> str:
:param plugin_id: 插件清单中的唯一标识
:return: 可由 plugin test 调用的 React 路由解析测试
"""
return f"""import assert from 'node:assert/strict';
import {{ existsSync }} from 'node:fs';
import {{ dirname, resolve }} from 'node:path';
import {{ fileURLToPath }} from 'node:url';
import {{ test }} from 'node:test';

import {{ resolvePluginViewPath }} from '../../../src/utils/pluginViewResolver.ts';

const frontendRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../..');
return f"""import {{ existsSync }} from 'node:fs'
import {{ expect, test }} from 'vitest'
import {{ resolvePluginViewPath }} from '../../../src/utils/pluginViewResolver.ts'

test('{plugin_id} React plugin view resolves to its generated TSX page', () => {{
assert.equal(resolvePluginViewPath('plugin/{plugin_id}/index', '.tsx'), '../../plugins/{plugin_id}/views/index.tsx');
assert.equal(existsSync(resolve(frontendRoot, 'plugins', '{plugin_id}', 'views', 'index.tsx')), true);
assert.equal(existsSync(resolve(frontendRoot, 'plugins', '{plugin_id}', 'api', '{plugin_id}.ts')), true);
}});
expect(resolvePluginViewPath('plugin/{plugin_id}/index', '.tsx')).toBe('../../plugins/{plugin_id}/views/index.tsx')
expect(existsSync(new URL('../../../plugins/{plugin_id}/views/index.tsx', import.meta.url))).toBe(true)
expect(existsSync(new URL('../../../plugins/{plugin_id}/api/{plugin_id}.ts', import.meta.url))).toBe(true)
}})
"""
22 changes: 9 additions & 13 deletions ruoyi-fastapi-backend/cli/runtime/plugin/scaffold/frontend_vue2.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def build_readme(plugin_id: str) -> str:

- `api/`: request wrappers used by plugin pages.
- `views/`: Vue pages loaded by backend menu component paths.
- `../../tests/plugins/{plugin_id}/`: frontend node tests for plugin view resolving.
- `../../tests/plugins/{plugin_id}/`: Vitest tests for plugin view resolution.

## Route Component

Expand All @@ -236,21 +236,17 @@ def build_readme(plugin_id: str) -> str:
@staticmethod
def build_test(plugin_id: str) -> str:
"""
构建 Vue 2 前端插件 node 测试样例。
构建 Vue 2 前端插件 Vitest 测试样例。

:param plugin_id: 插件ID
:return: 前端插件测试样例内容
"""
return f"""const assert = require('assert').strict
const {{ existsSync }} = require('fs')
const {{ resolve }} = require('path')
const {{ resolvePluginViewPath }} = require('../../../src/utils/pluginViewResolver')
return f"""import {{ existsSync }} from 'node:fs'
import {{ expect, test }} from 'vitest'
import resolver from '../../../src/utils/pluginViewResolver.js'

const frontendRoot = resolve(__dirname, '../../..')
const viewPath = resolve(frontendRoot, 'plugins', '{plugin_id}', 'views', 'index.vue')

assert.equal(resolvePluginViewPath('plugin/{plugin_id}/index'), './{plugin_id}/views/index.vue')
assert.equal(existsSync(viewPath), true)

console.log('{plugin_id} plugin frontend tests passed')
test('{plugin_id} route resolves to the generated Vue page', () => {{
expect(resolver.resolvePluginViewPath('plugin/{plugin_id}/index')).toBe('./{plugin_id}/views/index.vue')
expect(existsSync(new URL('../../../plugins/{plugin_id}/views/index.vue', import.meta.url))).toBe(true)
}})
"""
12 changes: 8 additions & 4 deletions ruoyi-fastapi-backend/cli/runtime/plugin/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ class PluginTestPlanBuilder:
"""
插件 CLI 测试计划构建器。

使用 Builder 模式发现后端 pytest 与前端 node 测试目标,并生成可执行命令。
发现后端 pytest 与前端测试目标,并生成可执行命令。

:ivar backend_root: 后端项目根目录
:ivar frontend_root: 前端项目根目录
Expand Down Expand Up @@ -939,17 +939,21 @@ def build(

frontend_target = self.frontend_root / 'tests' / 'plugins' / plugin_id
if frontend_target.exists():
vitest = self.frontend_root / 'node_modules' / 'vitest' / 'vitest.mjs'
# 独立宿主也可以继续使用其已有的 Node 测试。
runner = [self.node_executable, str(vitest), 'run'] if vitest.is_file() else [self.node_executable]
targets.extend(
[
PluginTestTarget(
kind='frontend',
target_path=test_file,
command=[self.node_executable, str(test_file)],
command=[*runner, str(test_file)],
workdir=self.frontend_root,
timeout=self.timeout,
)
for test_file in sorted(frontend_target.glob('*.test.*'))
if test_file.suffix in {'.js', '.cjs', '.mjs', '.ts', '.cts', '.mts'} and test_file.is_file()
for test_file in sorted(frontend_target.rglob('*.test.*'))
if test_file.suffix in {'.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.cts', '.mts'}
and test_file.is_file()
]
)
if frontend_build and self.frontend_root.exists():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

```bash
pnpm --dir plugins/examples/python/bundle_demo/web install --frozen-lockfile
pnpm --dir plugins/examples/python/bundle_demo/web run lint
pnpm --dir plugins/examples/python/bundle_demo/web run typecheck:tests
pnpm --dir plugins/examples/python/bundle_demo/web test
pnpm --dir plugins/examples/python/bundle_demo/web run build
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/** @typedef {{ getDelay?: () => number, shouldFail?: () => boolean }} MockOptions */

/**
* 创建仅供本地开发的内存请求适配器,不发送网络请求或保存文件。
*
* @param {Object} options 延迟和故障注入选项
* @param {MockOptions} [options] 延迟和故障注入选项
* @returns {Function} 可传入宿主桥的异步请求函数
*/
export function createMockPluginRequest({ getDelay = () => 300, shouldFail = () => false } = {}) {
Expand Down Expand Up @@ -70,7 +72,10 @@ export function createMockPluginRequest({ getDelay = () => 300, shouldFail = ()
}
}

/** 创建逐条产出事件的本地适配器,复用延迟和故障开关,支持取消与游标恢复。 */
/**
* 创建逐条产出事件的本地适配器,复用延迟和故障开关,支持取消与游标恢复。
* @param {MockOptions} [options] 延迟和故障注入选项
*/
export function createMockPluginStream({ getDelay = () => 300, shouldFail = () => false } = {}) {
return async function* (config) {
if (config.url !== '/apps/bundle_demo/api/events') throw new Error('模拟实时接口未实现')
Expand Down
Loading
Loading