NodeCommand { public static NodeCommandBuilder builder() { return builder(new ProcessWrapperImpl()); } NodeCommand(ProcessWrapper processWrapper, String nodeExecutable, int actualNodeVersion, List<String> nodeJsArgs, @Nullable String scriptFilename,
    List<String> args,
    Consumer<String> outputConsumer,
    Consumer<String> errorConsumer); void start(); int waitFor(); @Override String toString(); int getActualNodeVersion(); static NodeCommandBuilder builder();  }
@Test public void test_min_version() throws IOException { thrown.expect(NodeCommandException.class); thrown.expectMessage("Only Node.js v99 or later is supported, got"); NodeCommand.builder() .minNodeVersion(99) .pathResolver(getPathResolver()) .build(); }
@Test public void test_mac_default_executable_not_found() throws IOException { when(mockProcessWrapper.isMac()).thenReturn(true); thrown.expect(NodeCommandException.class); thrown.expectMessage("Default Node.js executable for MacOS does not exist."); NodeCommand.builder(mockProcessWrapper) .pathResolver(p -> "/file/does/not/exist") .build(); }
@Test public void test_non_existing_node_file() throws Exception { MapSettings settings = new MapSettings(); settings.setProperty("sonar.nodejs.executable", "non-existing-file"); NodeCommandBuilder nodeCommand = NodeCommand.builder(mockProcessWrapper) .configuration(settings.asConfig()) .script("not-used"); assertThatThrownBy(nodeCommand::build) .isInstanceOf(NodeCommandException.class) .hasMessage("Provided Node.js executable file does not exist."); await().until(() -> logTester.logs(LoggerLevel.ERROR) .contains("Provided Node.js executable file does not exist. Property 'sonar.nodejs.executable' was to 'non-existing-file'")); }
@Test public void test_non_existing_node_file_deprecated_key() throws Exception { MapSettings settings = new MapSettings(); settings.setProperty("sonar.typescript.node", "non-existing-file"); NodeCommandBuilder nodeCommand = NodeCommand.builder(mockProcessWrapper) .configuration(settings.asConfig()) .script("not-used"); assertThatThrownBy(nodeCommand::build) .isInstanceOf(NodeCommandException.class) .hasMessage("Provided Node.js executable file does not exist."); await().until(() -> logTester.logs(LoggerLevel.ERROR) .contains("Provided Node.js executable file does not exist. Property 'sonar.typescript.node' was to 'non-existing-file'")); }
@Test public void test_no_args() { NodeCommandBuilder commandBuilder = NodeCommand.builder(mockProcessWrapper); assertThatThrownBy(commandBuilder::build) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Missing arguments for Node.js."); }
@Test public void test_script_args() { NodeCommandBuilder commandBuilder = NodeCommand.builder(mockProcessWrapper).scriptArgs("arg"); assertThatThrownBy(commandBuilder::build) .isInstanceOf(IllegalArgumentException.class) .hasMessage("No script provided, but script arguments found."); }