Closed stephaneeybert closed 2 years ago
Hi @stephaneeybert ,
That's interesting. Would you mind showing the content of the file? Aren't there any describe
/test
/it
functions?
@David-Kunz Hello ! Sorry for the late reply. So here is the full source code of the test generated by the Angular CLI tool:
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
AppComponent
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'ng-dummy'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('ng-dummy');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('.content span')?.textContent).toContain('ng-dummy app is running!');
});
});
Thanks @stephaneeybert!
So there are some function calls with name it
as well as describe
blocks.
What Jester does: It looks at the parsed source code (done by Tree-Sitter) and finds the next it
/test
/describe
function call.
Would you mind installing the plugin https://github.com/nvim-treesitter/playground and show the output of :TSPlayground
?
I installed the above plugin and could see it being installed.
use {
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
}
use "nvim-treesitter/playground"
My configuration is:
local status_ok, configs = pcall(require, "nvim-treesitter.configs")
if not status_ok then
print("The treesitter extension could not be loaded")
return
end
configs.setup {
sync_install = false, -- installing languages asynchronously
ignore_install = { "haskell", "go" }, -- List of parsers to ignore installing
autopairs = {
enable = true
},
highlight = {
enable = true, -- enable the syntax highlighting
disable = { "css", "markdown" }, -- list of languages to disable
additional_vim_regex_highlighting = { "php" },
},
indent = {
enable = true,
disable = {
"yaml"
}
},
playground = {
}
}
But I guess I must have missed something, because when I type in the command :TSPlayground
the right pane that opens up is totally empty, this on any project.
Interesting, then it seems to be a problem with parsing.
Is Tree-Sitter enabled for the buffer? Is the correct language detected?
I wonder how to check that...
For information, I do have errors showing up in Typescript and Java files, and I have the LSP servers installed and can even debug in Typescript.
If I type in a syntax error in the above source code, then it shows a red mark and a diagnostic is available.
typescript: ',' expected.
typescript: Variable 'fi' implicitly has an 'any' type
My nvim configuration is available as well.
Okay, then the LSP server and its interaction with Neovim is correctly working. It seems that Tree-Sitter isn't used for parsing.
The command TSPlaygroundToggle gives for a Typescript file, an empty right hand window for a Javascript file, an empty right hand window
There is no such thing as the DOM tree in that window.
Sorry to keep you busy :-)
Interesting... Did you enable Tree-Sitter for those files in the first place?
In my configuration, I have
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true
}
}
to enable Tree-Sitter for syntax highlighting. Maybe this is a requirement.
Here's more info about how to enable it: https://github.com/nvim-treesitter/nvim-treesitter
Hey there, ran into this issue and this is what I did to resolve it
tree-sitter
needs to be installed, along with the language servers and syntax highlighting to be enabled in order for this to work. This is the config I added to my init.vim
require'nvim-treesitter.configs'.setup {
ensure_installed = { "javascript", "typescript" },
highlight = {
enable = true
}
}
Perhaps we could update README.md
? If you don't mind, I can make a PR in a couple of hours (since it's really late in my timezone right now)
Thanks a ton for this info @lethanhan97 , yes, adding it to the README would be great! I will do this real quick.
@David-Kunz Yes I had this setup as well as seen in my pasted code above.
So I added the missing configuration:
ensure_installed = { "javascript", "typescript", "java" },
And now I can see the DOM tree for all 3 languages listed above.
Thanks guys !
All right there is progress. When using jester to run a test I now get another message:
nvim-treesitter.ts_utils.get_node_text is deprecated: use vim.treesitter.query.get_node_text
I reckon I need to clean up some cache or fix some config somewhere.
Hi, this is just a warning because of deprecated APIs. You can ignore that for now, it shouldn't be a problem. I will change it soon.
Indeed I can pass the warning message. But I may have missed a step on the installation. As I get the following output from running a test:
jest -t 'AppComponent should create the app' -
-dummy/src/app/app\\.component\\.spec\\.ts
✔ ~/trash/ng-dummy [master L|✔]
22:49 $ jest -t 'AppComponent should create th
ash/ng\\-dummy/src/app/app\\.component\\.spec\
Command 'jest' not found, did you mean:
command 'test' from deb coreutils (8.30-3ubu```
Hi @stephaneeybert,
This is strange. Why does the jest
command fail in the second example?
In any way: You can configure the jest path using the options of Jester, maybe that will help?
Oh ! There is such a thing as a Jest PATH ? That tells me I should install a jest utility on my system.
Now I see from your README here a link to https://jestjs.io and I discover a testing framework.
I had no clue your plugin needed the installation of an external command. Sorry !
I shall now proceed to install jest on my system and have it in my PATH and let you know about my mileage.
I now installed jest with my install script:
if ! command -v jest &> /dev/null
then
printf "\nInstalling the jest program used by the jester plugin\n"
npm install -g --save-dev jest
printf "\nConfiguring jest for typescript\n"
npm install --save-dev @babel/preset-typescript
npm install --save-dev babel-jest @babel/core @babel/preset-env
npm install --save-dev ts-jest
npm install --save-dev @types/jest
fi
I'll try to configure jest for typescript and come back with my results. Thanks !
I'm closing this issue, if you still experience any problems, please come back to me.
I now installed jest with my install script:
if ! command -v jest &> /dev/null then printf "\nInstalling the jest program used by the jester plugin\n" npm install -g --save-dev jest printf "\nConfiguring jest for typescript\n" npm install --save-dev @babel/preset-typescript npm install --save-dev babel-jest @babel/core @babel/preset-env npm install --save-dev ts-jest npm install --save-dev @types/jest fi
I'll try to configure jest for typescript and come back with my results. Thanks !
Did you come up with a working config for typescript?
I created an Angular application which offered 3 tests by default:
ng new ng-dummy
I then could run the tests from the command line:
I was hopping to run them from within nvim:
With the current cursor location in the body of one test, I typed in the command:
:lua require"jester".run()
But it did not run the test. Instead of displayed the message:
Could not find any of the following: test, it, describe
Angular CLI: 13.3.3 Node: 16.14.2 Package Manager: npm 8.5.0 OS: linux x64 14:01 $ nvim --version NVIM v0.7.0 Build type: Release LuaJIT 2.1.0-beta3 Compiled by runner@fv-az316-460