-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testing conundrum when using webpack #3632
Comments
This is a workaround I'm using at the moment, in case it helps anyone. It uses a global Excerpt from my {
"scripts": {
"test-compile": "npm run main-out && tsc -p ./",
"main-out": "json -I -f package.json -e 'this.main=\"./out/extension.js\"'",
"main-dist": "json -I -f package.json -e 'this.main=\"./dist/extension.js\"'"
}
} Excerpt from my {
"version": "0.2.0",
"configurations": [{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index",
"${workspaceFolder}/demo/demo.code-workspace"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: test-compile",
"postDebugTask": "npm: main-dist"
}
]
} |
Hi @frenya I've asked the VS Code engineers and I don't think there is currently a better solution than your workaround. You can see microsoft/vscode#85779 which talks about the issue and imagines a switch like |
Thanks for the update and the link to the related issue, Greg. |
@frenya Thanks for mentioning your workaround in the vscode issue to help other users. |
It seems to me there's one fundamental flaw when it comes to unit testing while using the suggested webpack configuration for distribution and a plain compilation using
tsc
for testing.main
attribute ofpackage.json
must point todist/extension.js
dist/extension.js
even when unit testingout
folderThis is not a good solution. For instance, you will run into problems in case your tests rely on any of those modules being initialised by the
activate
function (e.g. when you want to reference the extension context).We need a way temporarily enforce loading the extension from
out/extension.js
for unit tests. Editingpackage.json
every time is not a good option.Maybe I'm just missing something, in which case please point me in the right direction.
The text was updated successfully, but these errors were encountered: