use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.
the class KarmaRunProfileState method getServerOrStart.
@Nullable
public KarmaServer getServerOrStart(@NotNull final Executor executor) throws ExecutionException {
NodeJsInterpreter interpreter = myRunSettings.getInterpreterRef().resolve(myProject);
NodeJsLocalInterpreter localInterpreter = NodeJsLocalInterpreter.castAndValidate(interpreter);
KarmaServerSettings serverSettings = new KarmaServerSettings.Builder().setNodeInterpreter(localInterpreter).setKarmaPackage(myKarmaPackage).setRunSettings(myRunSettings).setWithCoverage(myExecutionType == KarmaExecutionType.COVERAGE).setDebug(myExecutionType == KarmaExecutionType.DEBUG).build();
KarmaServerRegistry registry = KarmaServerRegistry.getInstance(myProject);
KarmaServer server = registry.getServer(serverSettings);
if (server != null && server.getRestarter().isRestartRequired()) {
server.shutdownAsync();
server = null;
}
if (server == null) {
registry.startServer(serverSettings, new CatchingConsumer<KarmaServer, Exception>() {
@Override
public void consume(KarmaServer server) {
RunnerAndConfigurationSettings configuration = myEnvironment.getRunnerAndConfigurationSettings();
if (configuration != null) {
ProgramRunnerUtil.executeConfiguration(myProject, configuration, executor);
}
}
@Override
public void consume(final Exception e) {
LOG.error(e);
showServerStartupError(e);
}
});
}
return server;
}
use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.
the class KarmaRunProgramRunner method doExecute.
@Nullable
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment environment) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
if (executionResult == null) {
return null;
}
KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
final RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, environment);
if (consoleView == null) {
return descriptor;
}
KarmaServer server = consoleView.getKarmaExecutionSession().getKarmaServer();
if (!server.areBrowsersReady()) {
server.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
} else {
RerunTestsNotification.showRerunNotification(environment.getContentToReuse(), executionResult.getExecutionConsole());
}
RerunTestsAction.register(descriptor);
return descriptor;
}
use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.
the class KarmaDebugProgramRunner method execute.
@NotNull
@Override
protected Promise<RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
if (executionResult == null) {
return Promise.resolve(null);
}
KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
if (consoleView == null) {
return Promise.resolve(KarmaUtil.createDefaultDescriptor(executionResult, environment));
}
KarmaServer karmaServer = consoleView.getKarmaExecutionSession().getKarmaServer();
if (karmaServer.areBrowsersReady()) {
KarmaDebugBrowserSelector browserSelector = new KarmaDebugBrowserSelector(karmaServer.getCapturedBrowsers(), environment, consoleView);
DebuggableWebBrowser debuggableWebBrowser = browserSelector.selectDebugEngine();
if (debuggableWebBrowser == null) {
return Promises.resolvedPromise(KarmaUtil.createDefaultDescriptor(executionResult, environment));
}
return KarmaKt.prepareKarmaDebugger(environment.getProject(), debuggableWebBrowser, () -> createDescriptor(environment, executionResult, consoleView, karmaServer, debuggableWebBrowser));
} else {
RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, environment);
karmaServer.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
return Promises.resolvedPromise(descriptor);
}
}
use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.
the class KarmaCoverageProgramRunner method listenForCoverageFile.
private static void listenForCoverageFile(@NotNull ExecutionEnvironment env, @NotNull KarmaServer server) throws ExecutionException {
KarmaRunConfiguration runConfiguration = (KarmaRunConfiguration) env.getRunProfile();
CoverageEnabledConfiguration coverageEnabledConfiguration = CoverageEnabledConfiguration.getOrCreate(runConfiguration);
CoverageHelper.resetCoverageSuit(runConfiguration);
String coverageFilePath = coverageEnabledConfiguration.getCoverageFilePath();
if (coverageFilePath != null) {
KarmaCoveragePeer coveragePeer = server.getCoveragePeer();
Objects.requireNonNull(coveragePeer);
coveragePeer.startCoverageSession(new KarmaCoverageSession() {
@Override
public void onCoverageSessionFinished(@Nullable File lcovFile) {
LOG.info("Processing karma coverage file: " + lcovFile);
UIUtil.invokeLaterIfNeeded(() -> {
Project project = env.getProject();
if (project.isDisposed())
return;
if (lcovFile != null) {
processLcovInfoFile(lcovFile, coverageFilePath, env, server, runConfiguration);
} else {
int response = Messages.showYesNoDialog(project, "Cannot find karma test coverage report - lcov.info", "Missing Karma Coverage Report", "Select lcov.info", "Cancel", Messages.getWarningIcon());
if (response == Messages.YES) {
FileChooser.chooseFile(FileChooserDescriptorFactory.createSingleFileDescriptor(), project, null, null, file -> {
File selected = file != null ? VfsUtilCore.virtualToIoFile(file) : null;
if (selected != null) {
processLcovInfoFile(selected, coverageFilePath, env, server, runConfiguration);
}
});
}
}
});
}
});
}
}
use of com.intellij.javascript.karma.server.KarmaServer in project intellij-plugins by JetBrains.
the class KarmaCoverageProgramRunner method doExecute.
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
FileDocumentManager.getInstance().saveAllDocuments();
ExecutionResult executionResult = state.execute(env.getExecutor(), this);
if (executionResult == null) {
return null;
}
RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, env);
KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
if (consoleView == null) {
return descriptor;
}
KarmaServer server = consoleView.getKarmaExecutionSession().getKarmaServer();
if (server.areBrowsersReady()) {
listenForCoverageFile(env, server);
} else {
server.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
}
return descriptor;
}
Aggregations