Search in sources :

Example 1 with JsTestDriverBuilder

use of com.google.jstestdriver.embedded.JsTestDriverBuilder in project intellij-plugins by JetBrains.

the class JstdServerMain method main.

public static void main(String[] args) {
    shutdownIfOrphan();
    try {
        // pre-parse parsing... These are the flags
        // that must be dealt with before we parse the flags.
        CmdLineFlags cmdLineFlags = new CmdLineFlagsFactory().create(args);
        List<Plugin> cmdLinePlugins = cmdLineFlags.getPlugins();
        // configure logging before we start seriously processing.
        LogManager.getLogManager().readConfiguration(cmdLineFlags.getRunnerMode().getLogConfig());
        final PluginLoader pluginLoader = new PluginLoader();
        // load all the command line plugins.
        final List<Module> pluginModules = pluginLoader.load(cmdLinePlugins);
        logger.log(Level.INFO, "loaded plugins {0}", pluginModules);
        JsTestDriverBuilder builder = new JsTestDriverBuilder();
        BasePaths basePath = cmdLineFlags.getBasePath();
        builder.addBasePaths(basePath);
        builder.setDefaultConfiguration(new DefaultConfiguration(basePath));
        builder.setConfigurationSource(cmdLineFlags.getConfigurationSource());
        builder.addPluginModules(pluginModules);
        builder.withPluginInitializer(TestResultPrintingModule.TestResultPrintingInitializer.class);
        builder.setRunnerMode(cmdLineFlags.getRunnerMode());
        builder.setFlags(cmdLineFlags.getUnusedFlagsAsArgs());
        builder.addServerListener(new JstdIntellijServerListener());
        JsTestDriver jstd = builder.build();
        jstd.runConfiguration();
        logger.info("Finished action run.");
    } catch (InvalidFlagException e) {
        e.printErrorMessages(System.out);
        CmdLineFlags.printUsage(System.out);
        System.exit(1);
    } catch (UnreadableFilesException e) {
        System.out.println("Configuration Error: \n" + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    } catch (ConfigurationException e) {
        System.out.println("Configuration Error: \n" + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    } catch (RetryException e) {
        System.out.println("Tests failed due to unexpected environment issue: " + e.getCause().getMessage());
        System.exit(1);
    } catch (FailureException e) {
        System.out.println("Tests failed: " + e.getMessage());
        System.exit(1);
    } catch (BrowserPanicException e) {
        System.out.println("Test run failed due to unresponsive browser: " + e);
        System.exit(1);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Unexpected Runner Condition: " + e.getMessage() + "\n Use --runnerMode DEBUG for more information.");
        System.exit(1);
    }
}
Also used : BrowserPanicException(com.google.jstestdriver.browser.BrowserPanicException) JsTestDriver(com.google.jstestdriver.JsTestDriver) BasePaths(com.google.jstestdriver.model.BasePaths) TestResultPrintingModule(com.google.jstestdriver.guice.TestResultPrintingModule) RetryException(com.google.jstestdriver.util.RetryException) JsTestDriverBuilder(com.google.jstestdriver.embedded.JsTestDriverBuilder) FailureException(com.google.jstestdriver.FailureException) BrowserPanicException(com.google.jstestdriver.browser.BrowserPanicException) IOException(java.io.IOException) FailureException(com.google.jstestdriver.FailureException) RetryException(com.google.jstestdriver.util.RetryException) Module(com.google.inject.Module) TestResultPrintingModule(com.google.jstestdriver.guice.TestResultPrintingModule) PluginLoader(com.google.jstestdriver.PluginLoader) Plugin(com.google.jstestdriver.Plugin)

Example 2 with JsTestDriverBuilder

use of com.google.jstestdriver.embedded.JsTestDriverBuilder in project intellij-plugins by JetBrains.

the class TestRunner method runTests.

@SuppressWarnings("deprecation")
private void runTests(@NotNull final File configFile, @NotNull String[] extraArgs, final boolean dryRun) throws ConfigurationException {
    JsTestDriverBuilder builder = new JsTestDriverBuilder();
    final ParsedConfiguration parsedConfiguration;
    try {
        parsedConfiguration = JstdConfigParsingUtils.parseConfiguration(configFile);
    } catch (Exception e) {
        throw new ConfigurationException("Configuration file parsing failed.\n" + "See http://code.google.com/p/js-test-driver/wiki/ConfigurationFile for clarification.\n\n" + "Details:", e);
    }
    final File singleBasePath = JstdConfigParsingUtils.getSingleBasePath(parsedConfiguration.getBasePaths(), configFile);
    myTreeManager.setCurrentBasePath(singleBasePath.getAbsolutePath());
    JstdConfigParsingUtils.wipeCoveragePlugin(parsedConfiguration);
    builder.setDefaultConfiguration(parsedConfiguration);
    builder.withPluginInitializer(new PluginInitializer() {

        @Override
        public Module initializeModule(Flags flags, Configuration config) {
            return new AbstractModule() {

                @Override
                public void configure() {
                    Multibinder<TestListener> testListeners = Multibinder.newSetBinder(binder(), TestListener.class);
                    testListeners.addBinding().to(TestResultHolder.class);
                    testListeners.addBinding().toInstance(new IdeaTestListener(myTreeManager, configFile, singleBasePath, dryRun, mySettings.getTestFileScope()));
                }
            };
        }
    });
    builder.setRunnerMode(RunnerMode.QUIET);
    builder.setServer(mySettings.getServerUrl());
    List<String> flagArgs = Lists.newArrayList("--captureConsole", "--server", mySettings.getServerUrl());
    ResolvedConfiguration resolvedConfiguration = JstdConfigParsingUtils.resolveConfiguration(parsedConfiguration);
    if (dryRun && JstdUtils.isJasmineTests(resolvedConfiguration)) {
        // https://github.com/ibolmo/jasmine-jstd-adapter/pull/21
        flagArgs.add("--reset");
    }
    flagArgs.addAll(Arrays.asList(extraArgs));
    List<String> coverageExcludedFiles = null;
    File emptyOutputDir = null;
    boolean runCoverage = false;
    if (myCoverageSession != null && !dryRun) {
        emptyOutputDir = createTempDir();
        if (emptyOutputDir != null) {
            flagArgs.add("--testOutput");
            flagArgs.add(emptyOutputDir.getAbsolutePath());
            List<String> testPaths = getTestFilePaths(resolvedConfiguration);
            coverageExcludedFiles = Lists.newArrayList(testPaths);
            coverageExcludedFiles.addAll(mySettings.getFilesExcludedFromCoverageRec());
            PluginInitializer coverageInitializer = getCoverageInitializer(coverageExcludedFiles);
            if (coverageInitializer != null) {
                builder.withPluginInitializer(coverageInitializer);
                builder.withPluginInitializer(new DependenciesTouchFix());
                runCoverage = true;
            }
        }
    }
    builder.setFlags(toStringArray(flagArgs));
    builder.setFlagsParser(new IntelliJFlagParser(mySettings, dryRun));
    JsTestDriver jstd = builder.build();
    jstd.runConfiguration();
    if (runCoverage) {
        File[] coverageReportFiles = emptyOutputDir.listFiles((dir, name) -> name.endsWith("-coverage.dat"));
        if (coverageReportFiles != null && coverageReportFiles.length == 1) {
            try {
                CoverageReport coverageReport = CoverageSerializationUtils.readLCOV(coverageReportFiles[0]);
                for (String excludedPath : coverageExcludedFiles) {
                    coverageReport.clearReportByFilePath(excludedPath);
                }
                myCoverageSession.mergeReport(coverageReport);
            } catch (Exception e) {
                myTreeManager.printThrowable(e);
            }
        }
    }
}
Also used : PluginInitializer(com.google.jstestdriver.hooks.PluginInitializer) Configuration(com.google.jstestdriver.config.Configuration) ResolvedConfiguration(com.google.jstestdriver.config.ResolvedConfiguration) ParsedConfiguration(com.google.jstestdriver.config.ParsedConfiguration) Multibinder(com.google.inject.multibindings.Multibinder) CoverageReport(com.google.jstestdriver.idea.rt.coverage.CoverageReport) TestResultHolder(com.google.jstestdriver.output.TestResultHolder) JsTestDriverBuilder(com.google.jstestdriver.embedded.JsTestDriverBuilder) ConfigurationException(com.google.jstestdriver.config.ConfigurationException) AbstractModule(com.google.inject.AbstractModule) ResolvedConfiguration(com.google.jstestdriver.config.ResolvedConfiguration) ParsedConfiguration(com.google.jstestdriver.config.ParsedConfiguration) ConfigurationException(com.google.jstestdriver.config.ConfigurationException) TestListener(com.google.jstestdriver.hooks.TestListener) Module(com.google.inject.Module) AbstractModule(com.google.inject.AbstractModule)

Aggregations

Module (com.google.inject.Module)2 JsTestDriverBuilder (com.google.jstestdriver.embedded.JsTestDriverBuilder)2 AbstractModule (com.google.inject.AbstractModule)1 Multibinder (com.google.inject.multibindings.Multibinder)1 FailureException (com.google.jstestdriver.FailureException)1 JsTestDriver (com.google.jstestdriver.JsTestDriver)1 Plugin (com.google.jstestdriver.Plugin)1 PluginLoader (com.google.jstestdriver.PluginLoader)1 BrowserPanicException (com.google.jstestdriver.browser.BrowserPanicException)1 Configuration (com.google.jstestdriver.config.Configuration)1 ConfigurationException (com.google.jstestdriver.config.ConfigurationException)1 ParsedConfiguration (com.google.jstestdriver.config.ParsedConfiguration)1 ResolvedConfiguration (com.google.jstestdriver.config.ResolvedConfiguration)1 TestResultPrintingModule (com.google.jstestdriver.guice.TestResultPrintingModule)1 PluginInitializer (com.google.jstestdriver.hooks.PluginInitializer)1 TestListener (com.google.jstestdriver.hooks.TestListener)1 CoverageReport (com.google.jstestdriver.idea.rt.coverage.CoverageReport)1 BasePaths (com.google.jstestdriver.model.BasePaths)1 TestResultHolder (com.google.jstestdriver.output.TestResultHolder)1 RetryException (com.google.jstestdriver.util.RetryException)1