简体   繁体   中英

Run vscode extension unit test

I've created vscode extension based on typescript with the following config

the path for the test is

vscode_extensions/my-ext/src/test/runTest.ts:1

**The error is:**

import * as path from "path";
       ^

SyntaxError: Unexpected token *

the tsconfig is

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "out",
    "lib": ["es6"],
    "sourceMap": true,
    "rootDir": "src"
    // "esModuleInterop": true
    // "strict": true /* enable all strict type-checking options */
  },
  "exclude": ["node_modules", ".vscode-test"]
}

Any idea?

The strange thing is that I was able to run the extension and debug it but not able to execute some basic mocha unit test.

I tried to switch to a newer node version using nvm (node 13 ) without success

As this is new for me, mocha test in js maybe I miss something...

When I face problems like that in nodejs - obviously its NOT a syntax issue, because syntax is correct, but somehow environment can't understand its properly - I try to check if its not the problem of node modules

  • Delete node_modules folder
  • Clear npm cache - npm cache clean --force
  • npm install
  • turn on strict mode "strict": true - its always good idea - maybe it will point you other problem which can be connected
  • recompile Typescript code

Of course check if you have properly installed Tpyescript, nodejs and so on - the easiest way it to check if Helo_World programs from documentation are working properly - for every module/programming language separately.

And you can check if on other machine problem exists - maybe its something deeper, like bad OS env settings (incorrect PATH in Linux can be really annoying).


If it will not help, then you can try to launch VScode in --verbose mode, which will write all log information in the terminal. To do it

  1. Open terminal which you use on your OS
  2. write code --verbose
  3. DONT CLOSE THE TERMINAL
  4. Then vscode opens - open your project and run it
  5. When you reach your issue - then go back to the terminal and check what is written here - it can help you to understand what is going on

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM