How to use findWebpackConfig method in Cypress

Best JavaScript code snippet using cypress

bundle.es6

Source:bundle.es6 Github

copy

Full Screen

1const Module = require("module");2const colorLogEvent = clc.cyan.bgBlue(`EVENT BUNDLE`);3const regFixtures = /^(\w+)Fixtures.js$/;4const regController = /^(\w+)Controller\.[m]?js$/;5const regClassController = /^(\w+)Controller$/;6const regService = /^(\w+)Service.[ej]s[6]?$/;7const regCommand = /^(\w+)Command.js$/;8const regEntity = /^(\w+)Entity.js$/;9const regI18nFile = /^(.*)\.(.._..)\.(.*)$/;10const regConfigFile = /^(.*)\..*$/;11const regRoutingFile = /^(routing)\..*$/;12const regWebpackCongig = /^(webpack)\.(dev\.|prod\.)?config\.js$/;13const checkIngnoreFile = function (string, basename) {14 let file = null;15 try {16 file = new nodefony.fileClass(string);17 } catch (e) {18 if (basename.match(/^\./)) {19 return true;20 }21 return false;22 }23 if (basename.match(/^\./)) {24 return true;25 }26 if (file.type === "Directory") {27 return "Directory";28 }29 return false;30};31const moduleFindDependencies = class moduleFindDependencies {32 constructor(Path, type, bundle) {33 this.container = {};34 this.bundle = bundle;35 this.childs = [];36 this.type = type;37 switch (type) {38 case "controller":39 this.path = this.bundle.controllersPath;40 this.reg = regController;41 this.loader = this.bundle.loadController;42 break;43 case "routing":44 this.path = this.bundle.configPath;45 this.reg = regRoutingFile;46 this.loader = this.bundle.reloadRouting;47 break;48 case "service":49 this.path = this.bundle.servicesPath;50 this.reg = regService;51 this.loader = this.bundle.reloadService;52 break;53 default:54 throw new Error("moduleFindDependencies type not valid : " + type);55 }56 this.cache = Module._cache;57 if (Path) {58 this.findRequire(Path);59 }60 }61 set(ele, val) {62 return this.container[ele] = val;63 }64 get(ele) {65 return this.container[ele];66 }67 setChild(path) {68 this.childs.push(path);69 }70 length() {71 return Object.keys(this.container).length;72 }73 findRequire(Path, check) {74 if (check === undefined) {75 check = true;76 }77 for (let module in this.cache) {78 if (this.cache[module].filename.indexOf(this.path) >= 0) {79 let basename = path.basename(this.cache[module].filename);80 if (check && this.cache[module].filename.indexOf(Path) >= 0) {81 if (path.basename(Path) === basename) {82 this.setChild(this.cache[module].filename);83 }84 }85 if (this.cache[module].children.length) {86 for (let child in this.cache[module].children) {87 if (this.cache[module].children[child].filename.indexOf(Path) >= 0) {88 let res = this.reg.exec(basename);89 if (res) {90 this.set(res[1], this.cache[module].filename);91 return this;92 } else {93 this.setChild(this.cache[module].filename);94 return this.findRequire(this.cache[module].filename, false);95 }96 }97 }98 }99 }100 }101 return this;102 }103 reload() {104 if (this.length()) {105 for (let i = 0; i < this.childs.length; i++) {106 this.bundle.log("Reload " + this.type + " Dependency : " + this.childs[i]);107 this.bundle.loadFile(this.childs[i], true);108 }109 for (let control in this.container) {110 this.loader.call(this.bundle, control, this.container[control], true);111 }112 }113 }114};115const defaultWatcher = function (reg /*, settings*/ ) {116 return {117 ignoreInitial: true,118 ignored: [119 (string) => {120 let basename = path.basename(string);121 let file = checkIngnoreFile(string, basename);122 if (file === true) {123 return true;124 }125 if (file === "Directory") {126 return false;127 }128 if (basename.match(reg)) {129 return false;130 }131 return true;132 }133 ],134 cwd: this.path135 };136};137const defaultOptions = {138 events: {139 nbListeners: 60,140 captureRejections: true141 }142};143/*144 * BUNDLE CLASS145 */146class Bundle extends nodefony.Service {147 constructor(name, kernel, container) {148 super(name, container, null, nodefony.extend(true, {}, defaultOptions));149 this.log("\x1b[36m REGISTER BUNDLE : " + this.name + " \x1b[0m", "DEBUG", this.kernel.cli.clc.magenta("KERNEL"));150 this.bundleName = path.basename(this.path);151 this.location = path.dirname(this.path);152 this.publicPath = path.resolve(this.path, "Resources", "public");153 this.environment = this.kernel.environment;154 this.waitBundleReady = false;155 this.setParameters("bundles." + this.name, this.getParameters("bundles." + this.name) || {});156 this.production = (this.kernel.environment === "prod") ? true : false;157 this.package = require(path.resolve(this.path, "package.json"));158 this.version = this.package.version;159 this.packageName = this.package.name;160 this.isCore = this.kernel.isBundleCore(this.name);161 // services162 this.injectionService = this.get("injection");163 this.reader = this.kernel.reader;164 // webpack165 this.webPackConfig = null;166 this.webpackWatch = false;167 this.webpackCompiler = null;168 this.webPackConfig = null;169 this.watching = null;170 // config171 this.regConfigFile = regConfigFile;172 this.configPath = path.resolve(this.path, "Resources", "config");173 //views174 this.views = {};175 this.views["."] = {};176 this.watcherView = null;177 // views178 this.serviceTemplate = this.get("templating");179 this.regTemplateExt = new RegExp("^(.+)\." + this.serviceTemplate.extention + "$");180 this.viewsPath = path.resolve(this.path, "Resources", "views");181 // controllers182 this.controllersPath = path.resolve(this.path, "controller");183 this.controllers = {};184 this.watcherController = null;185 this.regController = regController;186 // I18n187 this.locale = this.kernel.settings.system.locale;188 this.i18nPath = path.resolve(this.path, "Resources", "translations");189 this.watcherI18n = null;190 this.regI18nFile = regI18nFile;191 // Register Service192 this.servicesPath = path.resolve(this.path, "services");193 this.watcherServices = null;194 this.regService = regService;195 // others196 this.entities = {};197 this.fixtures = {};198 this.regRoutingFile = regRoutingFile;199 this.regWebpackCongig = regWebpackCongig;200 try {201 this.finder = new nodefony.Finder2({202 exclude: nodefony.Bundle.exclude(),203 excludeDir: nodefony.Bundle.excludeDir(),204 recurse: true205 });206 } catch (e) {207 throw e;208 }209 // KERNEL EVENTS210 this.kernel.prependOnceListener("onBoot", async () => {211 try {212 this.router = this.get("router");213 this.sockjs = this.get("sockjs");214 //this.orm = this.get("orm");215 //console.log("PASSS",this.orm)216 this.webpackService = this.get("webpack");217 this.translation = this.get("translation");218 // Register internationalisation219 if (this.translation) {220 this.locale = this.translation.defaultLocale;221 }222 // I18n223 this.i18nFiles = await this.findI18nFiles();224 // Register Entity225 await this.registerEntities();226 // WATCHERS227 if (this.kernel.environment === "dev" && this.settings.watch && this.kernel.type !== "CONSOLE") {228 this.initWatchers();229 }230 } catch (e) {231 throw e;232 }233 });234 this.kernel.once("onPostReady", async () => {235 switch(this.kernel.environment){236 case 'production':237 case 'prod':238 case 'preprod':239 case 'preproduction':240 this.clean();241 break;242 }243 });244 // BUNDLE EVENTS245 this.fire("onRegister", this);246 }247 static excludeDir() {248 return /^public$|^node_modules$|^clones$|^\.git|assets$|tmp$|doc$|build$|css$|scss$|public$/;249 }250 static exclude() {251 return /yarn.lock$|package-lock.json$|yarn-error.log$|package.json$/;252 }253 async initialize() {254 // Register services before boot255 return await this.registerServices()256 .then((results) => {257 let dir = null;258 if (this.name === "app") {259 dir = this.findResult;260 this.configPath = path.resolve(this.path, "config");261 } else {262 dir = this.resourcesFiles;263 }264 // config265 let conf = dir.find("config")[0];266 if (conf) {267 this.kernel.readConfig.call(this, null, conf.children, (result) => {268 //console.log(result)269 this.parseConfig(result);270 });271 } else {272 throw new Error("Bundle must have config directory");273 }274 //EVENT BOOT BUNDLE275 this.fire("onInitialize", this);276 return results;277 });278 }279 async find() {280 return this.findResult = await this.finder281 .in(this.path)282 .then((result) => {283 //this.log(result[0].children.length ,'WARNING', `FINDER ${this.name}`);284 this.resourcesFiles = result[0].children.find("Resources");285 return result[0].children;286 })287 .catch(e => {288 this.log(e, "ERROR");289 });290 }291 boot() {292 return new Promise(async (resolve, reject) => {293 try {294 //EVENT BOOT BUNDLE295 this.fire("onBoot", this);296 // finder controller297 await this.findControllerFiles();298 // finder views299 await this.findViewFiles();300 // I18N301 await this.registerI18n(this.locale);302 // Register Controller303 await this.registerControllers();304 // Register Views305 await this.registerViews();306 if (this.kernel.type === "CONSOLE") {307 await this.registerFixtures();308 }309 } catch (e) {310 return reject(e);311 }312 if (this.waitBundleReady === false) {313 this.fire("onReady", this);314 }315 return resolve(this);316 });317 }318 clean() {319 this.log(`CLEAN MEMORY BUNDLE : ${this.name}`);320 this.findResult = null;321 delete this.findResult;322 this.webPackConfig = null;323 delete this.webPackConfig;324 this.webpackCompiler = null;325 delete this.webpackCompiler;326 this.watching = null;327 delete this.watching;328 this.viewFiles = null;329 delete this.viewFiles;330 //this.i18nFiles = null;331 //delete this.i18nFiles;332 this.controllerFiles = null;333 delete this.controllerFiles;334 this.commandFiles = null;335 delete this.commandFiles;336 this.resourcesFiles = null;337 delete this.resourcesFiles;338 this.fixtureFiles = null;339 delete this.fixtureFiles;340 this.entityFiles = null;341 delete this.entityFiles;342 }343 fire() {344 this.log(`${colorLogEvent} ${arguments[0]}`, "DEBUG");345 return super.fire.apply(this, arguments);346 }347 initWebpack() {348 try {349 return this.findWebPackConfig()350 .then((compiler) => {351 if (!this.watching || this.kernel.environment === "prod") {352 if (this.kernel.cli.command === "webpack") {353 return Promise.resolve(compiler);354 }355 if (this.kernel.isCore || !this.isCore) {356 this.log(`MEMORY clean webpack compile bundle : ${this.name}`, "DEBUG");357 }358 this.webPackConfig = null;359 delete this.webPackConfig;360 this.webpackCompiler = null;361 delete this.webpackCompiler;362 return Promise.resolve(compiler);363 }364 })365 .catch((e) => {366 this.log(e, "ERROR");367 throw e;368 });369 } catch (e) {370 this.log(e, "ERROR");371 throw e;372 }373 }374 compileWebpack() {375 return new Promise((resolve, reject) => {376 if (this.webpackCompiler) {377 try {378 return this.webpackService.runCompiler(this.webpackCompiler, this.name + "_" + this.webpackCompiler.name, this.name, this.webpackCompiler.name)379 .catch(e => {380 return reject(e);381 });382 } catch (e) {383 return reject(e);384 }385 }386 return resolve();387 });388 }389 findWebPackConfig() {390 return new Promise((resolve, reject) => {391 let res = null;392 let file = null;393 switch (this.settings.type) {394 case "angular":395 try {396 res = this.findResult.find("webpack.config.js")[0];397 if (!res) {398 return reject(new Error("Angular bundle no webpack config file : webpack.config.js "));399 }400 return resolve(this.loadWebpackConfig(res));401 } catch (e) {402 shell.cd(this.kernel.rootDir);403 throw e;404 }405 break;406 case "react":407 file = null;408 try {409 switch (process.env.NODE_ENV) {410 case "development":411 case "production":412 file = path.resolve(this.path, "config", "webpack.config.js");413 break;414 }415 res = new nodefony.fileClass(file);416 process.env.PUBLIC_URL = path.resolve("/", this.bundleName, "dist");417 return resolve(this.loadWebpackConfig(res));418 } catch (e) {419 shell.cd(this.kernel.rootDir);420 return reject(e);421 }422 break;423 case "vue":424 file = path.resolve(this.path, "node_modules", "@vue", "cli-service", "webpack.config.js");425 try {426 this.webpackConfigFile = new nodefony.fileClass(file);427 process.env.VUE_CLI_CONTEXT = this.path;428 return resolve(this.loadWebpackConfig(this.webpackConfigFile));429 } catch (e) {430 shell.cd(this.kernel.rootDir);431 return reject(e);432 }433 break;434 default:435 try {436 this.webpackConfigFile = this.findResult.find("webpack.config.js")[0];437 if (!this.webpackConfigFile) {438 return resolve(false);439 }440 return resolve(this.loadWebpackConfig(this.webpackConfigFile));441 } catch (e) {442 shell.cd(this.kernel.rootDir);443 return reject(e);444 }445 }446 });447 }448 loadWebpackConfig(conf) {449 return this.webpackService.loadConfig(conf, this)450 .then((compiler) => {451 shell.cd(this.kernel.rootDir);452 return compiler;453 }).catch(e => {454 shell.cd(this.kernel.rootDir);455 throw e;456 });457 }458 initWatchers() {459 if (!this.settings.watch) {460 return;461 }462 let controllers = false;463 let views = false;464 let i18n = false;465 let config = false;466 let services = false;467 //let entities = false;468 let regJs = new RegExp(".*\.js$|.*\.es6$|.*\.es7$|.*\.mjs$");469 try {470 switch (typeof this.settings.watch) {471 case "object":472 controllers = this.settings.watch.controllers || false;473 views = this.settings.watch.views || false;474 i18n = this.settings.watch.translations || false;475 config = this.settings.watch.config || false;476 services = this.settings.watch.services || false;477 this.webpackWatch = this.settings.watch.webpack || false;478 break;479 case "boolean":480 controllers = this.settings.watch || false;481 views = this.settings.watch || false;482 i18n = this.settings.watch || false;483 config = this.settings.watch || false;484 services = this.settings.watch || false;485 this.webpackWatch = this.settings.watch || false;486 break;487 default:488 this.log("BAD CONFIG WATCHER ", "WARNING");489 return;490 }491 // controllers492 if (controllers) {493 this.watcherController = new nodefony.kernelWatcher(this.controllersPath, defaultWatcher.call(this, regJs), this);494 this.watcherController.setSockjsServer(this.sockjs);495 this.watcherController.listenWatcherController();496 this.kernel.on("onTerminate", () => {497 this.log("Watching Ended : " + this.watcherController.path, "INFO");498 this.watcherController.close();499 });500 }501 // views502 if (views) {503 this.watcherView = new nodefony.kernelWatcher(this.viewsPath, defaultWatcher.call(this, this.regTemplateExt), this);504 this.watcherView.listenWatcherView();505 this.watcherView.setSockjsServer(this.sockjs);506 this.kernel.on("onTerminate", () => {507 this.log("Watching Ended : " + this.watcherView.path, "INFO");508 this.watcherView.close();509 });510 }511 // I18n512 if (i18n) {513 this.watcherI18n = new nodefony.kernelWatcher(this.i18nPath, defaultWatcher.call(this, regI18nFile), this);514 this.watcherI18n.listenWatcherI18n();515 this.watcherI18n.setSockjsServer(this.sockjs);516 this.kernel.on("onTerminate", () => {517 this.log("Watching Ended : " + this.watcherI18n.path, "INFO");518 this.watcherI18n.close();519 });520 }521 // config522 if (config) {523 this.watcherConfig = new nodefony.kernelWatcher(this.configPath, defaultWatcher.call(this, regConfigFile), this);524 this.watcherConfig.listenWatcherConfig();525 this.watcherConfig.setSockjsServer(this.sockjs);526 this.kernel.on("onTerminate", () => {527 this.log("Watching Ended : " + this.watcherConfig.path, "INFO");528 this.watcherConfig.close();529 });530 }531 //services532 if (services) {533 this.watcherService = new nodefony.kernelWatcher(this.servicesPath, defaultWatcher.call(this, regJs), this);534 this.watcherService.listenWatcherServices();535 this.watcherService.setSockjsServer(this.sockjs);536 this.kernel.on("onTerminate", () => {537 this.log("Watching Ended : " + this.watcherService.path, "INFO");538 this.watcherService.close();539 });540 }541 //entities542 } catch (e) {543 throw e;544 }545 }546 reloadRouting(name, Path) {547 try {548 if (name === null) {549 let find = new moduleFindDependencies(Path, "routing", this);550 find.reload();551 } else {552 let fileClass = new nodefony.fileClass(Path);553 this.log("Reload Routing : " + Path);554 if (this.router) {555 this.router.reader(fileClass.path, this.name);556 }557 }558 } catch (e) {559 throw e;560 }561 }562 parseConfig(result) {563 if (result) {564 let config = null;565 for (let ele in result) {566 let ext = null;567 switch (true) {568 case this.kernel.regBundleName.test(ele):569 let myname = this.kernel.regBundleName.exec(ele);570 let name = myname[1] || myname[2];571 config = this.getParameters("bundles." + name);572 if (config) {573 ext = nodefony.extend(true, {}, config, result[ele]);574 this.log("\x1b[32m OVERRIDING\x1b[0m CONFIG bundle : " + name, "DEBUG");575 } else {576 ext = result[ele];577 this.log("\x1b[32m OVERRIDING\x1b[0m CONFIG bundle : " + name + " BUT BUNDLE " + name + " NOT YET REGISTERED ", "WARNING");578 }579 if (this.kernel.bundles[name]) {580 this.kernel.bundles[name].settings = ext;581 this.setParameters("bundles." + name, this.kernel.bundles[name].settings);582 } else {583 this.setParameters("bundles." + name, ext || {});584 }585 break;586 /*case /^version$/.test(ele):587 try {588 let res = semver.valid(result[ele]);589 if (!res) {590 this.log("Bad Bundle Semantic Versioning : " + result[ele] + " Check http://semver.org ", "WARNING");591 }592 } catch (e) {593 this.log(e, "ERROR");594 }595 break;*/596 case /^locale$/.test(ele):597 if (result[ele]) {598 this.locale = result[ele];599 }600 break;601 }602 }603 config = this.getParameters("bundles." + this.name);604 if (config && Object.keys(config).length) {605 this.log("\x1b[32m BUNDLE IS ALREADY OVERRIDING BY AN OTHERONE INVERT\x1b[0m CONFIG " + util.inspect(config), "WARNING");606 this.settings = nodefony.extend(true, {}, result, config);607 this.setParameters("bundles." + this.name, this.settings);608 } else {609 this.settings = result;610 this.setParameters("bundles." + this.name, this.settings);611 }612 this.settings.version = this.version;613 //console.log(this.settings)614 }615 }616 log(pci, severity, msgid, msg) {617 if (!msgid) {618 msgid = "BUNDLE " + this.name;619 }620 return super.log(pci, severity, msgid, msg);621 }622 loadFile(Path, force) {623 try {624 return this.autoLoader.load(Path, force);625 } catch (e) {626 console.error(e);627 throw e;628 }629 }630 getName() {631 return this.name;632 }633 getController(name) {634 return this.controllers[name];635 }636 async registerServices() {637 let service = await this.findResult.find("services")638 .find(regService);639 if (!service.length) {640 this.log("Bundle " + this.name + " No Services Found", "DEBUG");641 }642 service.forEach((ele) => {643 try {644 this.loadService(ele);645 } catch (e) {646 this.log(e, "ERROR");647 }648 });649 return service;650 }651 loadService(ele, force) {652 try {653 let Class = this.loadFile(ele.path, force);654 if (typeof Class === "function") {655 Class.prototype.bundle = this;656 if (force) {657 if (nodefony.services[Class.name]) {658 delete nodefony.services[Class.name];659 }660 }661 nodefony.services[Class.name] = Class;662 this.log("Register Service : " + Class.name, "DEBUG");663 return Class;664 } else {665 throw new Error("Bundle Register Service : " + ele.path + " error Service bad format " + typeof Class);666 }667 } catch (e) {668 throw e;669 }670 }671 reloadService(name, Path, force) {672 try {673 let File = new nodefony.fileClass(Path);674 this.reloadWatcherService(File, Path, force);675 } catch (e) {676 throw e;677 }678 }679 reloadWatcherService(File, Path, force) {680 try {681 if (File) {682 let Class = this.loadService(File, force);683 let injector = this.injectionService.getInjector(Class.name);684 if (injector) {685 injector.getServiceClass({686 class: Class687 });688 injector.getServiceName();689 injector.restartService();690 } else {691 let error = new Error(Class.name + " Service is not found or not register reboot server or check config file ");692 throw error;693 }694 } else {695 if (File === null) {696 let find = new moduleFindDependencies(Path, "service", this);697 find.reload();698 }699 }700 } catch (e) {701 throw e;702 }703 }704 async findControllerFiles() {705 this.controllerFiles = await this.findResult.find("controller").find(this.regController);706 if (!this.controllerFiles.length) {707 this.log("Bundle " + this.name + " controller directory not found", "DEBUG");708 }709 return this.controllerFiles;710 }711 async registerControllers(result) {712 if (result) {713 this.controllerFiles = result;714 }715 if (this.controllerFiles.length) {716 this.controllerFiles.forEach((ele) => {717 let res = this.regController.exec(ele.name);718 if (res) {719 let name = res[1];720 this.loadController(name, ele.path, false);721 }722 });723 }724 }725 reloadWatcherControleur(name, Path) {726 try {727 if (name === null) {728 let find = new moduleFindDependencies(Path, "controller", this);729 find.reload();730 } else {731 this.loadController(name, Path, true);732 }733 } catch (e) {734 throw e;735 }736 }737 loadController(name, Path, force) {738 if (this.controllers[name]) {739 delete this.controllers[name];740 this.controllers[name] = null;741 }742 let Class = null;743 try {744 Class = this.loadFile(Path, force);745 let res = regClassController.exec(Class.name);746 if (res) {747 name = res[1];748 } else {749 this.log("Controller Bad Class name :" + Class.name + " file : " + Path, "ERROR");750 this.log("Controller take the file name !!! " + name, "WARNING");751 }752 if (typeof Class === "function") {753 Class.prototype.name = name;754 Class.prototype.path = Path;755 Class.prototype.bundle = this;756 this.controllers[name] = Class;757 Class.prototype.annotation = null;758 let severity = "DEBUG";759 if (force) {760 severity = "INFO";761 }762 this.log("Load " + name + " Controller : '" + Path + "'", severity);763 if (this.router && true /*Class.prototype.annotation*/ ) {764 this.router.reader(Path, this.name);765 }766 } else {767 throw new Error("Bundle " + this.name + " Load Controller : " + Path + " Controller bad format module.exports must return a class ");768 }769 } catch (e) {770 throw e;771 }772 return Class;773 }774 async findViewFiles() {775 this.viewFiles = await this.resourcesFiles.find("views");776 if (!this.viewFiles.length) {777 this.log("Bundle " + this.name + " No views Found", "DEBUG");778 }779 return this.viewFiles;780 }781 async compileTemplate(file, basename, name) {782 return new Promise(async (resolve, reject) => {783 if (this.views[basename] && this.views[basename][name] && this.views[basename][name].template) {784 this.views[basename][name].template = null;785 delete this.views[basename][name].template;786 }787 let template = null;788 try {789 template = await this.serviceTemplate.compile(file);790 } catch (e) {791 return reject(e);792 }793 if (template) {794 this.views[basename][name].template = template;795 return resolve(template);796 }797 return resolve(null);798 });799 }800 setView(file) {801 let basename = path.basename(file.dirName);802 let res = null;803 let name = null;804 if (basename !== "views") {805 let dir = new nodefony.fileClass(file.dirName);806 let tab = [dir.name];807 while (path.basename(dir.dirName) !== "views") {808 dir = new nodefony.fileClass(dir.dirName);809 tab.push(dir.name);810 }811 basename = tab.reverse().join("/");812 if (!this.views[basename]) {813 this.views[basename] = {};814 }815 } else {816 basename = ".";817 if (!this.views[basename]) {818 this.views[basename] = {};819 }820 }821 res = this.regTemplateExt.exec(file.name);822 if (res) {823 name = res[1];824 if (this.views[basename][name]) {825 delete this.views[basename][name];826 }827 return this.views[basename][name] = {828 name: name,829 basename: basename,830 file: file,831 template: null832 };833 }834 return null;835 }836 async recompileTemplate(file, force) {837 return new Promise(async (resolve, reject) => {838 let bundle = this;839 // OVERRIDE VIEWS BUNDLE in APP DIRECTORY840 if (this.name === "app") {841 let pattern = null;842 if (this.kernel.platform === "win32") {843 let prefix = path.resolve(this.viewsPath);844 prefix = prefix.replace(/\\/g, "\\\\");845 pattern = prefix + "\\\\(\\w+)-bundle\\\\views\\\\(.+\\.twig)";846 } else {847 pattern = path.resolve(this.viewsPath, "(\\w+)-bundle", "views", "(.+\\.twig)");848 }849 let reg = new RegExp("^" + pattern + "$");850 let res = reg.exec(file.path);851 if (res && res[1]) {852 bundle = this.kernel.getBundle(res[1]);853 this.log(`\x1b[32m APP OVERRIDING VIEWS\x1b[0m Bundle : ${bundle.name} File : ${file.name}`, "DEBUG");854 }855 }856 try {857 let ele = bundle.setView(file);858 if (ele) {859 if (force) {860 await bundle.compileTemplate(ele.file, ele.basename, ele.name);861 } else {862 if (this.kernel.type !== "CONSOLE") {863 await bundle.compileTemplate(ele.file, ele.basename, ele.name);864 }865 }866 } else {867 this.log(` DROP VIEW TEMPLATE : ${file.path}`, "DEBUG");868 }869 return resolve(ele);870 } catch (e) {871 return reject(e);872 }873 });874 }875 async registerViews(result) {876 return new Promise(async (resolve, reject) => {877 let views = null;878 if (result) {879 views = await this.findViewFiles(result);880 } else {881 views = this.viewFiles;882 }883 views.getFiles().forEach(async (file) => {884 try {885 let ele = await this.recompileTemplate(file, true);886 if (ele) {887 if (ele.basename === ".") {888 this.log("Register Template : '" + this.name + "Bundle:" + "" + ":" + ele.name + "'", "DEBUG");889 } else {890 this.log("Register Template : '" + this.name + "Bundle:" + ele.basename + ":" + ele.name + "'", "DEBUG");891 }892 }893 } catch (e) {894 return reject(e);895 //throw e;896 }897 });898 return resolve(views);899 });900 }901 getView(viewDirectory, viewName) {902 if (this.views[viewDirectory]) {903 let res = this.regTemplateExt.exec(viewName);904 if (res) {905 let name = res[1];906 if (this.views[viewDirectory][name]) {907 return this.views[viewDirectory][name].file;908 }909 throw new Error("Bundle " + this.name + " directory : " + viewDirectory + " GET view file Name : " + viewName + " Not Found");910 } else {911 throw new Error("Bundle " + this.name + " directory : " + viewDirectory + " GET view file Name : " + viewName + " Not Found");912 }913 } else {914 throw new Error("Bundle " + this.name + " GET view directory : " + viewDirectory + " Not Found");915 }916 }917 getTemplate(viewDirectory, viewName) {918 if (this.views[viewDirectory]) {919 let res = this.regTemplateExt.exec(viewName);920 if (res) {921 let name = res[1];922 if (this.views[viewDirectory][name]) {923 return this.views[viewDirectory][name].template;924 }925 throw new Error("Bundle " + this.name + " directory : " + viewDirectory + " GET view file Name : " + viewName + " Not Found");926 } else {927 throw new Error("Bundle " + this.name + " directory : " + viewDirectory + " GET view file Name : " + viewName + " Not Found");928 }929 } else {930 throw new Error("Bundle " + this.name + " GET view directory : " + viewDirectory + " Not Found");931 }932 }933 async findI18nFiles(result) {934 let trans = null;935 if (result) {936 trans = await result.find("translations");937 } else {938 trans = await this.resourcesFiles.find("translations");939 }940 if (!trans.length || !trans[0]) {941 this.log("Bundle " + this.name + " No Translation Found", "DEBUG");942 return trans;943 }944 return trans[0].children;945 }946 getfilesByLocal(locale, dir) {947 let reg = new RegExp("^(.*)\.(" + locale + ")\.(.*)$");948 return dir.find(reg);949 }950 async registerI18n(locale, result) {951 let dir = null;952 if (result) {953 dir = await this.findI18nFiles(result);954 } else {955 dir = this.i18nFiles;956 }957 //console.trace(dir)958 if (!dir || !dir.length) {959 return;960 }961 let files = null;962 if (locale) {963 files = this.getfilesByLocal(locale, dir);964 } else {965 files = this.getfilesByLocal(this.translation.defaultLocale, dir);966 if (!files.length) {967 let bundleLocal = this.getParameters("bundles." + this.name + ".locale");968 files = this.getfilesByLocal(bundleLocal || this.translation.defaultLocale, dir);969 if (bundleLocal && !files.length) {970 this.log(`Translation File Locale : ${bundleLocal} not found`, "DEBUG");971 }972 }973 }974 files.getFiles().forEach((file) => {975 let domain = file.match[1];976 let Locale = file.match[2];977 this.log(`Read I18n file : ${file.path}`, 'DEBUG');978 this.translation.reader(file.path, this.name, Locale, domain);979 });980 }981 async registerCommand(store) {982 this.commandFiles = await this.findResult.find("Command")983 .find(regCommand);984 if (!this.commandFiles.length) {985 this.log(`Bundle ${this.name} No Command Found`, "DEBUG");986 return this.commandFiles;987 }988 let command = null;989 this.commandFiles.getFiles().forEach((file) => {990 let res = regCommand.exec(file.name);991 if (res) {992 try {993 command = this.loadFile(file.path);994 command.prototype.bundle = this;995 store.push(command);996 } catch (e) {997 throw new Error(e + " FILE COMMAND : " + file.path);998 }999 if (!command) {1000 throw new Error("Command : " + file + " BAD FORMAT");1001 }1002 let name = command.name || res[1];1003 if (!name) {1004 throw new Error("Command : " + name + "BAD FORMAT NANE ");1005 }1006 }1007 });1008 }1009 async getPublicDirectory() {1010 try {1011 return await new nodefony.Finder2({1012 excludeDir: /^docs$|^tests|^node_modules|^assets$/1013 })1014 .in(path.resolve(this.path, "Resources", "public"));1015 } catch (e) {1016 return null;1017 }1018 return null;1019 }1020 async registerEntities() {1021 this.entityFiles = await this.findResult.find("Entity")1022 .find(this.kernel.getOrm())1023 .find(regEntity);1024 if (!this.entityFiles.length) {1025 this.log(`Bundle ${this.name} No Entity Found`, "DEBUG");1026 return this.entityFiles;1027 }1028 this.entityFiles.forEach((file) => {1029 let res = regEntity.exec(file.name);1030 let Class = null;1031 if (res) {1032 try {1033 Class = this.loadFile(file.path);1034 } catch (e) {1035 this.log("LOAD ENTITY " + file.path, "ERROR");1036 throw e;1037 }1038 try {1039 this.entities[Class.name] = new Class(this);1040 this.log("LOAD ENTITY " + Class.name + " : " + file.name, "DEBUG");1041 } catch (e) {1042 this.log(e, "WARNING");1043 }1044 } else {1045 this.log("Drop Entity file " + file.name, "WARNING");1046 }1047 });1048 }1049 getEntity(name) {1050 if (this.entities[name]) {1051 return this.entities[name];1052 }1053 return null;1054 }1055 getEntities() {1056 if (this.entities) {1057 return this.entities;1058 }1059 return null;1060 }1061 async registerFixtures() {1062 this.fixtureFiles = await this.findResult.find("Fixtures")1063 .find(regFixtures);1064 if (!this.fixtureFiles.length) {1065 this.log("Bundle " + this.name + " No Fixutures Found", "DEBUG");1066 return this.entityFiles;1067 }1068 this.fixtureFiles.forEach((file) => {1069 let res = regFixtures.exec(file.name);1070 if (res) {1071 let name = res[1];1072 let Class = this.loadFile(file.path);1073 if (typeof Class === "function") {1074 Class.prototype.bundle = this;1075 this.fixtures[name] = Class;1076 this.log("LOAD FIXTURE : " + file.name, "DEBUG");1077 } else {1078 this.log("Register FIXTURE : " + name + " error FIXTURE bad format");1079 }1080 }1081 });1082 }1083 getFixture(name) {1084 if (this.fixtures[name]) {1085 return this.fixtures[name];1086 }1087 return null;1088 }1089 getFixtures() {1090 if (this.fixtures) {1091 return this.fixtures;1092 }1093 return null;1094 }1095}1096nodefony.Bundle = Bundle;...

Full Screen

Full Screen

run.js

Source:run.js Github

copy

Full Screen

...85 process.exit(1);86 }87 });88}89function findWebpackConfig() {90 let configLocation91 if (config.webpackConfigPath) {92 configLocation = config.webpackConfigPath;93 }94 else if (fs.existsSync('./node_modules/@vue/cli-service/webpack.config.js')) {95 configLocation = './node_modules/@vue/cli-service/webpack.config.js';96 }97 else if (fs.existsSync('./build/webpack.base.conf.js')) {98 configLocation = './build/webpack.base.conf.js';99 }100 return configLocation;101}102// TODO: add config file so users can customize webpack config location103function runTests() {104 let webpackConfig = findWebpackConfig();105 if (!webpackConfig) {106 quit("Error: Could not find webpack config file.")107 }108 try {109 let child = spawn('./node_modules/.bin/mochapack',110 [111 '--require',112 workingDir + '/generated-setup.js',113 '--webpack-config',114 webpackConfig,115 workingDir + '/*.vuetest.spec.js'116 ],117 {118 stdio: 'inherit'...

Full Screen

Full Screen

Themes.js

Source:Themes.js Github

copy

Full Screen

...93 const themePath = path.join(source, name);94 return {95 name,96 path: themePath,97 config: this.findWebpackConfig(themePath),98 languages: this.findLanguages(themePath),99 };100 });101 }102 /**103 * Find all language files of a single theme.104 * @param {string} themePath The path of a theme105 * @return {Array}106 */107 findLanguages(themePath) { // eslint-disable-line class-methods-use-this108 const localeRegex = /^[a-z]{2}-[a-z]{2}.json/i;109 const localeFolder = `${themePath}/locale`;110 let languages = [];111 if (fs.existsSync(localeFolder)) {112 const files = fs.readdirSync(localeFolder);113 // Collect the languages from the folder114 languages = files.reduce((matches, file) => {115 if (localeRegex.test(file)) {116 matches.push(file.substr(0, file.length - 5));117 }118 return matches;119 }, []);120 }121 return languages;122 }123 /**124 * Attempt to find a webpack.config.js inside the theme.125 * When a config is not found then a default is used.126 * @param {string} themePath The path to look for a config.127 * @returns {string} A path to a Webpack config128 */129 findWebpackConfig(themePath) { // eslint-disable-line class-methods-use-this130 const themeConfig = path.join(themePath, 'webpack.config.js');131 if (fs.existsSync(themeConfig)) {132 return themeConfig;133 }134 return path.join(__dirname, 'webpack.config.js');135 }136}...

Full Screen

Full Screen

mdx-paper.js

Source:mdx-paper.js Github

copy

Full Screen

...64 console.log('starting dev server…')65 console.log(argv)66 setEnvironmentVariables(argv)67 process.env.NODE_ENV = 'development'68 const webpackConfig = findWebpackConfig()69 webpackConfig.mode = 'development'70 webpackConfig.devtool = 'cheap-eval-source-map'71 const compiler = webpack(webpackConfig)72 const devServer = new WebpackDevServer(compiler, {73 hot: true,74 historyApiFallback: true,75 inline: false,76 })77 const hostname = 'localhost'78 const port = process.env.PORT || 808079 devServer.listen(port, hostname, () => {80 console.log(`Listening at http://${hostname}:${port}`)81 })82 }83 )84 .command(['build [file]'], 'build the paper', builder, argv => {85 console.log('building…')86 console.log(argv)87 setEnvironmentVariables(argv)88 process.env.NODE_ENV = 'production'89 const webpackConfig = findWebpackConfig()90 webpackConfig.mode = 'production'91 const compiler = webpack(webpackConfig)92 compiler.run((err, stats) => {93 stats.compilation.errors.forEach(error => {94 console.error(error)95 })96 if (err) {97 console.log(err)98 throw err99 }100 console.log('built')101 })102 })103 .help().argv

