|
1 | | -const fs = require('fs'); |
| 1 | +import fs from 'node:fs'; |
| 2 | +import path from 'node:path'; |
2 | 3 |
|
3 | | -const path = require('path'); |
| 4 | +const blogDir = path.join(__dirname, '../../docs/blog'); |
4 | 5 |
|
5 | | -const blogList = [ |
6 | | - 'check-conduct', |
7 | | - 'contributor-development-maintenance-guide', |
8 | | - 'css-in-js', |
9 | | - 'extract-ssr', |
10 | | - 'getContainer', |
11 | | - 'github-actions-workflow', |
12 | | - 'issue-helper', |
13 | | - 'mock-project-build', |
14 | | - 'modal-hook-order', |
15 | | - 'testing-migrate', |
16 | | - 'render-times', |
17 | | - 'to-be-collaborator', |
18 | | - 'tooltip-align', |
19 | | - 'tree-shaking', |
20 | | - 'why-not-static', |
21 | | -].map((blogName) => path.join(__dirname, `../../docs/blog/${blogName}.en-US.md`)); |
| 6 | +const blogList = fs |
| 7 | + .readdirSync(blogDir, { withFileTypes: true }) |
| 8 | + .filter((entry) => entry.isFile()) |
| 9 | + .map((entry) => entry.name) |
| 10 | + .filter((file) => file.endsWith('.en-US.md')) |
| 11 | + .map((file) => path.join(blogDir, file)); |
22 | 12 |
|
23 | | -describe('blog', () => { |
| 13 | +describe('Chinese detected in en-US blog', () => { |
24 | 14 | it('should not include Chinese in en-US blog', () => { |
25 | | - blogList.forEach((blog) => { |
26 | | - fs.readFile(blog, (err: NodeJS.ErrnoException | null, data: Buffer) => { |
27 | | - if (err) { |
28 | | - return; |
29 | | - } |
30 | | - const includeChinese = /[\u4E00-\u9FA5]/.test(data.toString()); |
31 | | - expect(includeChinese).toBe(false); |
32 | | - }); |
33 | | - }); |
| 15 | + for (const blog of blogList) { |
| 16 | + const data = fs.readFileSync(blog, 'utf-8'); |
| 17 | + const includeChinese = /[\u4E00-\u9FA5]/.test(data); |
| 18 | + if (includeChinese) { |
| 19 | + console.error('❌ 检测到中文:', blog); |
| 20 | + } |
| 21 | + expect(includeChinese).toBe(false); |
| 22 | + } |
34 | 23 | }); |
35 | 24 | }); |
0 commit comments