import test from 'node:test' import assert from 'node:assert/strict' import { existsSync } from 'node:fs' import { readSource } from './helpers.ts' // 验收反馈:日期控件/分页组件需显示中文。 // 不变式:应用入口为 Element Plus 注册 zh-cn 全局 locale(date-picker/pagination 全部跟随)。 test('align_locale_normal_primary_path', () => { // 10-04 起 EP 改按需注册(src/plugins/element.ts),全局配置通道换成 el-config-provider, // 所以这条不变式的落点从 main.ts 移到 App.vue —— 强度不许降:仍然要求真的引官方语言包并挂上 locale。 const app = readSource('src/App.vue') assert.match(app, /zh-cn|zhCn/i, 'App.vue 应引入 element-plus 中文语言包') assert.match(app, /]*:locale="zhCn"/, 'locale 必须经 el-config-provider 挂到全局') }) test('align_locale_normal_variant_input', () => { // 语言包必须来自 element-plus 官方路径(es/locale 或 dist/locale),不接受自造空对象。 const app = readSource('src/App.vue') assert.match(app, /element-plus\/(es|dist)\/locale/, 'locale 导入需指向 element-plus 语言包') }) test('align_locale_boundary_empty_input', () => { // 日期控件页面依赖全局 locale,不得在页面内再覆盖为 en。 const pages = [ 'src/pages/asin/DedupeRegistryPage.vue', 'src/pages/records/RecordsHistoryPage.vue', 'src/pages/tasks/ImageVideoTasksPage.vue', 'src/pages/tasks/ShopDataTasksPage.vue', ] for (const page of pages) { const src = readSource(page) assert.ok(!/locale\s*=\s*['"]en['"]/i.test(src), `${page} 不得局部覆盖英文 locale`) } }) test('align_locale_dependency_failure_returns_actionable_message', () => { // zh-cn 语言包在 node_modules 中真实存在(安装依赖即有效)。 assert.ok( existsSync('node_modules/element-plus/es/locale/lang/zh-cn.mjs') || existsSync('node_modules/element-plus/dist/locale/zh-cn.mjs'), 'element-plus zh-cn 语言包文件存在', ) })