const fs = require("fs"); const path = require("path"); const assert = require("assert"); const rootDir = path.resolve(__dirname, "..", ".."); const servicesDir = path.join(rootDir, "actions", "services"); const groupedServiceFiles = [ "searchService.js", "referenceDataService.js", "documentService.js", "portalService.js", "accountService.js", "caseService.js", "adminService.js", "integrationService.js", "notifyService.js" ]; const expectedIndexReExports = [ "./searchService", "./caseService", "./accountService", "./portalService", "./documentService", "./referenceDataService", "./notifyService", "./adminService", "./integrationService" ]; const parseNamedList = (block) => { return block .split(",") .map((item) => item.trim()) .filter(Boolean) .map((item) => item.replace(/\s+/g, " ")); }; const parseGroupedServiceFile = (filePath) => { const source = fs.readFileSync(filePath, "utf8"); const importMatch = source.match( /import\s*\{([\s\S]*?)\}\s*from\s*"(\.\/[^"]+)";/ ); assert( importMatch, `Unable to parse import block in ${path.basename(filePath)}` ); const exportMatch = source.match(/export\s*\{([\s\S]*?)\};/); assert( exportMatch, `Unable to parse export block in ${path.basename(filePath)}` ); return { directModulePath: importMatch[2], importedNames: parseNamedList(importMatch[1]).sort(), exportedNames: parseNamedList(exportMatch[1]).sort() }; }; const verifyGroupedServicesParity = () => { groupedServiceFiles.forEach((groupedFile) => { const groupedPath = path.join(servicesDir, groupedFile); const parsed = parseGroupedServiceFile(groupedPath); assert( parsed.directModulePath.endsWith("DirectService"), `${groupedFile} does not import a direct service module` ); assert.deepStrictEqual( parsed.importedNames, parsed.exportedNames, `${groupedFile} import/export names are not in parity` ); }); }; const verifyServicesIndexStability = () => { const source = fs.readFileSync(path.join(servicesDir, "index.js"), "utf8"); const matches = Array.from( source.matchAll(/export \* from "([^"]+)";/g) ).map((match) => match[1]); assert.deepStrictEqual( matches, expectedIndexReExports, "actions/services/index.js re-export list has changed unexpectedly" ); }; const run = () => { verifyGroupedServicesParity(); verifyServicesIndexStability(); console.log("Phase 6 parity tests passed."); }; run();