Search in sources :

Example 1 with FrontendDependencies

use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.

the class AbstractNodeUpdatePackagesTest method versionsMatch_noCleanUp.

@Test
public void versionsMatch_noCleanUp() throws IOException {
    // TODO: Fixme
    FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
    Map<String, String> packages = new HashMap<>();
    packages.put("@polymer/iron-list", "3.0.2");
    packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
    packages.put("@vaadin/vaadin-checkbox", "2.2.10");
    packages.put("@polymer/iron-icon", "3.0.1");
    packages.put("@vaadin/vaadin-time-picker", "2.0.2");
    // packages.put(VAADIN_CORE, "1.1.1");
    Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
    packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
    // Generate package json in a proper format first
    packageCreator.execute();
    makeNodeModulesAndPackageLock();
    Files.write(packageLock.toPath(), Collections.singletonList(stringify(makePackageLock("1.1.1"))));
    packageUpdater.execute();
    // nothing is removed
    Assert.assertTrue(mainNodeModules.exists());
    Assert.assertTrue(appNodeModules.exists());
    Assert.assertTrue(packageLock.exists());
}
Also used : HashMap(java.util.HashMap) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) Test(org.junit.Test)

Example 2 with FrontendDependencies

use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.

the class AbstractNodeUpdatePackagesTest method generatePackageJson_sameDependencies_updaterIsNotModified.

@Test
public void generatePackageJson_sameDependencies_updaterIsNotModified() {
    FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
    Map<String, String> packages = new HashMap<>();
    packages.put("@polymer/iron-list", "3.0.2");
    packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
    packages.put("@vaadin/vaadin-checkbox", "2.2.10");
    packages.put("@polymer/iron-icon", "3.0.1");
    packages.put("@vaadin/vaadin-time-picker", "2.0.2");
    Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
    packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
    packageCreator.execute();
    packageUpdater.execute();
    // generate it one more time, the content will be different since
    // packageCreator has not added its content
    packageUpdater.execute();
    Assert.assertFalse("Modification flag should be false when no dependencies changed.", packageUpdater.modified);
}
Also used : HashMap(java.util.HashMap) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) Test(org.junit.Test)

Example 3 with FrontendDependencies

use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.

the class AbstractNodeUpdatePackagesTest method frameworkManagedPackages_versionsAreUpdated.

@Test
public void frameworkManagedPackages_versionsAreUpdated() throws IOException {
    FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
    Map<String, String> packages = new HashMap<>();
    packages.put("@polymer/iron-list", "3.0.2");
    packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
    packages.put("@vaadin/vaadin-checkbox", "2.2.10");
    packages.put("@polymer/iron-icon", "3.0.1");
    packages.put("@vaadin/vaadin-time-picker", "2.0.2");
    Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
    packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
    packageCreator.execute();
    packageUpdater.execute();
    JsonObject dependencies = getPackageJson(packageJson).getObject(DEPENDENCIES);
    for (Map.Entry<String, String> entry : packages.entrySet()) {
        Assert.assertTrue(dependencies.hasKey(entry.getKey()));
        Assert.assertEquals(entry.getValue(), dependencies.getString(entry.getKey()));
    }
    packages.clear();
    packages.put("@polymer/iron-list", "3.1.0");
    packages.put("@vaadin/vaadin-confirm-dialog", "2.0.0");
    packages.put("@vaadin/vaadin-checkbox", "3.1.1");
    packages.put("@polymer/iron-icon", "3.0.3");
    packages.put("@vaadin/vaadin-time-picker", "2.0.3");
    packageUpdater.execute();
    dependencies = getPackageJson(packageJson).getObject(DEPENDENCIES);
    for (Map.Entry<String, String> entry : packages.entrySet()) {
        Assert.assertTrue(dependencies.hasKey(entry.getKey()));
        Assert.assertEquals(entry.getValue(), dependencies.getString(entry.getKey()));
    }
}
Also used : HashMap(java.util.HashMap) JsonObject(elemental.json.JsonObject) HashMap(java.util.HashMap) Map(java.util.Map) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) Test(org.junit.Test)

Example 4 with FrontendDependencies

use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.

the class AbstractNodeUpdatePackagesTest method generatePackageJson_noDependencies_updaterIsNotModified.

@Test
public void generatePackageJson_noDependencies_updaterIsNotModified() {
    FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
    Map<String, String> packages = new HashMap<>();
    Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
    packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
    packageCreator.execute();
    packageUpdater.execute();
    Assert.assertTrue("Modification flag should be true as we have added default dependencies.", packageUpdater.modified);
    // generate it one more time
    packageUpdater.execute();
    Assert.assertFalse("Modification flag should be false when there has never been dependencies.", packageUpdater.modified);
}
Also used : HashMap(java.util.HashMap) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) Test(org.junit.Test)

Example 5 with FrontendDependencies

use of com.vaadin.flow.server.frontend.scanner.FrontendDependencies in project flow by vaadin.

the class AbstractNodeUpdatePackagesTest method generatePackageJson_removedDependencies_updaterIsModified.

@Test
public void generatePackageJson_removedDependencies_updaterIsModified() {
    FrontendDependencies frontendDependencies = Mockito.mock(FrontendDependencies.class);
    Map<String, String> packages = new HashMap<>();
    packages.put("@polymer/iron-list", "3.0.2");
    packages.put("@vaadin/vaadin-confirm-dialog", "1.1.4");
    packages.put("@vaadin/vaadin-checkbox", "2.2.10");
    packages.put("@polymer/iron-icon", "3.0.1");
    packages.put("@vaadin/vaadin-time-picker", "2.0.2");
    Mockito.when(frontendDependencies.getPackages()).thenReturn(packages);
    packageUpdater = new TaskUpdatePackages(classFinder, frontendDependencies, baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
    packageCreator.execute();
    packageUpdater.execute();
    packages.remove("@vaadin/vaadin-checkbox");
    // generate it one more time, the content will be different since
    // packageCreator has not added its content
    packageUpdater.execute();
    Assert.assertTrue("Modification flag should be true when dependency removed.", packageUpdater.modified);
}
Also used : HashMap(java.util.HashMap) FrontendDependencies(com.vaadin.flow.server.frontend.scanner.FrontendDependencies) Test(org.junit.Test)

Aggregations

FrontendDependencies (com.vaadin.flow.server.frontend.scanner.FrontendDependencies)12 Test (org.junit.Test)11 HashMap (java.util.HashMap)10 JsonObject (elemental.json.JsonObject)4 FeatureFlags (com.vaadin.experimental.FeatureFlags)2 TARGET (com.vaadin.flow.server.Constants.TARGET)1 DEFAULT_FRONTEND_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR)1 DEFAULT_GENERATED_DIR (com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR)1 IMPORTS_NAME (com.vaadin.flow.server.frontend.FrontendUtils.IMPORTS_NAME)1 NODE_MODULES (com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES)1 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)1 AbstractTheme (com.vaadin.flow.theme.AbstractTheme)1 ThemeDefinition (com.vaadin.flow.theme.ThemeDefinition)1 File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Collections (java.util.Collections)1 List (java.util.List)1