const { test } = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const moduleEntrypoints = [ 'public/js/calculators.js', 'public/js/clinicalAssistant.js', 'public/js/notes.js', 'public/js/wellVisit.js' ]; function readProjectFile(relativePath) { return fs.readFileSync(path.join(__dirname, '..', relativePath), 'utf8'); } test('refactored frontend entrypoints are loaded as modules', () => { const indexHtml = readProjectFile('public/index.html'); moduleEntrypoints.forEach((entrypoint) => { const src = '/' + entrypoint.replace(/^public\//, ''); const pattern = new RegExp('<\\/script>'); assert.match(indexHtml, pattern, `${src} should be loaded as a module`); }); }); test('refactored module entrypoints do not use redundant IIFE wrappers', () => { moduleEntrypoints.forEach((entrypoint) => { const source = readProjectFile(entrypoint); assert.doesNotMatch(source, /^\s*\(function\s*\(/m, `${entrypoint} should not open an IIFE wrapper`); assert.doesNotMatch(source, /^\s*\}\)\(\);\s*$/m, `${entrypoint} should not close an IIFE wrapper`); }); });