Cucumber JS and actually getting something done - node.js

After being completely confused and googling tutorial after tutorial, reading books about cucumber that do not cover the JS implementation, I got over the fear of flames and decided to post my question here.
I have setup Cucumber-JS on my box, running fine. I use CoffeeScript, because I am lazy. I got my features folder, have my .feature written. Got my step definition and figured out that Cucumber JS requires a 'World' thingie to be anything near useful. I also discovered just moments ago, there can be some env.js tweaking to make this setup find the rest of my app.
I am not building a web based app, as I want some core logic to be worked out first. Where my trouble starts is the part how I am supposed to continue now.
I have a folder called 'lib' in the project root. Inside it, it is going to have my JS app, which I will eventually be running through NodeJS.
What changes do I have to make to env.js, world.coffee and mystep definition to be able to test my code I am developing in lib/myapp.coffee?
Thank you!

Eventually, I found out this is no Cucumber thing. It has to do with NodeJS and the way it handles modules. I eventually ended here:
http://www.sitepoint.com/understanding-module-exports-exports-node-js/

Related

Convert existing Angular project to Universal, encounter 'referenceerror: navigator is not defined'

I recently faced the task of converting a fairly mature angular project to SSR because I had overestimated the search power of SEO in angular projects. I'm not familiar with node, my angular project is on an apache server and uses php(slim) as the backend api, however, when I started trying to use "most of the tutorials", i.e., the first step, introducing nguniversal/express-engine into the project, it went well, npm did not report any errors.
Then I tried to run npm run build:ssr and it also worked fine. The problem is that when I run npm run serve:ssr, it ends up throwing a "ReferenceError: navigator is not defined" error...
Earlier, I built a completely clean angular project for testing, from build:ssr to run serve:ssr. Even I specified node xxxx/xxxx/main.js directly, no problem, which is obvious, because the angular project for testing is absolutely clean.
However, this does not work on my current "existing angular project". Yes, I fully understand that SSR doesn't allow for navigator or most so-called DOM manipulation, and although I'm not familiar with angular universal yet, I've previewed it and I know that's not possible, but here's the biggest problem :
In this existing angular project, there is no any navigator operations, not even a single line of code
In fact, main.js is also generated automatically, I can't stop it at all, I don't understand why there is "navigator" written in main.js?
I've checked many so-called solutions, including writing something in server.ts, but nothing helps, how can I continue? This is really quite desperate!
Big thank any help!

How to debug a serverless framework plugin?

I've searched throughout google about this question and I had no success...
I want to work on a serverless plugin fix, but I don't know how to attach the process to debug the code.
Currently, I'm using vscode and the plugin was developed using nodejs + typescript.
Does anyone have any tip or article explaining how to do that?
As every other process, that you want to debug, you need to run it and somehow connect the debugger to it.
You need to remember, that Serverless Framework is written in JS/TS, so it runs in Node.js. So you can debug it quite easily, if you are developing your Lambdas in Node.js, as it's quite common environment.
How to do it using Jetbrains/Webstorm/IntelliJ
Go to your node_modules directory and find the source code of the plugin, that you want to debug.
In the source code place the breakpoint.
Now Create a new "Run configuration" in IDE for NPM, that should be similar to mine:
4. Make sure you've chosen the correct package.json!
5. Now simply start debugging, like you normally do, but choose the run configuration, that you've just created.
In my example I'm using package script from package.json, but it could be also any other script, that triggers serverless deploy or serverless print in the end.
And that's it! Breakpoints should be triggered normally, like when you debug your own JS code.

How to debug a react.js library

I have been using react for about a year now and i recently wanted to delve into react-beautiful-dnd. I've built plugins for vanilla js and jQuery in the past , but i am not to sure about how to go about building a react.js plugin or even debug it. i am more interested in debugging this plugin and seeing how it works more then anything , so how exactly do i go about doing it ?
Typically with a JS plugin, its mostly one file , so a console.log inside each function would give you a clear enough understanding of why and when a certain function is triggered , how would you go about doing the same with a react.js plugin ?
There are multiple ways to debug.
node debug app.js
node-inspector
console
util
Well, I use a lot of well place console.log, console.dir and util.inspect statements throughout my code and follow the logic that way.
react-beautiful-dnd
Unfortunately there is not much documentation and do-how thing for given topic. But here is what I found helpful. you can follow this link for Quick start guide: https://github.com/atlassian/react-beautiful-dnd/issues/363
The codesandbox examples from the docs:
https://github.com/atlassian/react-beautiful-dnd#basic-usage-examples
Sample Project: https://github.com/jacobwicks/rbdnd-2-list-example
All Examples
Basic usage examples
We have created some basic examples on codesandbox for you to play with directly:
Simple vertical list
Simple horizontal list
Simple DnD between two lists
To Debug any Library:
Here's how you can debug that library. This is the most basic method.
Install it.
Check what you are using and what you need to debug.
Find that method in the node_modules.
Check if that method has any declaration in the code.
If yes put some console logs and see if they get printed on console.
Then check console for your logs.
Carry on the process of console logs until you get what you are looking for.
You have to find library's function you want to debug in node_module and console.log from there. You may need to console.log the parsed file usually found in node_module/plugin/lib or node_module/plugin/dist rather then the .jsx file in node_module/plugin/src.
How do I debug Node.js applications?.
This has quite a few answers on how you can go about debugging your react application.

How add a new extention?

I have a simple project of viewer on NodeJs: https://github.com/Autodesk-Forge/viewer-nodejs-tutorial with some basic exstention. I want to know how can I add the new extention from https://github.com/jeremytammik/forgefader to my project?
ForgeFader is based on React and uses ES6 syntax, One way to get started will be taking a look at the React Boiler plates we have in order for you to start getting familiar with it. https://github.com/Autodesk-Forge/forge-react-boiler.nodejs
After you are able to use this, you will be able to start checking the extension code in order to be able to use it in your project, It will require some work on your side, unfortunately this is not a plug and play extension like the ones used in the basic NodeJs tutorial.
Jeremy has done a great work documenting all his steps in the readme of the Fader repo you already have, I would suggest going over it.

Creating modules/HMVC in sails.js

I am trying to make a separation in my new SailsJS app by creating modules/HMVC, just like ASP.NET MVC, and Codeigniter PHP. These frameworks provide a mechanism for handling such a separation. Do any one have an idea how to implement this in SailsJS?
There is some development taking place in that direction, I'm not quite sure whether or not anything usable already exists, at least I haven't been able to find anything final so far. Two threads where adding HMVC to sails was discussed are
https://github.com/balderdashy/sails/issues/1191
https://github.com/balderdashy/sails/issues/594
I think the most recent sails plugin/backend components system discussion is balderdashy/sails/pull/2083.
It looks like the most viable module solution today is balderdashy/sails-hook-subapps, an example of a sails hook. Hopefully, it works with 0.12.x and gets some attention/docs soon!
Additionally, the project sailorjs/sailorjs appears to do exactly this as a fork of sails from version 0.10.x, though I don't know if there are plans ot utilize that work in sails.js.

Resources