Set filetype association for LightJavaCodeInsightFixtureTestCase
已回答
I have succesfully created an extension that creates references from 'Angular HTML Template' elements to my DSL. When I want to unit-test these references the fixture always considers the file a Plain HTML file so the PsiTree is not as expected and I cannot test my references.
Is there anyway to set the file type association for a LightJavaCodeInsightFixtureTestCase so something with '*.component.html' is considered an Angular HTML Template FileType.
请先登录再写评论。
Did you define a dependency on Angular plugin in your plugin.xml?
Yes, as an optional dependency. Everything works fine when I use it in runIde or when actually deploying the plugin. The only situation where it doesn't work is in a LightJavaCodeInsightFixtureTestCase where the PsiFile is identified as a plain HTML file instead of Angular HTML template
Tim, the Angular HTML language replaces the regular HTML under certain circumstances. One of the easiest ways to reproduce the regular project setup is to add `package.json` file with `@angular/core` dependency in it. E.g.:
You can also register your own context provider (`Angular2ContextProvider` in 2020.3 and older or `WebFrameworkContext` in 2021.1 and newer) in `setUp()` method, which always returns `true` for the test duration. E.g.:
Let me know if you have any questions!
Hi Piotr,
thank you for your answer. Unfortunately it didn't do the trick for me. I have upgraded to 2021.1 and to my surprise now my .ts files in my unit-tests are considered plain-text. Also, the icon for the Angular HTML file type is missing. Don't know if this might be a bug in the release or something went wrong during my upgrade.
I have tried your package.json example, that one didn't work. The WebFrameworkContext example I couldn't get to work, I'm not sure what I should register, the line in your example isn't working (probably also deprecated) and the interface for registerExtension shows little to no documentation. I do see a lot of references to a PlatformTestUtil, does this mean these tests should not setup using a LightJavaCodeInsightFixtureTestCase but rather a heavier one?
Kr, Tim
Tim, I am sorry, I haven't payed enough attention to the class you mentioned. Indeed, these tests should be based on `BasePlatformTestCase`. You can see Angular tests here and take the most appropriate as an example: https://github.com/JetBrains/intellij-plugins/tree/master/AngularJS/test/org/angular2 .
Hi Piotr,
thanks for your response. I have tried it quickly but so far nothing seems to get it working in a test environment. I have created a very simpel setup with 2 tests:
Both tests fail on their assertion:
testTSFile:
Second
In a few days I'll give it another go when I have some more time, perhaps you can have a quick look to see if you can reproduce the above to see if I'm missing something in my setup. The fact that my typescript file is recognized as plain text makes me think that it somehow is running against a community edition.
Tim,
I've run the code you've shared within the context of AngularJS plugin and both tests are green. I have used JUnit 3 though, so I had to remove all of the JUnit 4+ annotations. It seems that you must be missing dependencies in your test module classpath, or there are some problems with JUnit 4+. Are you using Gradle? Can you share configuration?
Hi Piotr,
this is my build.gradle
And the plugin.xml
And finally the withAngularJS.xml
Tim,
It seems that there is some problem with JUnit 5 and classloading/extension point registration. I can reproduce the issue locally - it is not related to Angular. However, I wasn't able to find a solution yet.
Hi Piotr,
thanks a lot for taking the time to investigate this. I will for now defer to manually testing these extensions. Rewriting all my tests to JUnit4 is a bit too much effort :). Let me know when you find something.
Kr, Tim
Hi Tim!
Actually, I've investigated it further and it turns out that it is actually a problem with 2021.1. Please include "CSS" plugin on your list in build.gradle as a workaround. With that plugin present, the `Angular2TSReferenceTest` works for me. Let me know if it works for you :)
Hi Piotr,
Thanks a lot, that also works for me :) :)
Awesome, thanks for confirmation and sorry for the trouble!