legacy_chart_smoke.mjs 1.0 KB

123456789101112131415
  1. // 冒烟:v2.9.2 的 charts.js 在 Node 里能否出 SVG(用最小夹具)
  2. import { readFileSync } from 'node:fs'
  3. import { fileURLToPath } from 'node:url'
  4. import { dirname, resolve } from 'node:path'
  5. const HERE = dirname(fileURLToPath(import.meta.url))
  6. const src = readFileSync(resolve(HERE, '../src/lib/legacy/charts.js'), 'utf8')
  7. const sandbox = { window: {} }
  8. const fn = new Function('window', 'document', 'navigator', src + '\nreturn window.__charts;')
  9. const factory = fn(sandbox.window, {}, {})
  10. const CH = factory({ t: (k) => k, fmt: (v) => String(v), esc: (s) => String(s), dv: (v) => String(v),
  11. EN: false, displayText: (x) => String(x == null ? '' : x), verb: () => {} })
  12. const svg1 = CH.rateChart({ months: ['m1', 'm2'], vals: [1, 2], cov: [1, 1], per_day: [0.5, 0.8] })
  13. const svg2 = CH.quadChart([{ n: 3, med: 700, nt: 3, 部件: 'x' }])
  14. console.log('rateChart:', /^<svg/.test(svg1) ? 'OK ' + svg1.length + ' B' : 'FAIL')
  15. console.log('quadChart:', /^<svg/.test(svg2) ? 'OK ' + svg2.length + ' B' : 'FAIL')