Skip to content

How to Contribute@Write Unit Tests

YLcoding edited this page Jun 11, 2020 · 1 revision

You can find documentation on the package that helps run vscode unit tests here: https://nodejs.org/api/assert.html

Here is a guide on setting the tests up: https://code.visualstudio.com/api/working-with-extensions/testing-extension

You will want to put your test in the unit-tests\suite folder and name it *.test.ts

Here is a very basic unit test for the vscode extension:

import * as assert from "assert";
import { currentDocumentListener, curFile } from "../../events";

/** This test suite tests the types of the exported variables from events */
suite("testing events.ts", () => {
  /** testing if curFile is the correct type after running currentDocumentListener */
  test("assert that curFile is valid string", async () => {
    currentDocumentListener();
    assert.notEqual(undefined, curFile);
    assert.equal(typeof "string", typeof curFile);
  });

});

If you want to run unit tests for the vscode extension, there are 2 scripts necessary in the package.json. First, run npm run pretest in order to compile the code from TS to JS and then run npm run unit-test.