Running the Tests

With the first few exercises, you will get a skeleton file with the exported modules. For later ones, you can find more information about modules in the node documentation.

For running tests, install jasmine as described in the Installing Javascript section. Move to the folder where that exercise's files are located (a path similar to {EXERCISM_HOME_DIR}/javascript/{EXERCISE}).

cd ~/exercism/javascript/bob
jasmine bob_test.spec.js

Only the first test will be executed, all the others have been marked pending using xit or xdescribe. As you keep solving the exercise, one by one change all xit and xdescribe to it and describe respectively to run all the tests. See Test Driven Development (TDD) to know more about this approach. When all tests pass, you are ready to submit!

Visual Studio on Windows

You can use any editor of your choice to write javascript. Here are just some instructions for using and running tests in Visual Studio. You are free to skip this section if you are not using Visual Studio on Windows.

Install Visual Studio Express 2013 for web. This will include the IDE and web development tools.

To get started, you can download a Visual Studio solution that is already set up to work with JavaScript and the other languages that Visual Studio supports.

Solution Explorer

  1. Download the Visual Studio Template from GitHub by clicking the Download Zip button on the page.
  2. Unzip the template into your exercises directory, for example C:\src\exercises
  3. Install the Exercism CLI
  4. Open a command prompt to your exercise directory
  5. Add your API key to exercism exercism configure --key=YOUR_API_KEY
  6. Configure your source directory in exercism exercism configure --dir=C:\src\exercises
  7. Fetch your first exercise exercism fetch javascript
  8. Open the Exercism solution in Visual Studio
  9. Expand the Exercism.javascript project
  10. Click on Show All Files in Solution Explorer (See below)
  11. The exercise you just fetched will appear greyed out. Right click on the folder and Include In Project
  12. Get coding...

Add files

If you have a paid version of Visual Studio, you should install the Web Essentials extension. It will make working with Javascript much easier.

You can run the unit tests from a node.js command line using the batch file in the project.

C:\Src\exercises\javascript>test example\bob_test.spec.js

Finished in 0.02 seconds
17 tests, 17 assertions, 0 failures, 0 skipped

If you do not see any output from running the tests, you are likely not in a Node.js command prompt.

Setting Up a Linter

** Note: This section is completely optional **

A linter is like a tester for your code's style and formatting. In some languages there are many acceptable styles, and using a linter allows you to be internally consistent (e.g. Ruby), or adhere to one of many common styles. In other languages there are fewer choices, and a linter allows programmers to look at code from a great variety of sources and still feel at home (e.g. Go). You can read more here.

The old standard linter for JavaScript is JSLint. However, it is controversially picky. JSHint is another popular linter. We suggest using ESLint, which is more customizable than either JSLint or JSHint, and is well-run.

To get started using ESLint, follow the instructions here. Once you have ESLint installed, you'll be able to lint your code with a simple eslint [options] [file|dir]* command. Eg, if you're in the hello-world directory, eslint . would lint all files in that directory.

Programming person with notebook