'VS Code Extensions - writing tests that include inline input documents

Following this guide to writing simple extensions for VS code, and automated tests of these. I need to have some expected text in the current document for the test to run against.

I found this example of a script that opens an existing text file and uses it as input.

Instead, I'm trying to run tests against inputs and expected results held in the test code itself. That would seem to be more robust and self-contained.

Here's my attempt:

import * as assert from 'assert';

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import * as taxi from '../../extension';

suite('Extension Test Suite', () => {
    vscode.window.showInformationMessage('Start all tests.');


    test('displayDiagnostics - empty, no summary', async () => {

        let dcoll = vscode.languages.createDiagnosticCollection('taxi');
        const startTime = new Date().getTime();
        const showSummary = false;
        const result: taxi.Result = {
            // eslint-disable-next-line @typescript-eslint/naming-convention
            total_errors: 0,
            // eslint-disable-next-line @typescript-eslint/naming-convention
            total_warnings: 0,
            errors: [],
            warnings: [],
        };
        vscode.workspace.openTextDocument({
            content: 'The quick brown fox'
        })
            .then((doc) => {
                const diags = taxi.displayDiagnostics(result, doc, startTime, showSummary);
                assert.strictEqual(diags.length, 0);
            }, (error) => {
                assert.fail(error);
            });
    });

: : etc etc

The openTextDocument seems to be almost working, but I'm seeing warnings saying "no active text editor".

Am I doing something wrong in setting up the tests?

The tests seem to pass even if I include a sure-to-fail line such as

                assert.strictEqual(1, 2);
(node:79286) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
(Use `Electron --trace-deprecation ...` to show where the warning was created)
Congratulations, your extension 'highlight-trailing-white-spaces' is now active!
updateDecorations(): no active text editor.

  Extension Test Suite
    ✔ displayDiagnostics - empty, no summary
    ✔ displayDiagnostics - empty with summary
    ✔ displayDiagnostics - errors and warnings, no summary
    ✔ displayDiagnostics
  4 passing (24ms)
The extension 'highlight-trailing-white-spaces' is now deactivated.
FAILED to register filesystem provider of vscode.git-extension for the scheme git
Canceled: Canceled
    at Object.F [as canceled] (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:5:1172)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:97:9076
    at Array.forEach (<anonymous>)
    at i.dispose (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:97:9024)
    at p.terminate (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:102:694)
    at s (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:112:36448)
    at Socket.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:112:34061)
    at Socket.emit (<node_internals>/events.js:327:22)
    at Pipe.<anonymous> (<node_internals>/net.js:673:12)
    at Pipe.callbackTrampoline (internal/async_hooks.js:131:14) {name: 'Canceled', stack: 'Canceled: Canceled
    at Object.F [as canceled]…ckTrampoline (internal/async_hooks.js:131:14)', message: 'Canceled'}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source