Skip to content

Local Development

Bleddyn Richards edited this page Mar 9, 2023 · 8 revisions

Introduction

This article will guide you through debugging the extension on your local machine and talk you through all prerequisite steps required to get the extension running on your local machine.

Prerequisites

Please make sure all commands are ran from a Git Bash terminal.

Debugging

Before you can dive in and begin debugging the extension there are a hand-full of tasks required to configure your local developer environment.

  1. Clone the repository to your local machine.
  2. Edit INPUT_PATH in all the config/*.env files to point to your working directory.
  3. Ensure the tasks.json and launch.json configurations below exist in their respective files within the .vscode directory.
  4. Ensure the TFS CLI is installed by running npm install -g tfx-cli
  5. Install all required npm modules by running npm run-script initdev

Now that all the modules have been installed and our environment is configured we can begin debugging by:

  1. Open the project with Visual Studio Code.
  2. Clicking Debug (Ctrl+Shift+D) in the explorer view.
  3. Selecting either Launch .Net Framework or Launch .Net Core.
  4. Clicking the Start Debugging button.

Task parameters are defined within the .env files found within the /config directory at the root of the repository.

See the VS Code repository for additional launch recipes:
https://github.com/Microsoft/vscode-recipes/tree/master/debugging-mocha-tests

Unit Tests

I'm slowly adding a suite of unit tests to the extension to ensure no breaking changes are added as we move forward with the development of the extension. I'm hoping this area of the wiki will grow overtime but for now here are the small number of steps to execute the unit tests:

Net Core

There are a handful of unit tests written for the .Net Core task. To run the tests execute the following npm command npm run-script test. This command is found in the package.json and will build the application and run the test suite.

Please note: - On first execution you will see the unit test "should succeed and print input task parameters" fail as this unit test is checking an absolute path. Please amend the path in the test and alter the path in the ./src/netcore/tests/builders/request-model-builder.ts model builder file.

I know I need to come up with a better solution to this 🙈

To debug the unit tests:

  1. From Visual Studio Code click Debug (Ctrl+Shift+D) in the explorer view.
  2. Selecting either Mocha .Net Core.
  3. Clicking the Start Debugging button.

Net Framework

There are currently no unit tests for the .Net Framework task but this is something I'm hoping to address in the near future.

Running Tasks

You can run the tasks by issuing one of the following commands. All output will be logged to the terminal window:

  • app:netframework to run the .Net Framework task
  • app:netcore to run the .Net Core task

Appendix

VS Code Configuration Files

Tasks.json

Ensure the following configuration is added to your tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build TypeScript",
            "command": "tsc",
            "type": "shell",
            "args": [
                "-p",
                "."
            ],
            "presentation": {
                "reveal": "never"
            },
            "problemMatcher": "$tsc"
        },
        {
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                "$tsc"
            ]
        }
    ]
}

Launch.json

Ensure the following configuration is added to your launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch .Net Framework",
            "protocol": "inspector",
            "envFile": "${workspaceFolder}/config/netframework.env",
            "args": [ "./src/netframework/index.ts" ],
            "cwd": "${workspaceRoot}",
            "runtimeArgs": [ "-r", "ts-node/register" ],
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Mocha .Net Framework",
            "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
            "args": [
                "--require", "ts-node/register",
                "--timeout", "999999",
                "--colors", "--recursive",
                "${workspaceFolder}\\src\\netframework\\tests\\index.ts"
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "protocol": "inspector"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch .Net Core",
            "protocol": "inspector",
            "envFile": "${workspaceFolder}/config/netcore.env",
            "args": [ "./src/netcore/index.ts" ],
            "cwd": "${workspaceRoot}",
            "runtimeArgs": [ "-r", "ts-node/register" ],
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Mocha .Net Core",
            "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
            "args": [
                "--require", "ts-node/register",
                "--timeout", "999999",
                "--colors", "--recursive",
                "${workspaceFolder}\\src\\netcore\\tests\\_suite.ts"
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "protocol": "inspector"
        }
    ]
}