Local Node vm Test Gate for Apps Script
Google Apps Script lacks a native local test runner, making it easy to push broken code directly into scheduled jobs. To close that gap, npm run push compiles all six Apps Script modules inside a local Node vm sandbox—mocking SpreadsheetApp, UrlFetchApp, and ScriptApp—and blocks clasp deployment unless the full verification suite passes.
// package.json — deployment blocked if sandbox suite fails
"scripts": {
"test": "node tests/verify_3layer_hybrid.js",
"push": "npm test && npx @google/clasp push -f"
}
// tests/verify_3layer_hybrid.js — syntax + runtime assertions
for (const file of srcFiles) {
const source = fs.readFileSync(path.join(srcDir, file), "utf8");
new vm.Script(source, { filename: file });
}
vm.runInNewContext(bundle, mockedAppsScriptGlobals);