1
0

TestHelperFunctions.js 603 B

12345678910111213141516171819
  1. 'use strict';
  2. const fs = require('node:fs');
  3. const path = require('node:path');
  4. function loadTemplateFragment(id) {
  5. const template = fs.readFileSync(path.resolve(__dirname, '../../tpl/bootstrap5.php'), 'utf8');
  6. const match = template.match(new RegExp(`<div id="${id}"[^>]*>[\\s\\S]*?<\\/div>`));
  7. if (!match) {
  8. throw new Error(`Template fragment #${id} not found`);
  9. }
  10. return match[0]
  11. .replace(/<\?php[\s\S]*?\?>/g, '')
  12. .replace(/<\?=[\s\S]*?\?>/g, '')
  13. .replace(/>\s+</g, '><')
  14. .trim();
  15. }
  16. exports.loadTemplateFragment = loadTemplateFragment;