Files
mxpic_EDA/tests/canvas-static-route.test.js
T
2026-05-30 12:23:51 +08:00

36 lines
1.3 KiB
JavaScript

/*
* Description: Static and helper regression tests for MXPIC EDA frontend/backend integration contracts.
* Inside functions: N/A - assertion-based test/module script.
* Developer : Qin Yue @ 2026
* Organization : OptiHK Limited
*/
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const root = path.resolve(__dirname, '..');
const canvasHtml = fs.readFileSync(path.join(root, 'frontend', 'canvas.html'), 'utf8');
const serverPy = fs.readFileSync(path.join(root, 'backend', 'server.py'), 'utf8');
assert(
canvasHtml.includes('src="/canvas-helpers.js"'),
'canvas.html should request the canvas helper script from /canvas-helpers.js'
);
assert(
serverPy.includes("@app.route('/canvas-helpers.js')"),
'backend/server.py should serve /canvas-helpers.js'
);
assert(
serverPy.includes("send_from_directory(FRONTEND_DIR, 'canvas-helpers.js')") ||
serverPy.includes('send_from_directory(FRONTEND_DIR, "canvas-helpers.js")'),
'the /canvas-helpers.js route should serve frontend/canvas-helpers.js'
);
assert(
serverPy.includes('def no_cache_response(response):'),
'canvas assets should use an explicit no-cache response helper'
);
assert(
serverPy.includes('Cache-Control') && serverPy.includes('no-store'),
'canvas routes should prevent stale browser caches while the editor is changing'
);