mocha-sidebar
mocha-sidebar copied to clipboard
Cannot run mocha-sidebar with typescript ts-node
Hi there,
I'm just trying out this package. But when I try to run the tests using mocha sidebar it just doesn't read show my tests.
In the output tab I get this Finding tests with Mocha on Node.js at "/usr/bin/node" And I also get the error Mocha sidebar: Process exited with code 1. See Mocha output for more info.
My workspace settings look like this:
"mocha.files.glob": "src/**/*.spec.ts", "mocha.options": { "compilers": { "ts": "ts-node/register" } }, "mocha.requires": [ "ts-node/register" ], "mocha.runTestsOnSave": "true"
I have typescript installed locally I have all my unit tests under src directory.
Is there any docs I can refer to for Typescript setup with ts-node?
Thanks Ahmad
Your test location matches files.glob settings
You can run your tests via command line ?
Yes I can run the tests fine using the command-line.
Is it something wrong with my files.glob settings?
hi @ahmadkhudeish
It works for me with these settings:
"mocha.options": { "compilers": "ts-node/register" }, "mocha.requires": [ "ts-node/register" ], "mocha.files.glob": "test/*.test.ts"
Well that looks exactly the samr as mine isnt it exxcept mine is pointing to a different directory. My files are stored inside src/modules/inventories/tests/test1.spec.ts.
Shouldn't my mocha.files.glob be able to recognise that directory and execute the tests?
I'm confused
Try to set the full path and see if it works for you
I tried to set the full path but no luck, still not working. Has this package been tested with path different than test/*.test.ts?
Could you try to set the compilers option like I did. Without the ts:
On Feb 14, 2018 22:38, "Ahmad Khudeish" [email protected] wrote:
I tried to set the full path but no luck, still not working. Has this package been tested with path different than test/*.test.ts?
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/maty21/mocha-sidebar/issues/61#issuecomment-365737775, or mute the thread https://github.com/notifications/unsubscribe-auth/AF2uY-Foqm0Xpl-yxpCNHsaKYZGOcibWks5tU0RWgaJpZM4SEmow .
@yehiyam I did change it, and still the same issue I get the error Mocha sidebar: Process exited with code 1. See Mocha output for more info.
Any ideas? Thanks
Just added more informative error message
I was able to make it work with only the following additions to settings.json
in my project:
{
"mocha.files.glob": "./test/**/*.ts",
"mocha.requires": ["ts-node/register"]
}
The "compilers" setting is deprecated so it wouldn't be good if it were required for things to work correctly.
I have same problem, got a error
"TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at mochaLens._getRelevantItems (C:\Users\zengming\.vscode\extensions\maty.vscode-mocha-sidebar-0.17.5\provider-extensions\mochaLens.js:158:16)
at mochaLens.provideCodeLenses (C:\Users\zengming\.vscode\extensions\maty.vscode-mocha-sidebar-0.17.5\provider-extensions\mochaLens.js:48:49)
at <anonymous>"
i just uninstall, and reintall it , it work! this is my config
"mocha.files.glob": "test/**/*.ts",
"mocha.requires": [
"ts-node/register"
],
"mocha.options": {
"compilers": {
"ts": "ts-node/register"
}
}
I have the same config as @zengming00 and the tests are now found, and they seem to run (as indicated by the footer bar saying "Tests 5 0" but there's no output anywhere except this every time in the "Mocha output"
I do this in RubyMine and it just works straight away without any config so maybe we should have some better defaults
trying to searching for tests using these settings:
mocha path: mocha
test files location: **/*.spec.ts
files to ignore: **/.git/**/*,**/node_modules/**/*
environmets: {}
requires: ["ts-node/register"]
options: {"compilers":{"ts":"ts-node/register"}}
@PandaWood you can see the test result in the output if you set mocha.logVerbous to true in the settings
Thanks that does it
It took me a while but I got it running.
I have no idea what was wrong, actually, but in the end my config is:
"mocha.files.glob": "**/*.spec.ts",
"mocha.requires": [
"ts-node/register"
],
I think what did the trick was no specifying the directory in mocha.files.glob, instead, going directly with the recursion.
All I am also having the same issue as outlined above. In my .vscode folder, I created a settings.json which generated a ton of settings stuff. The workspace tab was empty and I added what @zengming00 has but changed to fit my project:
{ "mocha.files.glob": "test/**/*.spec.ts", "mocha.requires": [ "ts-node/register" ], "mocha.options": { "compilers": { "ts": "ts-node/register" } } }
I have a very simple test called app.spec.ts located at test/ts/app.spec.ts. Even with the settings above, I do not get the gitlens hit to run all tests and my sidebar is blank. I even tried a reinstall of the plugin but no dice.
in the sidebar-mocha output I get:
`trying to searching for tests using these settings:
mocha path: mocha
test files location: test/**/*.ts
files to ignore: **/.git/**/*,**/node_modules/**/*
environmets: {}
requires: ["ts-node/register"]
options: {"compilers":{"ts":"ts-node/register"}}
` I am not sure why mocha.files.glob and test files location do not match.
I was able to get mocha running via a gulp task, but getting the sidebar setup would be excellent. This thread is the closest I have come across that seems to have a working answer. Any assistance will be greatly appreciated.
Do my best to fix it for you guys in this week
On Tue, Jul 17, 2018, 5:47 AM sparky.dasrath [email protected] wrote:
All I am also having the same issue as outlined above. In my .vscode folder, I created a settings.json which generated a ton of settings stuff. The workspace tab was empty and I added what @zengming00 https://github.com/zengming00 has but changed to fit my project:
{ "mocha.files.glob": "test/**/*.spec.ts", "mocha.requires": [ "ts-node/register" ], "mocha.options": { "compilers": { "ts": "ts-node/register" } } }
I have a very simple test called app.spec.ts located at test/ts/app.spec.ts. Even with the settings above, I do not get the gitlens hit to run all tests and my sidebar is blank. I even tried a reinstall of the plugin but no dice.
in the sidebar-mocha output I get:
`trying to searching for tests using these settings:
mocha path: mocha test files location: test//.ts files to ignore: /.git//,/node_modules/**/* environmets: {} requires: ["ts-node/register"] options: {"compilers":{"ts":"ts-node/register"}}
` I am not sure why mocha.files.glob and test files location do not match.
I was able to get mocha running via a gulp task, but getting the sidebar setup would be excellent. This thread is the closest I have come across that seems to have a working answer. Any assistance will be greatly appreciated.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/maty21/mocha-sidebar/issues/61#issuecomment-405442430, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_nuZeFR_Q7waS75FkYnmfIMp3N7os6ks5uHVBPgaJpZM4SEmow .
I had the same issue and I made it work after the reinstalling the extension. I also use the same configuration as @HeavyStorm.
Now even though the sidebar properly detects the tests, the Run Test
and Debug Test
that I can usually see test file are no longer available.
@maty21 Just to let you know, I saw there was an update to the sidebar, got it and no luck. Uninstalled-reinstalled and still nothing. The only change I made since my last post was the workspace settings to do recursive lookup:
{ "mocha.files.glob": "**/*.spec.ts", "mocha.requires": [ "ts-node/register" ], "mocha.options": { "compilers": { "ts": "ts-node/register" } }, }
The tests are still not showing up in the sidebar. In the offchance there is something wrong with the test file itself, here is one example:
import { assert } from "chai";
import { StringUtility } from "../../src/ts/StringUtility"
describe("StringUtility Tests\t", () => {
it("Should replace + in the string with -", () => {
let baseString = "1 + ";
let replacement = "-";
let result = StringUtility.replaceAt(baseString, replacement, baseString.length - 2);
assert.equal(result, "1 - ")
});
});
Let me know if I can provide anything else to help sort this out.
Thanks for your work as always.
Hi try remove options also what is ts-node package version
On Mon, Jul 23, 2018, 7:57 PM sparky.dasrath [email protected] wrote:
@maty21 https://github.com/maty21 Just to let you know, I saw there was an update to the sidebar, got it and no luck. Uninstalled-reinstalled and still nothing. The only change I made since my last post was the workspace settings to do recursive lookup:
{ "mocha.files.glob": "**/*.spec.ts", "mocha.requires": [ "ts-node/register" ], "mocha.options": { "compilers": { "ts": "ts-node/register" } }, }
The tests are still not showing up in the sidebar. In the offchance there is something wrong with the test file itself, here is one example:
`import { assert } from "chai"; import { StringUtility } from "../../src/ts/StringUtility"
describe("StringUtility Tests\t", () => { it("Should replace + in the string with -", () => { let baseString = "1 + "; let replacement = "-"; let result = StringUtility.replaceAt(baseString, replacement, baseString.length - 2); assert.equal(result, "1 - ") }); });`
Let me know if I can provide anything else to help sort this out.
Thanks for your work as always.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/maty21/mocha-sidebar/issues/61#issuecomment-407127698, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_nuWEv2cK74jUOOrl_t864MVo46UbOks5uJgCTgaJpZM4SEmow .
Please confirm that it's working for you now tks
@maty21
"ts-node": "^7.0.0",
Additionally, I removed the options section from the settings so all I have left is:
{ "mocha.files.glob": "**/*.spec.ts", "mocha.requires": [ "ts-node/register" ], }
Uninstalled and reinstalled the sidebar but still nothing. Sorry.
- What is the error u get ?
- I assume u can run it via cli , what is the command u running ?
- Can u send a sample of a not working porject so I will be able to debug it for u ?
Another thing I just added a sample of a working project under the test folder can u please try clone and run it so we can verify that there is no something that went wrong on your pc
@maty21 I wanted to let you know that I actually uninstalled the extension because the only way I managed to make it work was to uninstall / install the extension each time the VSCode was restarting.
After a new install, the extension managed to list the tests. After a restart of VSCode the extension was not finding any of the tests anymore (no change anywhere).
Also, the extension is opening error notifications constantly when you dev with TS. I think the reason is that when you type, the extension/mocha is running being executed, which result in ts-node to try to compile the code which result in a crash if you are in a middle of a change (you do not need to save a file for the notification to popup).
I hop this helps you.
hi @linvi I couldn't reproduce your issue can you explain more about what u think that can cause the problem. also, can you try test https://github.com/maty21/mocha-sidebar/tree/master/test/typeScript-test this sample on your pc i tried to restart vscode couple of times and its working for me tks a lot for your support
I have the same issue.
Extension settings:
"mocha.options": {
"compilers": "ts:ts-node/register"
},
"mocha.requires": [
"ts-node/register"
],
"mocha.files.glob": "./test/**/*.ts",
"mocha.coverage": {
"enable": false,
"decoration": false,
"runWithInterval": false,
"autoUpdateInterval": 20000,
"activeOnStart": false,
"runAfterTest": false,
"runCoverageAfterFileSave": false,
"reporters": []
},
"mocha.showInExplorer": true // tried 'false' as well and checked Test Explorer
The log outputs:
____________________________________________________________________________
trying to searching for tests using these settings:
mocha path: mocha
test files location: ./test/**/*.ts
files to ignore: **/.git/**/*,**/node_modules/**/*
environmets: {}
requires: ["ts-node/register"]
options: {"compilers":"ts:ts-node/register"}
if you find anything wrong please change those default settings
____________________________________________________________________________
data send to parent. Exiting.
The test file (test/contact.test.ts) content:
describe("Contact", () =>
{
it("should pass", () =>
{
});
});
However, nothing is displayed in the Test Explorer window.
I noticed that the 'busy' icon for the File Explorer stays visible when this extension is installed, and it goes away when I remove it.
Same as in the README file am I right ?
On Mon, Mar 26, 2018, 4:28 AM Rikki Gibson [email protected] wrote:
I was able to make it work with only the following additions to settings.json in my project:
{ "mocha.files.glob": "./test/**/*.ts", "mocha.requires": ["ts-node/register"] }
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/maty21/mocha-sidebar/issues/61#issuecomment-376021663, or mute the thread https://github.com/notifications/unsubscribe-auth/AE_nudPEVMJPImUUWhCrpY7OXcxheCCvks5tiERIgaJpZM4SEmow .
@yagasoft try remove option it's not needed , also what is the mocha cli command you running ?