Enabling Intellisense for Mocha - node.js

I'm running VS Code 1.0. I've already successfully added intellisense for a number of frameworks, i.e., Express, Restify, and even Gulp.
Now I'm trying to enable it for Mocha.
The minimum setup I'm doing is:
Create a folder.
npm init
npm install mocha
typings install mocha --ambient
Open Code in said folder.
Create a new file and try to type "describe".
Also, this guy got it working.

You just have to ad jsconfig.json file to the root of your project. It can even be empty.
Check this docs.

Related

How do I use Quokka with imported typescript files?

I've installed ts-node with NPM install, and tinkered with this for hours, I cant find any other documentation on the website as to why its not working. A quick google search has also turned up nothing; which is why I'm SURE its some small thing I'm missing. ts-node has also been installed globally AND in the project folder I'm getting the following error:
To import TypeScript files from quokka, `ts-node` module must be installed. 
It is also recommended to install `tsconfig-paths` module for tsconfig.json paths mapping. 
You may install the modules in your project or into quokka global folder by running `npm install ts-node tsconfig-paths` command inside the `~/.quokka/` folder. 
at ​​​Module.load​​​ ​internal/modules/cjs/loader.js:653​
at ​​​tryModuleLoad​​​ ​internal/modules/cjs/loader.js:593​
at ​​​Function.Module._load​​​ ​internal/modules/cjs/loader.js:585​
at ​​​require​​​ ​internal/modules/cjs/helpers.js:25​
at ​​​Object.<anonymous>​​​ ​frontEnd/datrix/src/app/Logic/DeveloperTemplate.ts:1​
at ​​​Module._compile​​​ ​internal/modules/cjs/loader.js:778​
does anyone have some insight on how this can be done?
I figured it out, I had to open the project file in vs code, not the directory above it.

Node package dependencies on IBM Cloud Foundry - require/module is not defined (Package not loading)

I am working on an application via the toolchain tool on IBM Cloud and editing the code via the Eclipse Orion IDE. As I am not accessing this through my local cli, my understanding is that in order to so call npm install {package}, I would just need to include the package in the package.json file under dependencies and require it in my app. However, when I load the application, I get the require is not defined indicating that the package has not been installed. Moreover, the require() is being used in the app.js file with the application being launched but not from files in my public directory.
After playing around further, it seems it might have to do with the way the directory tree is being traced as the error is only thrown in subdirectories. For example, require('express') works in app.js which is in the main directory ./ but fails when it is called in test.js in ./subdirectory/test.js. I feel like I'm missing something painfully simple like configuration of endpoint or something.
I've been searching around but I can't seem to find how to get the packages loaded, preferably without using the cli. Appreciate any pointers. Thanks!
Update: After playing around further, I am also getting module is not defined error when trying to require from another file in the same directory. For example module.exports = 'str' returns this error. While trying to require('./file') returns the require is not defined. It might have to do with how node is wrapping the functions?
Update 2: Tried "start": "npm install && node app.js" in package.json but no luck. Adding a build stage which calls npm install before deployment also does not work
Update 3: After adding npm install build stage, I am able to see that the dependencies have been successfully built via the logs. However, the require is not defined error still persists.
Update 4: Trying npm install from my CLI doesn't work as well even though all packages and dependencies are present
Update 5: Running cf restage or configuring cache via cacheDirectories does not work as well
Opened a related question regarding deployment here
Found out my confusion was caused due to me not realizing that require() cannot be used on the client side unless via tools such as Browserify.

firebase admin code completions not working in vscode

I have tried installing the typescript thing using :
npm install --save-dev #types/firebase
but with no luck .
There is no code completion or intellisense whatsoever for "firebase-admin" , "firebase-functions" . Whats methods can i use to fix this ?
I have tried adding this at the beginning of my node.js index file .
"/// <reference path="./node_modules/#types/firebase" />
With no luck here.
The typings for firebase and firebase admin are normally included into the NPM package, just peek in the node_modules folder. I made a little demo repo for you with the most common settings. The code completion worked as expected, the compilation as well.
https://github.com/giespaepen/firebase-admin-demo

Configure Mocha / NodeJS within VS Code - location of test folder - test files(s) undefined

Mocha is installed and runs fine through Terminal, Mocha Sidebar extension added in VS Code, however when using within VS Code it doesn't appear to find any tests within either a test folder I have set up, or a test folder I navigate to within VS Code
How do you alter the Mocha settings within VS Code to point it to a different/ correct location for the /test folder?
Is it possible to run tests on a folder you navigate to within VS code explorer and how to config that?
In the Output I am currently seeing the below:
Finding tests with Mocha on Node.js at "/usr/local/bin/node"
Running Mocha with Node.js at "/usr/local/bin/node"
No Mocha options are configured. You can set it under File > Preferences > Workspace Settings.
Test file(s):
undefined
I had this issue, and a couple of things solved it:
npm install -g glob
npm install -g mocha
npm install -g bluebird
Add "mocha.options": {} to the workspace configuration.
Add a glob option to the workspace configuration.
Restart VSCode.
Apparently not having global glob, mocha, and bluebird installed will cause it to fail on this.

How to create a simple (Hello World) node.js TypeScript project with ES6 modules?

Imagine a very simple program with a main file and some functions in a separate file, using ES6 modules and intended to be run with node.js.
my-utils.ts:
import * as fs from "fs";
export function readSimpleFile() {
return fs.fileReadSync("hello.txt", "utf-8");
}
main.ts:
import {readSimpleFile} from "./my-utils"
console.log(readSimpleFile());
What is the minimum set of files I need to add to the project and commands I have to run to get it building, running and checking types?
If you are to run a typescript project with node you need to have at least node, npm and typescript installed on your plateform.
Using an IDE to setup the project
Using intelliJ IDEA or Webstorm (they are the ones I know the best), the compilation of typescript into javascript is done automatically; you only need to do some settings.
Let us assume you have a file called project.ts containing your hello world code; IDEA or Webstorm will compile your code to project.js. Then you will only need to do node project.js to run your project.
Doing everything from scratch
First you need to know where exactly your npm packages are installed globally. This command can help you identify the path: npm config get prefix. In this folder, you should have a nodes_modules subfolder that contains the typescript module. If there is no typescript module, that is because you did not install typescript globally (npm install -g typescript).
Then you have to add the path of the bin of typescript subfolder in your environment variable.
Now you can compile the project with typescipt: tsc project.ts and you can run it node project.js.
Since you are using node function like fs you will need to install node typings npm install #types/node --save-dev before compiling with tsc.
Compilation option
To enable or disable all strict type checking options, you might need to use compilation option. You have to create the file in which you will specify the compilation option: tsc --init will create a tsconfig.json in which you can specify what behaviour you would like to have during the compilation of your app. All options are listed here.

Resources