Full Screen

Full Screen

webpack.js

Source:webpack.js Github

copy

Full Screen

1const { findConfigFile, parseConfig } = require('@gera2ld/plaid/util/helpers');2const DEFAULT_WEBPACK = require.resolve('../config/webpack.conf');3async function findWebpackConfig() {4 let filepath;5 try {6 filepath = await findConfigFile('webpack', 'No webpack.conf.js is found');7 } catch (err) {8 filepath = DEFAULT_WEBPACK;9 }10 return filepath;11}12async function loadWebpackConfig() {13 const filepath = await findWebpackConfig();14 const config = await parseConfig(require(filepath));15 return config;16}17function loadDefaultWebpackConfig() {18 return parseConfig(require(DEFAULT_WEBPACK));19}20function formatMessage(item) {21 return item.message;22}23function webpackCallback(resolve, reject) {24 return (err, stats) => {25 if (err) {26 console.error('[FATAL]', err);27 return reject(err);...

Full Screen

Full Screen

build.js

Source:build.js Github

copy

Full Screen

...19 process.argv = [20 process.argv[0],21 'webpack-cli',22 '--config',23 await findWebpackConfig(),24 ];25 require('webpack-cli/bin/cli');26}27async function buildWithAPI() {28 const compiler = webpack(await loadWebpackConfig());29 await new Promise((resolve, reject) => compiler.run(webpackCallback(resolve, reject)));30}31async function build(options) {32 if (options.analyze) process.env.RUN_ENV = 'analyze';33 await prebuild(options);34 await (options.api ? buildWithAPI : buildWithCLI)();35}...

Full Screen

Full Screen

develop.js

Source:develop.js Github

copy

Full Screen

...22 argv.push('-w');23 }24 argv.push(25 '--config',26 await findWebpackConfig(),27 );28 process.argv = argv;29 require(module);30}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const webpackConfig = require('@cypress/webpack-preprocessor')2const findWebpackConfig = require('find-webpack-config')3module.exports = (on, config) => {4 const options = {5 webpackOptions: findWebpackConfig()6 }7 on('file:preprocessor', webpackConfig(options))8}9const webpackConfig = require('@cypress/webpack-preprocessor')10const findWebpackConfig = require('find-webpack-config')11module.exports = (on, config) => {12 const options = {13 webpackOptions: findWebpackConfig()14 }15 on('file:preprocessor', webpackConfig(options))16}17const webpackConfig = require('@cypress/webpack-preprocessor')18const findWebpackConfig = require('find-webpack-config')19module.exports = (on, config) => {20 const options = {21 webpackOptions: findWebpackConfig()22 }23 on('file:preprocessor', webpackConfig(options))24}25const webpackConfig = require('@cypress/webpack-preprocessor')26const findWebpackConfig = require('find-webpack-config')27module.exports = (on, config) => {28 const options = {29 webpackOptions: findWebpackConfig()30 }31 on('file:preprocessor', webpackConfig(options))32}33const webpackConfig = require('@cypress/webpack-preprocessor')34const findWebpackConfig = require('find-webpack-config')35module.exports = (on, config) => {36 const options = {37 webpackOptions: findWebpackConfig()38 }39 on('file:preprocessor', webpackConfig(options))40}41const webpackConfig = require('@cypress/webpack-preprocessor')42const findWebpackConfig = require('find-webpack-config')43module.exports = (on, config) => {44 const options = {45 webpackOptions: findWebpackConfig()46 }47 on('file:preprocessor', webpackConfig(options))48}

