Create a JavaScript project in Visual Studio Code

In Visual Studio Code, on Windows, macOS, and Linux, you can create Jasmine or Mocha testing projects using the installed templates.

Prerequisites

Internet connectivity is required when creating projects.

Create a project

Using the extension GUI

  1. Select the Functional Testing for Developers extension in the Activity Bar.

  2. Expand the Templates menu.

  3. Expand the JavaScript menu.

  4. Click the desired template type (Jasmine or Mocha).

  5. Enter a name for the new project.

  6. Select a project location. By default, Visual Studio Code suggests the user's Documents folder if there is no open workspace. Otherwise, it suggests the open workspace.

Using the Command Palette

  1. Open the Command Palette (Ctrl + Shift + P).

  2. Type >FTD: Create JavaScript Project.

  3. Select the JavaScript project type (Jasmine or Mocha).

  4. Enter a name for the new project.

  5. Select a project location. By default, Visual Studio Code suggests the user's Documents folder if there is no open workspace. Otherwise, it suggests the open workspace.

Back to top

Visual Studio Code template content

The Jasmine/Mocha FTD project templates include the following:

  • package.json, which contains your project's settings, including the references to the LeanFT SDK and the @hpe/leanft-mocha-runner / @hpe/leanft-jasmine-runner, and the script for launching tests.
  • Node_modules folder, which contains the LeanFT SDK, testing framework, and the LeanFT SDK runner module. (npm installs this automatically.)
  • A basic ftdtest file template where you write your code.

    You can include multiple tests in one file, and you can use the Object Identification Center or Test Recorder to help generate the code.

    The exact structure of this template depends on whether you are using Jasmine or Mocha:

    • In a Mocha project, test files are saved with the .js extension. You can save test files in any folder under your project.
    • In a Jasmine project, test files are saved with the -spec.js extension and must be placed in the spec or test folder.

    The template includes initialization hooks that control what happens during the different phases of your run:

    • In Mocha projects, a before hook initializes the SDK engine and an after hook cleans up after execution completes.
    • In Jasmine projects, a beforeAll function initializes the SDK engine and an afterAll function cleans up after execution completes.
  • jsconfig.json - Optionally, you can create this file to customize test settings and enable IntelliSense support for LeanFT SDK JavaScript test objects and methods. For details, see Customize test settings.

Example: A new OpenText Functional Testing for Developers Jasmine project in Visual Studio Code:

Jasmine project structure showing package.json, spec folder with test files, and helper files

Example: A new OpenText Functional Testing for Developers Mocha project in Visual Studio Code:

Mocha project structure showing package.json, test folder with test files, and helper files

  • For details on using the Mocha framework, see the Mocha documentation.
  • For details on using the Jasmine framework, see the Jasmine documentation.

Back to top

Next steps: