Typescript typings for protactor in a visual studio project - node.js

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

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 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.

Angular AOT compilation fails with npm package

I am a complete newbee to web development, and now I am facing a problem that I do not know how to deal with.
I am using the npm package named #uniprank/ngx-file-uploader (https://www.npmjs.com/package/#uniprank/ngx-file-uploader) in my web application, which is developed in Typescript with Angular 4. When compiling it with JIT compilation it works with no problems. However, now I would like to turn my application to production mode, so I tried AOT compilation. When I try to compile my application with the Angular compiler, as it is shown here: https://angular.io/guide/aot-compiler. The message shown is the following:
Unexpected value 'undefined' exported by the module 'FileUploaderModule in /node_modules/#uniprank/ngx-file-uploader/typings/index.d.ts'
I am completely lost at this point. Although I have been looking around in the web, I cannot figure out what means that message and how to fix it.
Any ideas to solve this problem will be appreciated. Thanks.

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.

Typescript declaration file for mongoose

Is there a typescript declaration file for mongoose? I've looked at Boris Yankov's Definitely Typed repo, but there does not seem to be one. Anyone know where I can get a good d.ts file for the mongoose library?
Kind regards as always.
I found a github project here. It has the mongoose typescript definitions in there.
Just an update on this. Now you should use typings to import your types definitions inside your application.
Use npm and install it globally:
$sudo npm install -g typings
to install the mongoose package:
$ typings install mongoose
More info about typings: https://www.npmjs.com/package/typings
Tutorial on how to setup mongoose with typings in typescript project: http://www.vandiest.biz/?p=3931
You can check http://onoffswitch.net/mongoose-with-typescript/ . It also includes a link for a github repository which contains unit tests and schema definition with typescript.
It is tempting to say that if it isn't on Definitely Typed it probably doesn't exist.
Of course, it was only a matter of time before it was added: Definitely Typed definition for Mongoose.
You can get all of the Definitely Typed type definitions using NuGet, or TSD (available via NPM) or just on the GitHub repository.
This question was asked in 2013, and since then, things have changed a lot, and none of the given answer mentions how to go about finding declaration files now.
So the answer to the question, where can I find typescript declaration file for mongoose (or for any other library) is to search for such declaration file using TypeSearch
It is a tool developed by the TypeScript team that helps in searching for declaration file hosted on the DefinitelyTyped repository (which has since grown big and now almost impossible to search using the GitHub web interface).
The other thing that has changed since 2013, is that Typings or tsd is no longer the recommended tool for working with declaration files (as mentioned in some of the already given answers). The recommended way is to now use npm. You can read more about this here: The Future Of Declaration Files

Resources