Full Screen

Using AI Code Generation

copy

Full Screen

1const webpackConfig = require('@cypress/webpack-preprocessor')2const { findWebpackConfig } = require('@cypress/webpack-preprocessor')3const webpackOptions = findWebpackConfig()4const options = {5 watchOptions: {}6}7module.exports = on => {8 on('file:preprocessor', webpackConfig(options))9}

Full Screen

Using AI Code Generation

copy

Full Screen

1const webpackPreprocessor = require('@cypress/webpack-preprocessor');2const findWebpackConfig = require('find-webpack-config');3const webpackConfig = findWebpackConfig();4const options = {5};6module.exports = on => {7 on('file:preprocessor', webpackPreprocessor(options));8};9const webpackPreprocessor = require('@cypress/webpack-preprocessor');10const findWebpackConfig = require('find-webpack-config');11const webpackConfig = findWebpackConfig();12const options = {13};14module.exports = on => {15 on('file:preprocessor', webpackPreprocessor(options));16};17const webpackPreprocessor = require('@cypress/webpack-preprocessor');18const findWebpackConfig = require('find-webpack-config');19const webpackConfig = findWebpackConfig();20const options = {21};22module.exports = on => {23 on('file:preprocessor', webpackPreprocessor(options));24};25{26 "env": {27 }28}29{

Full Screen

Using AI Code Generation

copy

Full Screen

1const webpackConfig = require("@cypress/webpack-preprocessor");2const path = require("path");3const findWebpackConfig = require("find-webpack");4module.exports = (on, config) => {5 const options = {6 webpackOptions: findWebpackConfig(),7 watchOptions: {},8 };9 on("file:preprocessor", webpackConfig(options));10};11const webpackConfig = require("@cypress/webpack-preprocessor");12const path = require("path");13const findWebpackConfig = require("find-webpack");14module.exports = (on, config) => {15 const options = {16 webpackOptions: findWebpackConfig(),17 watchOptions: {},18 };19 on("file:preprocessor", webpackConfig(options));20};

Full Screen

Using AI Code Generation

copy

Full Screen

1const findWebpackConfig = require('@cypress/webpack-preprocessor')2const webpackOptions = findWebpackConfig()3module.exports = (on, config) => {4 on('file:preprocessor', findWebpackConfig())5}6module.exports = (on, config) => {7 on('file:preprocessor', webpackOptions)8}9module.exports = (on, config) => {10 on('file:preprocessor', require('@cypress/webpack-preprocessor'))11}12module.exports = (on, config) => {13 on('file:preprocessor', require('@cypress/webpack-preprocessor')())14}15module.exports = (on, config) => {16 on('file:preprocessor', require('@cypress/webpack-preprocessor')({}))17}18module.exports = (on, config) => {19 on('file:preprocessor', require('@cypress/webpack-preprocessor')({}))20}21module.exports = (on, config) => {22 on('file:preprocessor', require('@cypress/webpack-preprocessor')({}))23}24module.exports = (on, config) => {25 on('file:preprocessor', require('@cypress/webpack-preprocessor')({}))26}27module.exports = (on, config) => {28 on('

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const findWebpackConfig = require('find-webpack');3const { get } = require('lodash');4const webpackConfig = findWebpackConfig();5const alias = get(webpackConfig, 'resolve.alias');6const pathToPlugin = alias['@cypress/code-coverage/support'];7require(path.join(process.cwd(), pathToPlugin));8require('../test');

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful