How to make IDEA recognise keywords from Jasmine Node.js package? - node.js

I've got an IDEA 14.1.2 project using the Jasmine Node module for testing. Unfortunately IDEA doesn't recognise Jasmine function names like beforeEach, describe, it and expect, even though everything seems valid (the tests run fine). That is, when hovering over any of these I get a message like "Unresolved function or method function_name()", and when Ctrl-clicking I get the message "Cannot find declaration to go to".
Relevant settings:
In Languages & Frameworks → JavaScript → Libraries the following are checked:
Node.js v0.12.2 Core Modules (type Global)
HTML (type Predefined)
HTML5 / ECMAScript 5 (type Predefined)
Node.js Globals (type Predefined)
In Languages & Frameworks → Node.js and NPM (NodeJS JetBrains plugin 141.712):
the Node interpreter is set (it's in a subdirectory of the project),
"Node.js v0.12.2 Core Modules is set up", and
under Packages "jasmine" is listed as version 2.2.1 (latest).
Maybe I need to index internal Node modules, but I don't have the relevant check box in Languages & Frameworks → Node.js and NPM. Is this not available in this version of the plugin?
I've tried invalidating caches and restarting.

You need to add a TypeScript definition file as described here.
Go to Project Settings > Languages & Frameworks > JavaScript > Libraries, click Download, select Typescript community stubs from the combobox, choose jasmine and click Download and Install.

Related

How can I use the node.js v8 module in a react app?

I'm trying to use the serialization API from the node.js v8 module in my react app (created with create-react-app) but it doesn't seem to work.
According to the documentation it should just be a case of importing/requiring the module. When I try this, it all appears to be working as expected - no errors. I can even access methods like .serialize() and .deserialize() on the v8 object too - great. But when I try to actually run my project (using react-scripts start) I get a compilation error:
Module not found: Can't resolve 'v8' in '...'
Is it looking for a file called "v8.js" to import rather than using the node module for some reason? How do I get around this?
node_modules is only a concept when working within the node ecosystem. So it is only possible to import "v8" when within a node process.
Since you ask about a "react app" that seems to imply that you are writing something for the browser. Which now has modules which use import/export (similar to require/module.exports from node), however, that still doesn't mean that the "v8" package will be present.
Many of node's packages are C++ backed (or to use the technical term, they are "native packages") instead of being purely written in JS. Also, it should be noted that unlike dependencies listed in your "package.json" file, none of the node packages are actually downloaded when you run npm install since they are all bundled with your installation of node.

How to enable Node.js code autocompletion in VSCode?

I have installed Visual Studio Code and Node.js and both basically work, but autocomplete is not (completely) working. If I type 'console.' I do indeed see a list popup. Likewise if I do:
const http = require("http");
http.
But if I simply type 'process.' I don't see anything. In fact as soon as I type '.' Code autocompletes 'process' to 'ProcessingInstruction'. I was expecting to see argv pop up, along with all the other stuff you see if you type 'process' at a Node prompt.
Here's what I see when I type 'console.':
Yay -- it works!
But here's what I see when I type 'process.' (I have to change the autocompleted 'ProcessingInstruction' back to 'process'):
Boo -- it doesn't know 'process'! :(
You will need to tell VS Code about the types in Node JS (as you hit at yourself in the comment). To do this you can install the types for node running the following command (assuming you have already run npm init):
npm install --save-dev #types/node
It will install the types for Node JS, which VS Code automatically picks up and you'll be auto-completing all Node JS-specific things going forward. You don't even have to restart VS Code.
As you are adding more dependencies to your project (if you will be doing so). Many of them have a #types/X package as well (if they don't have the already included in the package), which will allow autocomplete as well.
Per Microsoft's Documentation: https://code.visualstudio.com/docs/nodejs/working-with-javascript
IntelliSense for JavaScript libraries and frameworks is powered by TypeScript type declaration (typings) files.
Automatic type acquisition requires npmjs, the Node.js package manager, which is included with the Node.js runtime.
In my situation, I do not have npmjs installed and that's why automatic type acquisition fails.
*Edit, that is, after installing npm, my autocomplete starting working successfully for node related hints.
If you are using pure javascript for your node app, when including the required modules, they should be defined with single quotes instead of double-quotes. If you were using a code formatter extension like "Prettier" for instance, it adds it by default before the IntelliSense, then you would have to update your settings to use single quote.

How to set WebStorm for node.js?

I'm developing for ReactNative because I developer of front-end. (Using WebStorm)
But I got a job of server of node.js. (I want to using WebStorm too)
A lot of expression is occurrence like this.
I just clone some node.js project and open the project in WebStorm.
How do I set WebStorm for node.js?
(if I change setting for node.js, I wish ReactNative project is not changed.)
Please make sure that JavaScript Language Version (Settings/Preferences | Languages & Frameworks | JavaScript) is set to ECMAScript 6; looks as if ESMAScript 6 syntax (arrow functions, etc.) can't be parsed correctly

Typescript typings for protactor in a visual studio project

I am writing with protractor e2e tests for our Angular Webapp, since all your javascript code is writtin in typescript i would like to do the same for the tests. Now i have run into the problem that the protractor typescript NuGets are outdated protracotr v1.5.
These are based on the DefinitelyTyped typings, but i cant find them in their offical git repository. So where do i get working Typings?
I cant really get my head around nodejs so if there is a solution including nodejs i am happy to take it but would like to get some detailed explanation.
Errors are like:
Property 'stacktrace' does not exist on type 'typeof webdriver'
webdriver is defined in the selenium-webdriver.d.ts but apparently it is not complete

Visual Studio 2015: Bug setting TestFramework to Mocha for unit test files in NodeJS Project

I'm working on a Typescript project in Visual Studio (2015 Community edition) build server side unit tests using Mocha.
I however read that NodeJS Tools supports running within the VS Test Runner, and even Typescript unit tests. You have to set the TestFramework property of the file to 'Mocha'. The project I'm working on even already has existing tests which this is set for. However I don't get a dropdown option in the GUI to set it, it's just empty:
I'm using NTVS v1.1 (and Typescript 1.7). Am I missing something in my Visual Studio setup? The build type of the test .ts file is also already set to TypeScriptCompile. Perhaps more of a specific VS question than a programming question, but the environment/tools is so programmer's specific that I thought somebody here can help me.
PS Running tests manually each time is driving me crazy, and I bumped into too many problems with using a HTML spec runner which I tried first, because this server side tests (e.g. CommonJS require and import statements that my browser doesn't get) and also because it's TypeScript.
But alternative solutions are also welcome. I'm using grunt and am also experience using Gulp, I'm just hoping for a full solution, not something that'll cost me half a day to script together, debug and document..
Note: I DO get the dropdown to select Mocha Testframework for .js files (after including in VS project), but NOT for .ts files :S.
Hmm... pretty silly, but it seems indeed a GUI issue:
You simply have to type Mocha into the property field yourself manually.
In the case of Typescript there doesn't appear a dropdown (e.g. caret) on hoover in the 'TestFramework' field. My expectation was really fixed on the dropdown' experience beause it DOES do that for Javascript files and in so many other fields in the 'Properties' window.
So a short overview of things to do:
type yourself and make sure you don't type Mohca or something:).
Install Mocha locally
Make sure the BuildAction of the .ts file is set to TypeScriptCompile
I'm off fixing other issues, this Typescript is nice, but the tools and language are evolving too fast for the 'Google-based development' I have to rely too really work well :S.

Resources