const JsdomEnvironment = require('jest-environment-jsdom'); const path = require('path'); const fs = require('fs'); class FineUiEnvironment extends JsdomEnvironment { async setup(...args) { await super.setup(args); const document = this.dom.window.document; document.createElement('body'); [ '../node_modules/@fui/core/dist/fineui.js', '../node_modules/@fui/materials/docs/materials.js', '../config/fineui.prepare.js', './fineui.setup.js', ].forEach(scriptRelativePath => { writeScript(document, scriptRelativePath); }); return Promise.resolve(); } } function writeScript(document, scriptRelativePath) { const scriptEl = document.createElement('script'); scriptEl.text = fs.readFileSync(path.resolve(__dirname, scriptRelativePath), { encoding: 'utf8', }); document.body.appendChild(scriptEl); } module.exports = FineUiEnvironment;