|
| 1 | +import { createRequire } from 'node:module'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { fileURLToPath } from 'node:url'; |
| 4 | + |
| 5 | +const version = process.argv[2]; |
| 6 | + |
| 7 | +if (!version) { |
| 8 | + console.error('Usage: node --experimental-network-imports common/scripts/bytepack-smoke-test.mjs <version>'); |
| 9 | + process.exit(1); |
| 10 | +} |
| 11 | + |
| 12 | +const attempts = Number(process.env.BYTEPACK_SMOKE_ATTEMPTS || 10); |
| 13 | +const delayMs = Number(process.env.BYTEPACK_SMOKE_DELAY_MS || 30000); |
| 14 | +const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..'); |
| 15 | +const requireFromVChart = createRequire(path.join(repoRoot, 'packages/vchart/package.json')); |
| 16 | +const Canvas = requireFromVChart('canvas'); |
| 17 | + |
| 18 | +const wait = ms => new Promise(resolve => setTimeout(resolve, ms)); |
| 19 | + |
| 20 | +async function runSmoke() { |
| 21 | + const vchartModule = await import(`https://bytepack.bytedance.net/@visactor/vchart@${version}`); |
| 22 | + const extensionModule = await import( |
| 23 | + `https://bytepack.bytedance.net/@visactor/vchart-extension@${version}/esm/charts/pie-3d/chart.js` |
| 24 | + ); |
| 25 | + |
| 26 | + extensionModule.registerPie3dChart(); |
| 27 | + |
| 28 | + const VChart = vchartModule.default ?? vchartModule.VChart; |
| 29 | + if (!VChart) { |
| 30 | + throw new Error('Unable to resolve VChart constructor from BytePack module.'); |
| 31 | + } |
| 32 | + |
| 33 | + const chart = new VChart( |
| 34 | + { |
| 35 | + type: 'pie3d', |
| 36 | + width: 240, |
| 37 | + height: 240, |
| 38 | + data: [ |
| 39 | + { |
| 40 | + id: 'data', |
| 41 | + values: [ |
| 42 | + { category: 'A', value: 12 }, |
| 43 | + { category: 'B', value: 18 } |
| 44 | + ] |
| 45 | + } |
| 46 | + ], |
| 47 | + categoryField: 'category', |
| 48 | + valueField: 'value', |
| 49 | + outerRadius: 0.72 |
| 50 | + }, |
| 51 | + { |
| 52 | + mode: 'node', |
| 53 | + modeParams: Canvas, |
| 54 | + animation: false, |
| 55 | + options3d: { |
| 56 | + enable: true |
| 57 | + } |
| 58 | + } |
| 59 | + ); |
| 60 | + |
| 61 | + chart.renderSync(); |
| 62 | + chart.release(); |
| 63 | +} |
| 64 | + |
| 65 | +let lastError; |
| 66 | +for (let attempt = 1; attempt <= attempts; attempt++) { |
| 67 | + try { |
| 68 | + console.log(`BytePack smoke test for @visactor/vchart@${version}, attempt ${attempt}/${attempts}`); |
| 69 | + await runSmoke(); |
| 70 | + console.log(`BytePack smoke test passed for @visactor/vchart@${version}`); |
| 71 | + process.exit(0); |
| 72 | + } catch (err) { |
| 73 | + lastError = err; |
| 74 | + console.error(`BytePack smoke test failed on attempt ${attempt}/${attempts}:`); |
| 75 | + console.error(err && err.stack ? err.stack : err); |
| 76 | + |
| 77 | + if (attempt < attempts) { |
| 78 | + await wait(delayMs); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +console.error(`BytePack smoke test failed after ${attempts} attempts.`); |
| 84 | +if (lastError) { |
| 85 | + console.error(lastError && lastError.stack ? lastError.stack : lastError); |
| 86 | +} |
| 87 | +process.exit(1); |
0 commit comments