Search in sources :

Example 61 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class InstallCompileRunN4jscExternalShadowNestedNodeModulesTest method testCompileAndRunWithExternalDependencies.

/**
 * Test for checking the npm support in the headless case by downloading third party package, importing it and
 * running it with Common JS.
 *
 * TODO: use System.lineSeparator()
 */
@Test
public void testCompileAndRunWithExternalDependencies() {
    final Path wsRoot = workspace.getAbsoluteFile().toPath();
    final Path project = wsRoot.resolve("packages").resolve("P");
    final Path fileToRun = project.resolve("src-gen").resolve("Main.js");
    N4jscOptions options = COMPILE(workspace);
    CliCompileResult cliResult = n4jsc(options, VALIDATION_ERRORS);
    assertEquals(cliResult.toString(), 1, cliResult.getTranspiledFilesCount());
    String expectedString = "Main.n4js in P\n";
    expectedString += "#methodOld() in version 2.0.0\n";
    expectedString += "#methodNew() in version 2.0.0";
    ProcessResult nodejsResult = nodejsRun(workspace.toPath(), fileToRun);
    assertEquals(nodejsResult.toString(), expectedString, nodejsResult.getStdOut());
}
Also used : Path(java.nio.file.Path) CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) N4jscOptions(org.eclipse.n4js.cli.N4jscOptions) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 62 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class N4jscInitTest method yarnHelloWorldTested.

/**
 * test yarn hello world test
 */
@Test
public void yarnHelloWorldTested() throws Exception {
    N4jscTestOptions options = INIT().setWorkingDirectory(cwd.toPath()).workspaces().answers(",,,,,,yes,yes");
    n4jsc(options, SUCCESS);
    yarnInstall(cwd.toPath());
    ProcessResult resultBuild = yarnRun(cwd.toPath(), "run", "build");
    assertTrue(resultBuild.getStdOut().contains("Errors: 0"));
    assertTrue(resultBuild.getStdOut().contains("Generated: 4"));
    ProcessResult resultNodejs = nodejsRun(cwd.toPath(), Path.of("packages/my-project"));
    assertEquals("Hello World", resultNodejs.getStdOut());
    ProcessResult resultTest = yarnRun(cwd.toPath(), "run", "test");
    assertTrue(resultTest.getStdOut().contains("Testing completed: SUCCESSES: 1, FAILURES: 0, ERRORS: 0, SKIPPED: 0"));
}
Also used : ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) N4jscTestOptions(org.eclipse.n4js.cli.N4jscTestOptions) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 63 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class N4jscInitTest method helloWorld.

/**
 * test hello world example
 */
@Test
public void helloWorld() throws Exception {
    String answers = ",,,,,,yes";
    N4jscTestOptions options = INIT().setWorkingDirectory(cwd.toPath()).answers(answers);
    n4jsc(options, SUCCESS);
    npmInstall(cwd.toPath());
    CliCompileResult result = n4jsc(IMPLICIT_COMPILE(cwd).setWorkingDirectory(cwd.toPath()), SUCCESS);
    assertEquals(1, result.getTranspiledFilesCount());
    ProcessResult resultNodejs = nodejsRun(cwd.toPath(), Path.of("."));
    assertEquals("Hello World", resultNodejs.getStdOut());
}
Also used : CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) N4jscTestOptions(org.eclipse.n4js.cli.N4jscTestOptions) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 64 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class IncompleteApiImplementationJarTest method testApiImplStub_CompileAndRunWithNodejsPlugin.

/**
 * Compile & Run Tests for IDE-1510
 *
 * @throws Exception
 *             in Error cases
 */
@Test
@Ignore("GH-1291")
public void testApiImplStub_CompileAndRunWithNodejsPlugin() throws Exception {
    Path workspace = Path.of(TARGET, WORKSPACE_FOLDER).toAbsolutePath();
    Path nodeModulesPath = Paths.get(workspace.toString(), N4JSGlobals.NODE_MODULES).toAbsolutePath();
    Path project = Path.of(workspace.toString(), N4CliHelper.PACKAGES, "one.x.impl").toAbsolutePath();
    N4CliHelper.copyN4jsLibsToLocation(nodeModulesPath, N4JSGlobals.N4JS_RUNTIME);
    CliCompileResult cliResult = n4jsc(COMPILE(project.toFile()));
    assertEquals(cliResult.toString(), 2, cliResult.getTranspiledFilesCount());
    Path fileA = project.resolve("src-gen/AT_IDE-1510_Missing_Method.js");
    ProcessResult nodejsResult = nodejsRun(workspace, fileA);
    assertTrue(nodejsResult.toString(), nodejsResult.getStdOut().contains("Hello from Implementation one.x.impl::p.A.n4js !"));
    assertTrue(nodejsResult.toString(), nodejsResult.getStdOut().contains("N4ApiNotImplementedError: API for method A.missing_n not implemented yet."));
    assertTrue(nodejsResult.toString(), nodejsResult.getStdOut().contains("N4ApiNotImplementedError: API for method A.missing_someIA not implemented yet."));
}
Also used : Path(java.nio.file.Path) CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) Ignore(org.junit.Ignore) AbstractCliJarTest(org.eclipse.n4js.cli.helper.AbstractCliJarTest) Test(org.junit.Test)

Aggregations

ProcessResult (org.eclipse.n4js.cli.helper.ProcessResult)64 Test (org.junit.Test)59 AbstractCliCompileTest (org.eclipse.n4js.cli.helper.AbstractCliCompileTest)55 Path (java.nio.file.Path)13 CliCompileResult (org.eclipse.n4js.cli.helper.CliCompileResult)12 Ignore (org.junit.Ignore)9 CliTools (org.eclipse.n4js.cli.helper.CliTools)5 N4jscOptions (org.eclipse.n4js.cli.N4jscOptions)4 N4jscTestOptions (org.eclipse.n4js.cli.N4jscTestOptions)4 File (java.io.File)3 AbstractCliJarTest (org.eclipse.n4js.cli.helper.AbstractCliJarTest)2 ArrayList (java.util.ArrayList)1 CliException (org.eclipse.n4js.cli.helper.CliTools.CliException)1 Project (org.eclipse.n4js.tests.codegen.Project)1 FileURI (org.eclipse.n4js.workspace.locations.FileURI)1 Xpect (org.eclipse.xpect.runner.Xpect)1