Douglas Rogers
Douglas Rogers

Reputation: 458

How to open a specific folder when debugging VS Code extension?

I've developed an extension that reads a directory's package.json file. For the extension to work, you must be inside of a JavaScript file. I'm attempting to test this extension by using a test directory inside of the extension's src directory that houses a package.json file and an index.js file.

My goal is to allow the test to open the directory, open the index.js file and the run the tests there. This way the test directory goes anywhere the extension goes and the tests are predictable based on the package.json file I put into place.

How do I get the tests to open that test directory and run the tests from that specific index.js file?

Upvotes: 7

Views: 2639

Answers (1)

Douglas Rogers
Douglas Rogers

Reputation: 458

I figured it out. I had to add the path to the directory into "args" array of the Extension Test object in launch.json.

"args": [
  "${workspaceFolder}/src/test/test-directory/",
  "${workspaceFolder}/src/test/test-directory/index.js",
  "--extensionDevelopmentPath=${workspaceFolder}",
  "--extensionTestsPath=${workspaceFolder}/out/test"
]

I was also able to have index.js open up as well. All of which I realized were totally useless in the tests that I were doing. But at least now I know how to do it and maybe someone else will, too.

Also, if you don't add ${workspaceFolder} in front of the directory you are referencing, VS Code assumes you want a new file created. So instead of opening the index.js file that I had available, it was creating a new empty file named index.js.

Upvotes: 12

Related Questions