Michael K. Snead
*Sometimes with the use of a Transpiler
A library released in 2013 (React.js) can still run, unmodified, under the WScript engine (unchanged since 1999)*
*You will, of course, need to include ES5 shim/sham
Yesterday's JavaScript (ES3 / IE8) can do...
MSDN Create JS Intellisense XML Comments
https://msdn.microsoft.com/en-us/library/bb514138.aspx
Eliminating JavaScript Code Smells
elijahmanor.github.io/talks/js-smells/
ES6 is the next version of JavaScript. The members of TC-39 working on the spec include folks from...
You can use ES6 in IE8 using the Babel.js transpiler today.
Out of the box, the Windows 10 browser "Edge" will have ES6 support.
As an aside: The folks behind ES6/7 are only planning to accelerate the rate at which new editions of the spec are released.
A transpiler is also known as a 'source to source' compiler. Source code from one language is rewritten into another.
Many transpilers exist for JavaScript. This is probably because JavaScript is the only language understood by web browsers and it's dynamic enough to serve as a 'compile target'.
Let's build something!
...It's just a simple shell, though. For more complex scenarios, feel free to contact me or some of the other JS ninjas at Paylocity!
You mention all these modern tools for JS... but how to use them?
I want to use VS2013 with my existing JavaScript codebase.
We're going to look at a sample application you can find here:
Visual Studio Task Runner Explorer
https://visualstudiogallery.msdn.microsoft.com/8e1b4368-4afb-467a-bc13-9650572db708
Chutzpah (or ReSharper)
https://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe
Web Essentials for VS2013.4
https://visualstudiogallery.msdn.microsoft.com/56633663-6799-41d7-9df7-0f2a504ca361
Start with these tools...
Linting code on the fly...
Teams often have their own rules and conventions. JSHint is configurable to be as strict or loose as you need.
Linting code on the fly...
Linting code on the fly...
Documentation on configuring rules for JSHint can be found at the website:
http://jshint.com/docs/options/
Chutzpah provides JavaScript unit testing within Visual Studio alongside your C# unit tests with a complete DOM (webkit).
Integrated, unified unit testing...
If you use ReSharper, you can configure ReSharper to use PhantomJS and it should automatically pick up your QUnit unit tests.
QUnit is the testing framework used by the jQuery team.
Integrated, unified unit testing...
First, install the Chutzpah Visual Studio Extension. Then install the Chutzpah Nuget package into the solution. This wont add any files except into nuget's "Packages".
How do I 'Chutzpah'?
Next, add a Chutzpah.json file, which tells Chutzpah about your folder structure and chosen testing framework.
How do I 'Chutzpah'?
After that, add your test framework and your unit tests. Use <reference> tags to tell Chutzpah to bring in dependencies and the module to test. The next time the test explorer is refreshed, just like with the NUnit adapter, your tests should show up right alongside C# tests.
How do I 'Chutzpah'?
So far, we've illustrated linting (using the JSHint library for static analysis) and unit tests (using Chutzpah and QUnit).
These activities and a host of others are also available as gulp or grunt tasks.
...but I want more...
Instructions for setting up gulp for a project in VS2013...
A little setup...
*If you've never used gulp before. Running it again is harmless, though.
Gulp runs atop the node.js runtime. Much like C# and .NET use nuget packages, the node.js runtime uses npm packages.
Nuget uses a packages.config file to keep track of which packages are needed. npm uses a package.json file.
Gulp: one sip at a time
Gulp itself has a special file that defines all of the tasks gulp will run for your project called 'Gulpfile.js'.
Gulp: one sip at a time
node, npm and gulp all run from the terminal. The VS Task Runner Explorer runs them in the same way and captures their output. You need to make sure that node and npm are accessible from your PATH.
Gulp: one sip at a time
Once everything is setup, open the Task Runner Explorer window under View > Other Windows > Task Runner Explorer.
Gulp: one sip at a time
You can bind a "watch" task to Solution Open that runs whenever a file in a series is changed. This gives gulp "run task on save" abilities, like "run JavaScript unit tests whenever I save a JavaScript file".
Gulp: one sip at a time
Now, whenever I save a file, gulp runs my unit tests and linting tools. Notice below that Wizard.js failed linting on Save.
Gulp: one sip at a time
Extra Credit: gulp can also use growl or toast notifications to let you know when something needs your attention! Growl notifications are similar to "Toastr" or Outlook's new message popup. If you'd like some help setting this up, reach out.
Gulp: one sip at a time
The Benefits Center app includes sample code for these notifications. Windows 8 has native support for them.