assetUrl.test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const assert = require('node:assert/strict')
  2. const fs = require('node:fs')
  3. const path = require('node:path')
  4. const {
  5. DEFAULT_ASSET_BASE_URL,
  6. DEFAULT_PROFILE_IMAGE_BASE_URL,
  7. getAssetBaseUrl,
  8. getProfileImageUrl,
  9. htmlUrl,
  10. imageUrl
  11. } = require('../utils/assetUrl')
  12. assert.equal(DEFAULT_ASSET_BASE_URL, 'https://transcend.ringzle.com/web/assets')
  13. assert.equal(getAssetBaseUrl({}), DEFAULT_ASSET_BASE_URL)
  14. assert.equal(
  15. getAssetBaseUrl({ VUE_APP_ASSET_BASE_URL: 'https://test.example/assets/' }),
  16. 'https://test.example/assets'
  17. )
  18. assert.equal(
  19. imageUrl('fm_logo.png', { VUE_APP_ASSET_BASE_URL: 'https://test.example/assets/' }),
  20. 'https://test.example/assets/images/fm_logo.png'
  21. )
  22. assert.equal(
  23. getProfileImageUrl('2025/06/16/avatar.png'),
  24. 'https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/16/avatar.png'
  25. )
  26. assert.equal(
  27. getProfileImageUrl('2025/06/16/avatar.png', { VUE_APP_PROFILE_IMAGE_BASE_URL: 'https://test.example/profile/' }),
  28. 'https://test.example/profile/2025/06/16/avatar.png'
  29. )
  30. assert.equal(
  31. htmlUrl('PERILL常见问题与支持.html'),
  32. 'https://transcend.ringzle.com/web/assets/html/PERILL%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E4%B8%8E%E6%94%AF%E6%8C%81.html'
  33. )
  34. assert.equal(
  35. imageUrl('fm_logo.png'),
  36. 'https://transcend.ringzle.com/web/assets/images/fm_logo.png'
  37. )
  38. assert.equal(
  39. imageUrl('/fm_logo.png'),
  40. 'https://transcend.ringzle.com/web/assets/images/fm_logo.png'
  41. )
  42. assert.equal(
  43. imageUrl('中文图片.png'),
  44. 'https://transcend.ringzle.com/web/assets/images/%E4%B8%AD%E6%96%87%E5%9B%BE%E7%89%87.png'
  45. )
  46. const sourceRoots = ['components', 'pages', 'pagesHome', 'pagesMy', 'pagesPublish']
  47. const sourceFiles = sourceRoots.flatMap(root => {
  48. const files = []
  49. const visit = current => {
  50. for (const entry of fs.readdirSync(path.join(__dirname, '..', current), { withFileTypes: true })) {
  51. const relative = path.join(current, entry.name)
  52. if (entry.isDirectory() && !entry.name.includes('lime-echart')) visit(relative)
  53. else if (/\.(vue|js|scss|css)$/.test(entry.name)) files.push(relative)
  54. }
  55. }
  56. visit(root)
  57. return files
  58. })
  59. for (const file of sourceFiles) {
  60. const source = fs.readFileSync(path.join(__dirname, '..', file), 'utf8')
  61. assert.equal(source.includes('https://transcend.ringzle.com/web/assets/images/'), false, file)
  62. }
  63. console.log('asset URL rules: PASS')