@@ -5,6 +5,77 @@ const assert = require("assert");
|
||||
|
||||
const rootDir = path.resolve(__dirname, "..", "..");
|
||||
|
||||
const loadMapAppealTypeModule = () => {
|
||||
const filePath = path.join(
|
||||
rootDir,
|
||||
"lib",
|
||||
"domain",
|
||||
"case-lifecycle",
|
||||
"mapAppealType.js"
|
||||
);
|
||||
|
||||
let source = fs.readFileSync(filePath, "utf8");
|
||||
source = source.replace(/export const\s+/g, "const ");
|
||||
source = source.replace(
|
||||
/export function\s+mapAppealType/,
|
||||
"function mapAppealType"
|
||||
);
|
||||
source += `
|
||||
module.exports = {
|
||||
caseTypeAliases,
|
||||
caseTypeKeyByAppealTypeId,
|
||||
normaliseCaseType,
|
||||
mapAppealType
|
||||
};
|
||||
`;
|
||||
|
||||
const context = {
|
||||
module: { exports: {} },
|
||||
exports: {},
|
||||
require
|
||||
};
|
||||
|
||||
vm.runInNewContext(source, context, { filename: filePath });
|
||||
return context.module.exports;
|
||||
};
|
||||
|
||||
const loadAppealTypeFamilyModule = () => {
|
||||
const filePath = path.join(
|
||||
rootDir,
|
||||
"lib",
|
||||
"domain",
|
||||
"appeal-type-policy",
|
||||
"getAppealTypeFamily.js"
|
||||
);
|
||||
|
||||
let source = fs.readFileSync(filePath, "utf8");
|
||||
source = source.replace(
|
||||
/import\s+\{\s*mapAppealType\s*\}\s+from\s+"\.\.\/case-lifecycle\/mapAppealType";?/,
|
||||
'const { mapAppealType } = require("../case-lifecycle/mapAppealType");'
|
||||
);
|
||||
source = source.replace(
|
||||
/export function\s+getAppealTypeFamily/,
|
||||
"function getAppealTypeFamily"
|
||||
);
|
||||
source += `
|
||||
module.exports = { getAppealTypeFamily };
|
||||
`;
|
||||
|
||||
const context = {
|
||||
module: { exports: {} },
|
||||
exports: {},
|
||||
require: (modulePath) => {
|
||||
if (modulePath === "../case-lifecycle/mapAppealType") {
|
||||
return loadMapAppealTypeModule();
|
||||
}
|
||||
return require(modulePath);
|
||||
}
|
||||
};
|
||||
|
||||
vm.runInNewContext(source, context, { filename: filePath });
|
||||
return context.module.exports;
|
||||
};
|
||||
|
||||
const createFakeDate = (isoString) => {
|
||||
const RealDate = Date;
|
||||
|
||||
@@ -51,13 +122,22 @@ const loadEsModuleFunctions = (
|
||||
/import\s+\{\s*isRepresentationWindowOpen\s*\}\s+from\s+"\.\/resolveRepresentationWindow";/,
|
||||
'const { isRepresentationWindowOpen } = require("./resolveRepresentationWindow");'
|
||||
);
|
||||
source = source.replace(
|
||||
/import\s+\{\s*getAppealTypeFamily\s*\}\s+from\s+"\.\.\/appeal-type-policy";?/,
|
||||
'const { getAppealTypeFamily } = require("../appeal-type-policy");'
|
||||
);
|
||||
|
||||
source += `\nmodule.exports = { ${exportNames.join(", ")} };\n`;
|
||||
|
||||
const context = {
|
||||
module: { exports: {} },
|
||||
exports: {},
|
||||
require,
|
||||
require: (modulePath) => {
|
||||
if (modulePath === "../appeal-type-policy") {
|
||||
return loadAppealTypeFamilyModule();
|
||||
}
|
||||
return require(modulePath);
|
||||
},
|
||||
Date,
|
||||
Number,
|
||||
Set,
|
||||
|
||||
Reference in New Issue
Block a user