0

I am writing automated testing scripts using TestComplete. TestComplete mostly supports Ecmascript 2015, but it has a few quirks that are causing intellisense to not work as I would expect.

Here is two examples of code files:

File: UsefulStuffFileName.js

class UsefulStuff {
    constructor(initValue) {
        this.initValue = initValue;
    }

    get someValue(){
        return this.initValue + " someValue";
    }

    doStuff(input) {
        return input + " stuff done";
    }
}

module.exports.UsefullStuff = UsefullStuff;

File: WorkingHere.js

var useful = require('UsefulStuffFileName');

class WorkingHere {
    constructor() {
        this.usefullStuff = new useful.UsefulStuff("Hello");
    }

    doCoolStuff() {
        // I want intellisense options when I type the period after this.usefulStuff
        // The options would be someValue, doStuff() and initValue.
        //                                |
        //                                |
        //                                V
        let myVariable = this.usefullStuff.someValue;                
    }
}

The quirks, as I see them are:

  1. The export is done via this style: module.exports.UsefullStuff = UsefullStuff;. (This makes it work with TestComplete.)
  2. The "import" assigns to a variable (var useful = require('UsefulStuffFileName');)
  3. The "new"ing of the object uses the variable to access the class (new useful.UsefulStuff("Hello");).

Is there anyway to configure Visual Studio Code to understand how these files are related and give me intellisense?

Note: If I try the more standard import {UsefulStuff} from './UsefulStuffFileName'; I get an error saying "Unexpected token import" from TestComplete.

1 Answer 1

0

This can be done via these steps.

  1. Change the import to look like this:

    var { UsefulStuff } = require('UsefulStuff');

  2. Change the instantiation of the class to look like this:

    this.usefulStuff = new UsefulStuff("Hello");

  3. Add a file called jsconfig.json and put this in it:

.

{
    "compilerOptions": {
      "baseUrl": "."      
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.