IntelliJ Kotlin/JS Mocha Unit Testing Unavailable via Plugin - intellij-idea

I am experiencing some difficulty getting IntelliJ to recognize my Kotlin Tests as mocha tests and generating the green play button in the gutter allowing me to run Kotlin/JS unit tests in the IDE via the Mocha Plugin. Now, I somehow managed to get this working after some trial and error and then inexplicable earlier today it just stopped working and the green play buttons vanished from the gutter. I have tried all the normal stuff such as invalidating the IDE cache, removing .idea/*.iml files and reimporting project. Nothing seems to work.
Image of Working Environment
here is an image of the setup working as expected that I luckily took a snapshot of while I had the chance because I had so much difficulty getting it working.
You can also see that the mocha run configuration is accurately picking up on the fact that the actual file being ran is going to be the output file in my build directory.
My initial instinct led me to believe that this was due to IntelliJ picking up on my map.js files being generated as well, however this is not the case as did not (and do not) have my compile options set to with sourceMap = true or sourceMapEmbedSources = "always", as you can see from this snippet from my build.gradle.kts
compileKotlin2Js {
kotlinOptions {
moduleKind = "commonjs"
}
}
compileTestKotlin2Js {
kotlinOptions {
moduleKind = "commonjs"
}
}
For the record, my gradle build compiles and tests run successfully. To clarify, I am specifically trying to get IntelliJ to recognize the project structure in such a way that the run configurations can make these education decisions for me and speed up my workflow.

Related

alternate way to set Build and run using IntelliJ IDEA

I am working with Java source code with TestNG and frequently see errors like no test found to run OR Test event were not received whenever I try to run test cases in IntelliJ IDEA.
Which I can fix with changing Build and run using IntelliJ IDEA from Gradle.
I am looking for alternative way using which can add this somewhere as configuration instead of going and changing this manually.
You can use gradle-idea-ext-plugin to set build and run actions right in the Gradle build script:
import static org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.CHOOSE_PER_TEST
plugins {
...
id "org.jetbrains.gradle.plugin.idea-ext" version "1.0"
...
}
idea.project.settings {
delegateActions {
delegateBuildRunToGradle = true // Delegate Run/Build to Gradle
testRunner = CHOOSE_PER_TEST // Test execution: PLATFORM, GRADLE or CHOOSE_PER_TEST
}
}
But actually, the fact that it works with IDE runner, but does not work with Gradle runner may indicate problems. I would first check if it works from the command line Gradle - make sure you run the same test with it as from the IDE. If it works in terminal but does not work in IDE, I would report a bug at YouTrack with reproducible sample.

Micronaut Kotlin: Rest Controllers not working

I'm creating a simple application with 2 Rest Controllers with Kotlin. However, for every endpoint
the error is
{"message":"Not Found","_links":{"self":{"href":"
My inferences till now, for which I have searched for solutions and they didn't worked.
1.The generated folders are also empty. Might be an issue
As I have tried both IDE and command line. So, ruling out any issue from Idea
Tried to add a Java Controller in the project, but that also didn't run
Tried to use Micronaut annotations along with Spring Web annotations, didn't worked.
Is there anything else that I can change to make it work?
Ideally I would want to make it work with Kotlin and not Java.
Environment:
IDE - IntelliJ Idea 2020.2 Ultimate
Build - tried both Maven and Gradle, command line and IDE
EnableAnnotations: Done
Delegate Gradle Runner: Done
JDK: 11 ( but set as 8 in build file)
Update1 - Got few things working
Got the base code from Micronaut Launcher site
My Sample code
#RestController
#Validated
#RequestMapping("/hello")
open class UserController {
#Get("/echo")
fun echo():String{
return "hello"+ System.currentTimeMillis()
}
}
AOP is not working and thus had to use #Validated and open. The build.gradle has allOpen plugin.
#GetMapping should work as per https://micronaut-projects.github.io/micronaut-spring/latest/guide/#springMvc
I had to use Micronaut's #Get to make it working
Please help in fixing these 2 issues.

How run flutter 'packages pub run build_runner build' with debug mode in intellij idea?

I want to put break point on my generator code, but I don't know how to run the command on the debug mode.
I wrote generator using source_gen and build_runner
class MyGenerator extends GeneratorForAnnotation<Todo> {
#override
FutureOr<String> generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
return "// Hey! Annotation found!";
}
}
run commad flutter packages pub run build_runner build*
copy build.dart to root folder of project
add new run configuration
run debug, now you can debug your code generator!
* the packages is optional, you can just run flutter pub run build_runner build
Ivan's answer worked for me, but every time I changed a file that was using an annotation - the build process outputted:
[SEVERE] Terminating builds due to build script update
[INFO] Terminating. No further builds will be scheduled
and then renamed the build script itself from build.dart to build.dart.cached, and then exit with code 75.
After digging through the build_runner code, I discovered that this behavior can be mitigated by using the following Program Arguments:
serve --skip-build-script-check
(i.e. instead of just serve as Ivan suggested).
There may be some negative consequences; in the build_runner source code, in options.dart, I saw this:
// For testing only, skips the build script updates check.
bool skipBuildScriptCheck;

IntelliJ run vs running a jar, with a Springboot Kotlin, Multi module Gradle project with Social Oauth2

TL;DR: Why does everything run fine when started via IntelliJ, and why is it broken when call java -jar app.jar. And how do I fix this?
Alright, I have some issues with a backend I am trying to dockerize. I have an application created with Spring Boot (1.4.2.RELEASE) following the Spring Oauth (2.0.12.RELEASE) guide on their page. I follow the Gradle version, since I prefer Gradle over Maven. Also I am using Kotlin instead of Java. Everything is fine, I start via IntelliJ my backend with static front end, I can login via Facebook (and Google and Github), I receive a nice Principal witch holds al the information I need, and I can modify Spring Security to authorize and permit endpoints. So far so good.
Now for the bad part, when I run either ./gradlew clean build app:bootrun or ./gradlew clean build app:jar and run the jar via java -jar (like I will do in my Docker container), my backend comes up. My static front end pops up. Now I want to login via Facebook, I end up on the Facebook login page, I enter my credentials, and... nothing!
I end up back on my homepage, not logged in, no log messages that mean anything to me, just silence. The last thing I see in the log is:Getting user info from: https://graph.facebook.com/me
This Url will give me in my browser:
{
"error": {
"message": "An active access token must be used to query information about the current user.",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "GV/58H5f4fJ"
}
}
When going to this URL via an IntelliJ start, it will give me credential details. Obviously something is going wrong, but I have no clue what. Especially since a run from IntelliJ works fine. There is some difference between how the jar is started, and how IntelliJ's run config works, but I have no clue where to search for what. I could post trace logging, or all my Gradle files, but perhaps thats too much info to put in 1 question. I will defenitly update this question if someone needs some more details :)
The structure outline of this project is as follows:
root:
- api: is going to be opensourced later, contains rest definitions and DTOs.
- core: contains the meat. Also here is included in the gradle file
spring-boot-starter, -web, -security, spring-security-oauth2, and some jackson stuff.
- rest: contains versioned rest service implementations.
- app: contains angular webjars amongst others, the front end, and
my `#SpringBootApplication`, `#EnableOAuth2Client`
and the impl of `WebSecurityConfigurerAdapter`.
Why does everything run fine when started via IntelliJ, and why is it broken using bootRun or the jar artefact. And how do I fix this?
I found it, the problem was not Multi module Graldle, Spring boot, or Oauth2 related. In fact it was due to a src set config of Gradle, where Java was supposed to be in a Java src set folder, and Kotlin in a Java src set folder:
sourceSets {
main.java.srcDirs += 'src/main/java'
main.kotlin.srcDirs += 'src/main/kotlin'
}
As Will Humphreys stated in his comment above, IntelliJ takes all source sets, and runs the app. However, when building the jar via Gradle, these source sets are stricter. I had a Java file in my Kotlin src set, which is no problem for IntelliJ. But the jar created by Gradle takes into account the source sets as defined in the build.gralde file, which are stricter.
I found my missing bean issue with the code below:
#Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}
The Bean I missed was called AuthenticationController, which is a #RestController, and kinda crucial for my authentication code.

Karma not picking the changes, have to run tests twice

I am running Jasmine tests on Karma (latest, 0.12.14) from IntelliJ IDEA (latest, 13.1.2) on OS X.
IntelliJ just uses Karma plugin that points to my karma installation: /usr/local/lib/node_modules/karma
The problem is that Karma watcher doesn't pick new changes from JS files. When I run tests again, everything is fine. It's not a huge issue (they run pretty fast), but it's annyoing to always run tests twice after you do a change.
Anybody experienced similar issue?
Add the following property to your karma.conf.js file:
usePolling: true
I put it after the autoWatch flag.
Reference: AutoWatch doesn't work #895
Finally got this to work. This is a known issue when using Karma in IntelliJ with build tools like Webpack / Gulp / etc... and that the post-processed files are outside of the files that Karma is directly serving.
The workaround is to manually modify the IntelliJ config in this file: ...\plugins\js-karma\js_reporter\karma-intellij\lib\intellijRunner.js
At or near line #75 in the runWithConfig() method, change the refresh property --> true.
See this comment for details
Had this issue in both IntelliJ and Webstorm and fixed both the same way.
In the case of using IntelliJ IDEA, maybe try
Preferences > General > Uncheck "safe write"
I am not sure if question is still actual, but i found a solution (or just a workaround).
I changed this file C:\Users\MyUser\.IntelliJIdea14\config\plugins\js-karma\js_reporter\karma-intellij\lib\intellij.conf.js a little bit here:
config.singleRun = false;
var originalAutoWatch = config.autoWatch;
//config.autoWatch = false; <-- this line
config.autoWatchBatchDelay = 0;
For sure the plugin maintainers had some reason to add this line, but for me this worked fine enough (there were isolated crashes I can't reproduce).
I am not sure about older versions of intelij but I am using 2016.3 (the latest version at the time of writing this) and it all works OK assuming karma config has autoWatch: true.
Having exactly the same problem all I have to do was to switch on Toggle auto-test in intelij and all started working fine without any other change.
Please check autoWatch property in karma config file set to TRUE.
Also if you are using Sublime Text 3 then set "atomic_save": false in your user settings as it also causes issues with watches. see here
Macros worked for me. After trying usePolling: true, modifying the intellijRunner.js, and unchecking Safe Write I still had to save or run tests twice to catch the changes.
Made a compound macro to both Save and Run File and Save and Re-Run Test. Then I overwrote each commands' shortcut via Keymap.
How to bind multiple actions to a shortcut
screenshot of macro: Save and Run test at cursor
screenshot of macro: Save and Re-run last test
screenshot of Keymap for macros