diff options
author | Shane Bryzak | 2016-07-14 11:26:29 +0000 |
---|---|---|
committer | Ilya Buziuk | 2016-07-18 08:23:19 +0000 |
commit | 17f0d10644e2d89d621167c9d7adbae9e667578f (patch) | |
tree | 529a8c1d12fe307722dff88bdc4c4358432fbb6c | |
parent | 00cf89b9c8c8b32278a0d15d7ba4e385554412a3 (diff) | |
download | webtools.jsdt-17f0d10644e2d89d621167c9d7adbae9e667578f.tar.gz webtools.jsdt-17f0d10644e2d89d621167c9d7adbae9e667578f.tar.xz webtools.jsdt-17f0d10644e2d89d621167c9d7adbae9e667578f.zip |
Bug 491474 - Added tests to cover npm script functionality
Change-Id: I9a668f4e00c64a3945c99a1f138b83c1f745baa7
Signed-off-by: Shane Bryzak <sbryzak@redhat.com>
6 files changed, 124 insertions, 11 deletions
diff --git a/nodejs/org.eclipse.wst.jsdt.js.npm/META-INF/MANIFEST.MF b/nodejs/org.eclipse.wst.jsdt.js.npm/META-INF/MANIFEST.MF index 94536cfe1..84342321f 100644 --- a/nodejs/org.eclipse.wst.jsdt.js.npm/META-INF/MANIFEST.MF +++ b/nodejs/org.eclipse.wst.jsdt.js.npm/META-INF/MANIFEST.MF @@ -24,5 +24,6 @@ Require-Bundle: org.eclipse.ui, Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin -Export-Package: org.eclipse.wst.jsdt.js.npm +Export-Package: org.eclipse.wst.jsdt.js.npm, + org.eclipse.wst.jsdt.js.npm.util diff --git a/tests/org.eclipse.wst.jsdt.js.common.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.jsdt.js.common.tests/META-INF/MANIFEST.MF index 601511812..2bc551531 100644 --- a/tests/org.eclipse.wst.jsdt.js.common.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.wst.jsdt.js.common.tests/META-INF/MANIFEST.MF @@ -10,4 +10,5 @@ Require-Bundle: org.junit, org.eclipse.wst.jsdt.core;bundle-version="2.0.0", org.eclipse.wst.jsdt.js.common;bundle-version="1.0.000", org.eclipse.wst.jsdt.js.gulp;bundle-version="1.0.000", - org.eclipse.wst.jsdt.js.grunt;bundle-version="1.0.000" + org.eclipse.wst.jsdt.js.grunt;bundle-version="1.0.000", + org.eclipse.wst.jsdt.js.npm;bundle-version="1.0.000" diff --git a/tests/org.eclipse.wst.jsdt.js.common.tests/resources/package.json b/tests/org.eclipse.wst.jsdt.js.common.tests/resources/package.json new file mode 100644 index 000000000..f691c91fe --- /dev/null +++ b/tests/org.eclipse.wst.jsdt.js.common.tests/resources/package.json @@ -0,0 +1,12 @@ +{ + "name": "gulptest", + "version": "0.0.0", + "description": "Generated with Eclipse npm Tools", + "main": "index.js", + "scripts": { + "tests": "echo 'Error: no test specified' && exit 1", + "doSomething": "echo 'Doing something now' && exit 0", + "foo": "echo 'bar bar' && exit 0"}, + "author": "", + "license": "ISC" +}
\ No newline at end of file diff --git a/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java index 47528d666..1e995f580 100644 --- a/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java +++ b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/BuildSystemVisitorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Red Hat, Inc. + * Copyright (c) 2016 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -42,22 +42,22 @@ import org.junit.Test; public class BuildSystemVisitorTest { private static IFile gruntfile; private static IFile gulpfile; - + @BeforeClass public static void init() throws CoreException, IOException, URISyntaxException { File grunt = ResourceUtil.getFileFromBundle(TestRunner.PLUGIN_ID, "resources/gruntfile.js"); File gulp = ResourceUtil.getFileFromBundle(TestRunner.PLUGIN_ID, "resources/gulpfile.js"); - + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("TestJsProject"); IProjectDescription description = ResourcesPlugin.getWorkspace() .newProjectDescription("Testing common js functionality"); description.setNatureIds(new String[] { JavaScriptCore.NATURE_ID }); project.create(description, null); project.open(null); - + gruntfile = project.getFile("gruntfile.js"); gruntfile.create(new FileInputStream(grunt.getAbsolutePath()), true, null); - + gulpfile = project.getFile("gulpfile.js"); gulpfile.create(new FileInputStream(gulp.getAbsolutePath()), true, null); } @@ -82,7 +82,7 @@ public class BuildSystemVisitorTest { fail("Exception occured while reading file"); } } - + @Test public void GulpTasksTest() { try { @@ -97,5 +97,6 @@ public class BuildSystemVisitorTest { fail("Exception occured while reading file"); } } - + + } diff --git a/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/NpmScriptsTest.java b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/NpmScriptsTest.java new file mode 100644 index 000000000..8084d1d9c --- /dev/null +++ b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/NpmScriptsTest.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2016 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat Inc. - initial API and implementation and/or initial documentation + *******************************************************************************/ +package org.eclipse.wst.jsdt.js.common.tests; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.wst.jsdt.core.JavaScriptCore; +import org.eclipse.wst.jsdt.js.common.tests.suites.TestRunner; +import org.eclipse.wst.jsdt.js.common.tests.util.ResourceUtil; +import org.eclipse.wst.jsdt.js.npm.PackageJson; +import org.eclipse.wst.jsdt.js.npm.util.NpmUtil; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author Shane Bryzak + * + */ +public class NpmScriptsTest { + + private static IFile packageJsonFile; + + @BeforeClass + public static void init() throws CoreException, IOException, URISyntaxException { + File npm = ResourceUtil.getFileFromBundle(TestRunner.PLUGIN_ID, "resources/package.json"); + + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("TestNpmProject"); + IProjectDescription description = ResourcesPlugin.getWorkspace() + .newProjectDescription("Testing common js functionality"); + description.setNatureIds(new String[] { JavaScriptCore.NATURE_ID }); + project.create(description, null); + project.open(null); + + packageJsonFile = project.getFile("package.json"); + packageJsonFile.create(new FileInputStream(npm.getAbsolutePath()), true, null); + } + + @AfterClass + public static void teardown() throws CoreException { + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("TestNpmProject"); + project.delete(true, true, null); + } + + @Test + public void TestNpmScriptContentProvider() { + try { + PackageJson packageJson = NpmUtil.parsePackageJsonFile(packageJsonFile); + + assertTrue("Not all npm scripts found", packageJson.getScripts().size() == 3); + + boolean foundTests = false; + boolean foundDoSomething = false; + boolean foundFoo = false; + + for (String scriptName : packageJson.getScripts().keySet()) { + + if ("tests".equals(scriptName)) { + foundTests = true; + } else if ("doSomething".equals(scriptName)) { + foundDoSomething = true; + } else if ("foo".equals(scriptName)) { + foundFoo = true; + } + } + + assertTrue("Couldn't find script 'tests'", foundTests); + assertTrue("Couldn't find script 'doSomething'", foundDoSomething); + assertTrue("Couldn't find script 'foo'", foundFoo); + } catch (CoreException e) { + fail("CoreException occured while reading file"); + } catch (UnsupportedEncodingException e) { + fail("UnsupportedEncodingException occured while reading file"); + } + + } +} diff --git a/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/suites/TestRunner.java b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/suites/TestRunner.java index 0073988d4..0cc339064 100644 --- a/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/suites/TestRunner.java +++ b/tests/org.eclipse.wst.jsdt.js.common.tests/src/org/eclipse/wst/jsdt/js/common/tests/suites/TestRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Red Hat, Inc. + * Copyright (c) 2016 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ package org.eclipse.wst.jsdt.js.common.tests.suites; import org.eclipse.wst.jsdt.js.common.tests.BuildSystemVisitorTest; +import org.eclipse.wst.jsdt.js.common.tests.NpmScriptsTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @@ -19,7 +20,7 @@ import org.junit.runners.Suite.SuiteClasses; * @author "Ilya Buziuk (ibuziuk)" */ @RunWith(Suite.class) -@SuiteClasses({ BuildSystemVisitorTest.class }) +@SuiteClasses({ BuildSystemVisitorTest.class, NpmScriptsTest.class }) public class TestRunner { public static final String PLUGIN_ID = "org.eclipse.wst.jsdt.js.common.tests"; }
\ No newline at end of file |